Skip to content

feat(adapter): add LangGraph export and run adapter#26

Open
dahlinomine wants to merge 1 commit intoopen-gitagent:mainfrom
dahlinomine:feat/langgraph-adapter
Open

feat(adapter): add LangGraph export and run adapter#26
dahlinomine wants to merge 1 commit intoopen-gitagent:mainfrom
dahlinomine:feat/langgraph-adapter

Conversation

@dahlinomine
Copy link
Copy Markdown
Contributor

Summary

Adds langgraph as a new export format and run adapter.

Closes #1.

Changes

  • src/adapters/langgraph.ts — exports a gitagent directory as a LangGraph StateGraph Python script using the ReAct pattern with ToolNode and conditional routing
  • src/runners/langgraph.ts — runs the exported graph script via python3
  • Multi-agent topology: sub-agents defined in agent.yaml are annotated with guidance for LangGraph supervisor-node patterns
  • Compliance constraints (FINRA 2210, 17a-4, SOD conflicts) are injected into the system SYSTEM_PROMPT constant
  • Model routing: gpt-4o default, claude-*ChatAnthropic, gemini-*ChatGoogleGenerativeAI

Usage

# Export to a LangGraph Python script
gitagent export -f langgraph -d ./my-agent -o agent_graph.py

# Run directly
gitagent run -a langgraph -d ./my-agent

Generated output example

Given an agent with a research skill and claude-3-5-sonnet-20241022 model:

from langgraph.graph import StateGraph, END
from langgraph.prebuilt import ToolNode
from langchain_anthropic import ChatAnthropic

class AgentState(TypedDict):
    messages: Annotated[Sequence[BaseMessage], operator.add]

@tool
def research(input: str) -> str:
    """Research a topic..."""
    raise NotImplementedError("research not yet implemented")

tools = [research]
llm = ChatAnthropic(model="claude-3-5-sonnet-20241022", temperature=0.3)
llm_with_tools = llm.bind_tools(tools)
# ... StateGraph wiring ...
graph = workflow.compile()

Testing

  • npm run build passes
  • gitagent export -f langgraph -d examples/standard produces valid Python
  • gitagent export -f langgraph -d examples/full renders compliance constraints

Checklist

  • Follows the existing adapter pattern (crewai, openai, lyzr)
  • Runner follows the existing runner pattern (runners/openai.ts)
  • Wired into adapters/index.ts, commands/export.ts, commands/run.ts
  • No new dependencies added
  • Conventional commit message

@shreyas-lyzr
Copy link
Copy Markdown
Contributor

can we create a adapter for DeepAgents instead? https://docs.langchain.com/oss/python/deepagents/overview

@dahlinomine
Copy link
Copy Markdown
Contributor Author

Thanks for the direction! I've replaced the LangGraph adapter with a Deep Agents one: #29

It uses create_deep_agent() from the deepagents SDK and follows the same pattern as the other adapters — skills become @tool stubs, SOUL.md/compliance constraints go into system_prompt, and there's a __main__ REPL for quick testing. Happy to adjust anything.

@shreyas-lyzr
Copy link
Copy Markdown
Contributor

Closing alongside #27 — this PR adds adapter and runner files but doesn't wire them into export.ts, run.ts, or index.ts. Also no tests, no docs, no import support. If you'd like to contribute a LangGraph adapter, please submit a complete PR with wiring, tests, and a mapping doc.

@dahlinomine
Copy link
Copy Markdown
Contributor Author

Thanks @shreyas-lyzr — fair points. Standalone adapter and runner files without the core wiring don't really complete the feature. I'll close this and resubmit as a proper PR: full wiring into export.ts, run.ts, and index.ts, tests, a mapping doc, and import support. Will follow the same structure as the other adapters in the codebase.

- src/adapters/langgraph.ts: full StateGraph export with SOUL.md/RULES.md/
  skills/knowledge/compliance mapping, @tool stubs from tools/*.yaml, and
  HITL nodes for human_in_the_loop (always/conditional)
- src/runners/langgraph.ts: runner that generates agent.py + isolated venv
  + pip install, executes via python agent.py [--prompt]
- src/adapters/langgraph.test.ts: 20 node:test unit tests covering export
  structure, model routing (Claude/OpenAI/Gemini), HITL wiring, requirements
- docs/adapters/langgraph.md: full field mapping, graph diagrams, model
  resolution table, compliance mapping, usage examples
- src/adapters/index.ts: add exportToLangGraphString, exportToLangGraph
- src/commands/export.ts: wire langgraph case + update format description
- src/commands/run.ts: wire langgraph case + import runWithLangGraph
@dahlinomine dahlinomine force-pushed the feat/langgraph-adapter branch from 25f94a0 to 9139369 Compare March 27, 2026 18:18
@dahlinomine
Copy link
Copy Markdown
Contributor Author

Update: rather than close and resubmit, I've pushed the complete implementation directly to this branch. Here's what's now included:

New files:

  • src/adapters/langgraph.ts — full StateGraph export: maps SOUL.md/RULES.md/DUTIES.md/skills/knowledge/compliance → Python SYSTEM_PROMPT; tools/*.yaml@tool stubs; human_in_the_loop → HITL human_review_node
  • src/runners/langgraph.ts — creates a temp workspace, sets up a Python venv, runs pip install -r requirements.txt, then launches python agent.py [--prompt]
  • src/adapters/langgraph.test.ts — 20 node:test unit tests (model routing, HITL wiring, requirements, .env.example, string export headers)
  • docs/adapters/langgraph.md — field mapping table, graph structure diagrams, model resolution table, compliance mapping, usage examples

Wired into core:

  • src/adapters/index.ts — exports exportToLangGraphString, exportToLangGraph
  • src/commands/export.tscase 'langgraph': in switch + format description updated
  • src/commands/run.tscase 'langgraph': in switch + import { runWithLangGraph } added

Follows the same patterns as the gemini and opencode adapters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Adapter] LangGraph export/runner

2 participants