Preview — full styling will appear after the next deploy completes.

agentic-ai-patterns

Subgraph

Reusable hierarchical graphs

A parent graph calls compiled child graphs as ordinary nodes, enabling modular composition and reuse of agent logic across multiple workflows.

flowchart TD
    S([__start__]) --> L
    subgraph search
        L[llm] -->|tool_calls| T[tools]
        T --> L
        L -->|no tool calls| C[collect]
    end
    C --> SN
    subgraph summary
        SN[summarise]
    end
    SN --> E([__end__])

Subgraphs bring software engineering principles — encapsulation, reuse, separation of concerns — to LangGraph. A child graph is compiled as an independent `CompiledGraph` and then called as a regular node inside any parent graph. The parent's state flows in, the child's final state flows back out, and the parent continues.

In this example, a `search_subgraph` runs a full ReAct loop against a database and returns raw results. A `summary_subgraph` then polishes those raw results into a human-friendly report. The parent graph simply calls them in sequence — it doesn't know or care about their internal complexity.

Subgraphs are especially powerful when the same retrieval or processing logic is needed in multiple parent workflows. They can also simplify testing: each subgraph can be run and unit-tested independently before integration into the larger pipeline.