Skip to main content

Compile structured YAML configurations into production-grade LangGraph multi-agent architectures.

Project description

GraphForge ๐Ÿ› ๏ธ๐Ÿฆœ๐Ÿ”—

Compile structured YAML configurations into productionโ€‘grade LangGraph multiโ€‘agent architectures.

GraphForge eliminates LangGraph boilerplate by letting you declare your agent topology in YAML. Define nodes, chains, tools, edges, subโ€‘agents, and supervisors โ€” the compiler scaffolds a complete, modular, runnable Python codebase ready for production.

๐Ÿ“– Full Developer Wiki โ†’ โ€” complete reference for every YAML field, node type, edge type, and generated output.


๐Ÿš€ Key Features

  • Declarative Multiโ€‘Agent Workflows โ€” Define the full agent graph (nodes, edges, subโ€‘agents, supervisor routing) in simple YAML.
  • TypedDict State (LangGraphโ€‘native) โ€” Generates TypedDict classes with Annotated[..., add_messages] reducers by default. Pydantic BaseModel is available via state_type: pydantic.
  • Supervisor Orchestration โ€” type: supervisor nodes generate an LLM-driven routing scaffold with configurable route_field and compile-time validation.
  • Hierarchical Parent-Scoped Output โ€” Sub-agent code is generated inside subdirectories under the parent source_dir (e.g. my_agent/adaptive_rag/).
  • All LangGraph Edge Types โ€” standard, conditional, supervisor_route, tool_loop, fan_out (Send API), and interrupt_before humanโ€‘inโ€‘theโ€‘loop.
  • Parallel Fan-Out via Send API โ€” type: fan_out dispatches one node to multiple inputs simultaneously using langgraph.types.Send.
  • Async Node Scaffolding โ€” async_fn: true generates async def node functions with notes on awaiting LLM/tool calls.
  • Multi-Model LLM Support โ€” provider: openai | anthropic | ollama | groq per chain or supervisor node with model-specific imports scaffolded.
  • MCP Tool Client Stubs โ€” source: mcp in the tools block scaffolds a Model Context Protocol client.
  • Checkpointing โ€” memory.type: sqlite | in_memory wires SqliteSaver / MemorySaver into workflow.compile().
  • Real-time Streaming โ€” Generated main.py uses app.stream() with thread config for node-by-node event output.
  • Mermaid Flowcharts โ€” Auto-generates flowchart.md with nested subgraph rendering and distinct supervisor styling.
  • CLI โ€” forge compile, forge validate, forge init, forge ingest, plus --dry-run preview.

๐Ÿ› ๏ธ Quick Start

1. Install

Option A โ€” PyPI (once published)

pip install agentgraph-compiler
# or
uv add agentgraph-compiler

Option B โ€” Directly from GitHub (available now, no clone needed)

pip install agentgraph-compiler

Option C โ€” Clone for local development

git clone https://github.com/cvaws/GraphForge.git
cd GraphForge
uv sync

After any install, the forge CLI is available in your environment:

forge --help

2. Initialize a Project

uv run forge init

Creates:

  • configs/config.yaml โ€” Global settings (models, vector store, embedding)
  • configs/agents/agent.yaml โ€” Starter agent workflow spec

3. Configure Environment

cp .env.example .env
# Fill in OPENAI_API_KEY (and optionally LANGCHAIN_API_KEY for tracing)

4. Validate Configuration

uv run forge validate configs/agents/agent.yaml

Runs Pydantic schema validation and checks all edge targets exist as declared nodes โ€” without writing any files.

5. Compile Agent Topology

# Preview without writing files
uv run forge compile configs/agents/agent.yaml --dry-run

# Compile Python scaffold
uv run forge compile configs/agents/agent.yaml

6. Run the Agent

uv run python my_agent/main.py "How do I build multi-agent graphs with GraphForge?"

๐Ÿ’ก Try an Example

Six ready-to-compile examples cover every supported LangGraph pattern โ€” all configs live in configs/agents/examples/:

Example Pattern
simple_rag/ Single-agent RAG with conditional edges
multi_agent/ Supervisor + 2 sub-agents via graphRef
react_agent/ ReAct tool_loop + MCP tool client
parallel_fanout/ Parallel fan_out via Send API
human_in_loop/ interrupt_before + approve/revise cycle
async_agent/ async_fn: true async nodes
# Example: compile and run the ReAct agent
uv run forge compile configs/agents/examples/react_agent/agent.yaml
uv run python react_agent/main.py "What is the current price of Bitcoin?"

