opengap icon indicating copy to clipboard operation
opengap copied to clipboard

feat(adapters): added LangGraph and DeepAgents export adapters

Open krishvsoni opened this issue 6 months ago • 4 comments

feat(adapters): added LangGraph and DeepAgents export adapters

  • Implemented exportToLangGraph and exportToLangGraphString functions in src/adapters/langgraph.ts to convert agent configurations into LangGraph Python code.
  • Implemented exportToDeepAgents and exportToDeepAgentsString functions in src/adapters/deepagents.ts to emit a create_deep_agent(...) LangChain DeepAgents harness — skills, tools, and sub-agents map directly; no graph wiring.
  • Created comprehensive test suites in src/adapters/langgraph.test.ts (18 tests) and src/adapters/deepagents.test.ts (13 tests) to validate the output of the export functions, ensuring correct handling of agent metadata, skills, tools, skillflows, hooks, and sub-agents.
  • Added helper functions for YAML rendering and agent directory structure creation to facilitate testing.
  • Ensured compatibility with existing agent structures by supporting both skillflows/ and workflows/ directories.

What

Adds two new export adapters to gitagent:

  • langgraph : converts a gitagent directory into a runnable LangGraph StateGraph Python module. Skills become nodes, skillflows/*.yaml become add_edge / add_conditional_edges, tools/*.yaml bind to a ToolNode, pre_tool_use hooks become a before_tool callback, and agents/<name>/ become nested compiled StateGraphs.
  • deepagents : converts a gitagent directory into a create_deep_agent(...) call. Skills are passed via skills=["./skills"] (DeepAgents reads each SKILL.md natively), tools are @tool defs in tools=[...], and sub-agents become SubAgent dicts in subagents=[...]. Use this when you want the model to orchestrate planning and delegation instead of authoring a graph by hand.

Why

Issue #1 has been open since Feb 27 and the @shreyas-lyzr 's most recent comment asked for LangGraph proper as the natural sibling of the in-flight LangChain adapter (PR #16), with the explicit mapping agent.yaml → StateGraph config, skills/ → nodes, skillflows/*.yaml → edges + conditional routing. The maintainer's earlier comment in the same thread linked the DeepAgents overview as a possible alternative — shipping it as a sibling adapter gives users both paths (explicit graph wiring vs. LLM-orchestrated harness) without forcing a choice.

Closes #1

How Tested

  • [x] npm run build passes
  • [x] gitagent validate passes on example agents
  • [x] Manual testing (describe below)

Ran both adapters end-to-end against examples/langgraph, examples/deepagents, and the bundled examples/full compliance agent (sub-agents, workflow with depends_on, hooks, FINRA / Federal Reserve / SEC compliance block). Diffed each export against the committed expected_output.py and verified syntactic validity with ast.parse. Full suite is 60/60 across 11 suites — 18 new LangGraph tests + 13 new DeepAgents tests, no pre-existing tests modified.

$ npm run build
> tsc && chmod +x dist/index.js

$ node dist/index.js export --dir examples/langgraph --format langgraph -o /tmp/lg.py
✓ Exported to /tmp/lg.py
$ node dist/index.js export --dir examples/deepagents --format deepagents -o /tmp/da.py
✓ Exported to /tmp/da.py

$ python -c "import ast; ast.parse(open('/tmp/lg.py').read()); print('OK')"
OK
$ python -c "import ast; ast.parse(open('/tmp/da.py').read()); print('OK')"
OK

$ npm test
# tests 60
# suites 11
# pass 60
# fail 0

Checklist

  • [x] My code follows the existing style of this project
  • [x] I have added/updated tests (if applicable)
  • [x] I have updated documentation (if applicable)
  • [x] I have read the CONTRIBUTING.md

krishvsoni avatar May 13 '26 09:05 krishvsoni

This is a serious piece of work. Brutally honest review:

What's right:

  • The mapping documented in src/adapters/langgraph.ts header is exactly the right shape — agent.yaml → StateGraph config, SOUL/RULES/DUTIES → system prompt, skills/<name>/SKILL.md → graph node, skillflows/*.yaml → add_edge / add_conditional_edges, tools/*.yaml → ToolNode, pre_tool_use → before_tool, agents/<name>/ → nested compiled StateGraph. That's the canonical correspondence — every element of GAP maps to something in LangGraph.
  • Shipping DeepAgents alongside LangGraph as the LLM-orchestrated harness alternative (no explicit graph wiring) is a smart sibling — gives users both paths. The cleanest is the skills=["./skills"] integration since DeepAgents reads SKILL.md natively.
  • 18 + 13 = 31 tests with regex assertions against the generated Python, plus ast.parse validation. That's how adapter tests should look — not stubs.
  • examples/langgraph/ and examples/deepagents/ include expected_output.py artifacts. Diff-testable.
  • Closes #1 (LangGraph adapter request open since Feb 27).

One thing for a follow-up (not a blocker): The paper/open-gap.md Appendix B fidelity matrix should add rows for langgraph and deepagents. Will add this myself in a doc-only follow-up.

Merging.

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

Hit a clean merge conflict — PR #66 (mcp_servers) just merged minutes before this and also touches src/commands/export.ts and src/adapters/index.ts. Bad timing on my part — I should have merged in the other order.

Quick rebase needed against the new main. The conflict footprint is tiny: just the two integration files at the bottom of the export switch and the adapters/index re-exports. The actual langgraph.ts and deepagents.ts files are untouched by #66 and will rebase clean.

If you push a rebase, I'll merge same-day (less than an hour if I'm at a keyboard). If easier, I'm happy to rebase locally and force-push to your branch myself — your call. Either way the merge is approved on the substance.

Apologies for the conflict — that one was on me.

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

Thanks @shreyas-lyzr no worries on the conflict, totally understandable timing.

Rebased onto main and force-pushed. The src/commands/export.ts and src/adapters/index.ts conflicts were trivial as you predicted both langgraph/deepagents entries slot in cleanly after gitclaw in the switch and re-exports.

One small extra: README.md also had a tiny conflict against PR #78's adapter table additions (copilot/codex/kiro/gitclaw). Resolved by keeping all rows the table now lists every upstream adapter, plus langgraph and deepagents at the bottom. Net diff against main is just +2 lines on README, as expected.

krishvsoni avatar May 14 '26 06:05 krishvsoni

@shreyas-lyzr Can you check now?

krishvsoni avatar May 14 '26 17:05 krishvsoni