opengap icon indicating copy to clipboard operation
opengap copied to clipboard

[Adapter] LangGraph export/runner

Open shreyas-lyzr opened this issue 9 months ago • 8 comments

Summary

Add a LangGraph adapter to gitagent, enabling export and run support for the LangGraph framework.

Details

LangGraph is a popular framework for building stateful, multi-agent applications with LLMs. A gitagent adapter would allow users to:

  • Export: Convert a gitagent agent definition to a LangGraph graph/state machine
  • Run: Execute a gitagent-defined agent using the LangGraph runtime

Acceptance Criteria

  • [ ] gitagent export --format langgraph generates valid LangGraph Python code
  • [ ] gitagent run ./agent --adapter langgraph executes the agent
  • [ ] Documentation added to README adapter table
  • [ ] Example added to examples/

Resources

shreyas-lyzr avatar Feb 26 '26 23:02 shreyas-lyzr

https://docs.langchain.com/oss/python/deepagents/overview

DeepAgent instead.

shreyas-lyzr avatar Mar 18 '26 11:03 shreyas-lyzr

Hi @shreyas-lyzr, you mentioned DeepAgent as a potential alternative.

Could you clarify:

  1. Is the current LangGraph PR complete or does it need work?
  2. Should we pursue DeepAgent implementation instead of LangGraph?
  3. If DeepAgent is preferred, would you like me to work on that adapter?

I'd be happy to help implement whichever approach you think is best.

https://docs.langchain.com/oss/python/deepagents/overview

DeepAgent instead.

krishvsoni avatar Apr 09 '26 06:04 krishvsoni

Apologies for the long silence. Still wanted, still open. With the LangChain adapter (PR #16) in flight, LangGraph becomes interesting because it's the natural sibling.

Mapping I think is right:

  • agent.yaml → LangGraph StateGraph config (model, max_turns, etc.)
  • skills/ → LangGraph nodes (each skill becomes a callable node)
  • skillflows/*.yaml → LangGraph edges + conditional routing (this is the natural fit — gitagent's SkillsFlow is conceptually equivalent to a LangGraph state graph)
  • tools/ → LangGraph tool bindings
  • hooks/pre_tool_use → LangGraph before_tool callback (LangGraph supports this)
  • Sub-agents (agents/<name>/) → nested LangGraph graphs

The skillflows/ ↔ LangGraph correspondence is genuinely close — implementing this adapter would also stress-test our SkillsFlow design and likely surface useful spec questions.

Sequencing: Easier to do after PR #16 (LangChain) lands, since LangGraph imports a lot of LangChain primitives — sharing adapter helpers would be cleaner.

Open to anyone who wants to take it. help wanted. Apologies for the wait.

shreyas-lyzr avatar May 04 '26 15:05 shreyas-lyzr

Resolved by #80 (LangGraph + DeepAgents adapters merged 2026-05-13). Thanks @krishvsoni for shipping both flavors.

shreyas-lyzr avatar May 13 '26 17:05 shreyas-lyzr

Reopening — #80 hit a merge conflict (with the just-merged #66 mcp_servers PR, which also touches export.ts and adapters/index.ts). Will close again once #80 lands after rebase.

shreyas-lyzr avatar May 13 '26 17:05 shreyas-lyzr

PR #80 addresses this issue — it adds both langgraph and deepagents adapters. Currently in review. Status:

  • src/adapters/langgraph.ts converts agent.yaml → LangGraph StateGraph (skills → nodes, skillflows → edges/conditional routing, tools → ToolNode)
  • src/adapters/deepagents.ts converts agent.yaml → create_deep_agent(...) call (LLM-orchestrated, no graph wiring)
  • 18 LangGraph tests + 13 DeepAgents tests
  • Example agents in examples/langgraph/ and examples/deepagents/

Two blocking issues flagged in the PR review: (1) no runner implementation for gitagent run -a langgraph, and (2) the anthropic:claude-sonnet-4-5 provider prefix format needs verification against the adapter's provider detection logic. Once those are resolved the PR should be mergeable.

Tracking here — will close this issue when #80 merges.

shreyas-lyzr avatar May 24 '26 09:05 shreyas-lyzr

PR #80 (feat/1-langgraph-adapter by @krishvsoni) directly addresses this issue and is currently open for review. It adds both LangGraph (StateGraph) and DeepAgents adapters with comprehensive test coverage — 18 tests for LangGraph and 13 for DeepAgents.

Key items from the PR review that should be resolved before close:

  • Skills listed in agent.yaml but absent from skillflows will generate isolated graph nodes that are never reached — this should warn at export time
  • SKILLS = ["./skills"] in deepagents output uses a relative path that will break if the script is run from a different directory
  • src/adapters/index.ts was not updated to export the DeepAgents adapter, so it will not be accessible via the top-level package export

Once those are addressed in PR #80, this issue can be closed. Assigning @shreyas-lyzr to coordinate.

shreyas-lyzr avatar May 25 '26 09:05 shreyas-lyzr

Thanks for the thorough review @shreyas-lyzr, all four points are addressed in the latest push.

1. Skills with no skillflow entry (silent unreachable nodes)

Fixed both ways you suggested. The LangGraph adapter now detects skills that are declared in agent.yaml but referenced by no skillflow step, and it:

  • warns at export time on stderr — gitagent: skill "<name>" is declared but no skillflow step references it; it will not be reachable in the compiled graph.
  • emits a note in the generated module itself listing the unreferenced skills, right under their node definitions.

When there are no skillflows, skills are chained sequentially as before, so nothing is silently orphaned.

2. SKILLS = ["./skills"] relative path

Now resolved relative to the generated file instead of the CWD:

SKILLS = [str(Path(__file__).resolve().parent / "skills")]

Same treatment for sub-agent skills (Path(__file__).resolve().parent / "agents" / "<name>" / "skills"). from pathlib import Path is only imported when skills are actually present.

3. NotImplementedError stubs

The stub raises a descriptive message at runtime — raise NotImplementedError("Implement tool: <name>") — so anyone running the file gets a clear, tool-specific signal, and both example READMEs call out that stubs must be replaced. Happy to add an inline # TODO: implement comment above the raise as well if you'd prefer it visible without running the file.

4. index.ts missing the DeepAgents export

Exported: exportToDeepAgents / exportToDeepAgentsString are in src/adapters/index.ts, and the adapter is wired into both export (--format deepagents) and run (-a deepagents).


On the two blocking items from the PR review:

  • Runners : added runners/langgraph.ts and runners/deepagents.ts (sharing a small runners/python.ts helper), so gitagent run -a langgraph|deepagents works instead of falling through. -p is honored via a GITAGENT_PROMPT env var the entrypoint reads.
  • anthropic:claude-sonnet-4-5 prefix : confirmed correct as-is: the string is passed straight to init_chat_model() (LangGraph) and create_deep_agent(model=...) (DeepAgents), both of which parse provider:model natively. Stripping the prefix would actually break provider selection, so no change there.

Both example expected_output.py snapshots were regenerated and match the live CLI output exactly; the full test suite stays green (31 adapter tests).

krishvsoni avatar May 25 '26 16:05 krishvsoni