See configs/agents/examples/README.md for compile/run instructions for all examples.


๐Ÿ“– CLI Reference

Command Usage Description
compile forge compile <path> [--dry-run] Compiles YAML into Python scaffolds under source_dir.
validate forge validate <path> Schema validation + edge target reference checks.
init forge init [directory] Scaffolds starter configs/config.yaml and agent.yaml.
ingest forge ingest [--config path] Ingests URLs from config.yaml into Qdrant vector store.

โš™๏ธ Global Configuration (configs/config.yaml)

Centralize model providers, vector store settings, and ingestion URLs:

models:
  chat:
    name: gpt-4o
    temperature: 0.5
  embedding:
    name: text-embedding-3-small
    provider: openai

vector_store:
  name: qdrant
  url: "http://localhost:6333"
  collection: "agent"

ingestion:
  urls:
    - "https://lilianweng.github.io/posts/2023-06-23-agent/"

๐Ÿ“– YAML Reference

Graph Config

version: "1.0"

graph:
  source_dir: "my_agent"               # Output directory for scaffolded Python code
  state_type: typeddict                 # "typeddict" (default, LangGraph-native) | "pydantic"
  state_schema: "graphs.state.AgentState"
  state_fields:
    messages: "List[BaseMessage]"       # โ†’ Annotated[List[BaseMessage], add_messages]
    next: "str"                         # Supervisor routing field
    context: "dict"
  shared_fields: [messages, context]    # Fields readable/writable by sub-agents
  memory:
    type: sqlite                        # "sqlite" | "in_memory" | omit for stateless
    db_path: ".checkpoints/agent.db"

Node Types

nodes:
  # Standard node โ€” calls a Python function
  my_node:
    module: "graphs.nodes.my_node"
    function: "my_node"
    chains: ["my_chain"]              # Chains to import into the node
    description: "Does something useful."

  # Async node
  async_node:
    module: "graphs.nodes.async_node"
    async_fn: true                    # Scaffolds `async def async_node(state)`

  # Supervisor node โ€” LLM-driven router
  supervisor:
    type: supervisor
    provider: openai                  # openai | anthropic | ollama | groq
    llm: gpt-4o
    route_field: next                 # State field the supervisor writes to (default: "next")
    system_prompt: "templates/supervisor.prompt"
    routes_to: [rag_agent, code_agent]

  # Sub-agent reference โ€” compiles recursively, nested under parent source_dir
  rag_agent:
    graphRef: "sub-agents/adaptive-rag.yaml"
    description: "Adaptive RAG sub-agent."

Chain Config

chains:
  retrieval_grader:
    module: "graphs.chains.retrieval_grader"
    runnable: "retrieval_grader"
    provider: anthropic                         # Per-chain provider
    llm: claude-3-5-haiku-20241022
    temperature: 0.0
    prompt: "retrieval_grader"                  # Loads templates/retrieval_grader.prompt
    tools: [web_search]                         # Binds tool imports into chain scaffold
    description: "Binary relevance grader."

Edge Types

edges:
  # Standard directed edge
  - type: standard
    start: retrieve
    end: grade_documents

  # Conditional edge with a router function
  - type: conditional
    start: grade_documents
    router:
      module: "routers.router"
      function: "route_after_grading"
    mappings:
      web_search: web_search
      generate: generate

  # Supervisor routing โ€” dispatches based on state[route_field]
  - type: supervisor_route
    start: supervisor
    routes_to: [rag_agent, code_agent]
    end: post_process

  # Tool loop โ€” LLM node โ†” ToolNode
  - type: tool_loop
    start: llm_node
    tool_node: tools
    end: END

  # Fan-out โ€” parallel dispatch via Send API
  - type: fan_out
    start: coordinator
    target: worker              # Node to fan out to (runs in parallel)
    field: tasks                # State field (iterable) to fan out over
    key: task                   # Key name in each Send payload
    end: aggregator

  # Human-in-the-loop โ€” pause before this node
  - type: standard
    start: generate
    end: human_review
    interrupt_before: true

Tool Config

tools:
  web_search:
    module: "graphs.tools.web_search"
    function: "web_search"
    description: "Queries Tavily for web results."

  # MCP Tool Client stub
  my_mcp_tool:
    module: "graphs.tools.my_mcp_tool"
    function: "my_mcp_tool"
    source: mcp
    server_url: "http://localhost:8000/mcp"
    description: "Calls remote MCP server."

๐Ÿ“Š Generated Flowchart

GraphForge auto-generates flowchart.md for every compiled agent:

flowchart TD
    START([START]) --> supervisor{{"Supervisor: supervisor\n(Routes request to sub-agent)"}}
    supervisor -.->|rag_agent| rag_agent__START
    supervisor -.->|code_agent| code_agent__START

    subgraph rag_agent ["rag_agent (Adaptive RAG Sub-Agent)"]
        direction TB
        rag_agent__START --> retrieve["retrieve\n(Pulls document chunks from vector store)"]
        retrieve --> grade_documents["grade_documents"]
        grade_documents --> generate["generate"]
    end

    subgraph code_agent ["code_agent (Code Generator Sub-Agent)"]
        direction TB
        code_agent__START --> plan["plan\n(Breaks task into plan)"]
        plan --> write_code["write_code"]
    end

    rag_agent__END --> post_process["post_process\n(Formats final response)"]
    code_agent__END --> post_process
    post_process --> END([END])

    classDef supervisorStyle fill:#d35400,stroke:#fff,stroke-width:2px,color:#fff;
    class supervisor supervisorStyle;
    classDef nodeStyle fill:#2980b9,stroke:#fff,stroke-width:2px,color:#fff;
    class post_process nodeStyle;

๐Ÿ“ Generated Output Structure

forge compile configs/agents/agent.yaml scaffolds the full hierarchy under source_dir:

my_agent/                               โ† Parent source_dir
โ”œโ”€โ”€ flowchart.md                        โ† Mermaid diagram of the multi-agent DAG
โ”œโ”€โ”€ main.py                             โ† Runnable entrypoint with app.stream()
โ”œโ”€โ”€ graphs/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ graph.py                        โ† Compiled StateGraph + checkpointer
โ”‚   โ”œโ”€โ”€ state.py                        โ† TypedDict AgentState with add_messages reducer
โ”‚   โ”œโ”€โ”€ chains/
โ”‚   โ”‚   โ””โ”€โ”€ post_process_chain.py
โ”‚   โ””โ”€โ”€ nodes/
โ”‚       โ”œโ”€โ”€ supervisor.py               โ† LLM routing scaffold
โ”‚       โ””โ”€โ”€ post_process.py
โ”‚
โ”œโ”€โ”€ adaptive_rag/                       โ† Sub-agent nested under my_agent/
โ”‚   โ”œโ”€โ”€ graphs/
โ”‚   โ”‚   โ”œโ”€โ”€ graph.py
โ”‚   โ”‚   โ”œโ”€โ”€ state.py
โ”‚   โ”‚   โ””โ”€โ”€ nodes/
โ”‚   โ””โ”€โ”€ routers/
โ”‚
โ””โ”€โ”€ code_agent/                         โ† Sub-agent nested under my_agent/
    โ”œโ”€โ”€ graphs/
    โ””โ”€โ”€ routers/

๐Ÿ” Observability (LangSmith)

Enable full step-by-step tracing in .env:

LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=your_langchain_api_key
LANGCHAIN_PROJECT=GraphForge-Agents

๐Ÿงช Tests

uv run pytest -v

CI runs on every push via .github/workflows/ci.yml.


๐Ÿค Contributing

See CONTRIBUTING.md for dev setup, how to add new edge/node types, and the PR process.


๐Ÿ“ฆ License

Released under the Apache 2.0 License. Version 0.2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentgraph_compiler-0.2.1.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentgraph_compiler-0.2.1-py3-none-any.whl (38.1 kB view details)

Uploaded Python 3

File details

Details for the file agentgraph_compiler-0.2.1.tar.gz.

File metadata

  • Download URL: agentgraph_compiler-0.2.1.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for agentgraph_compiler-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8337cc1771f787d4ac599ef5c93ab18a95d2fe076db7384d273c1266f6e1bcb0
MD5 68d52643ff47c9adf328f85987fd4005
BLAKE2b-256 55db883820c4ac3f75b5f080725898055f746a435185bc29024b0dfe6e242069

See more details on using hashes here.

File details

Details for the file agentgraph_compiler-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for agentgraph_compiler-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a70a3ad09091c582e84ad378614edc690d9a5b3079aa5abfe365fc0dd3705dd
MD5 7e33563457a7e4a24709575c9a99c2f4
BLAKE2b-256 35798ed44074ca45903ffdc86a1e787a3440c247427ea7cd59c51e5cf9a33105

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page