Deep AgentsDeep Agents 0.7 · Python 3.11+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
28 small wins to finish your pathNext lesson →

CompiledSubAgent: your own agent as a subagent

CompiledSubAgent wraps an agent or LangGraph graph you already built, with a name and a description, so a deep agent can delegate to it through the task tool like any other subagent.

Last updated: 29 Sep, 2026 · Deep Agents 0.7

The video defines subagents as dictionaries. The docs add a second form for when you already have an agent: build it with LangChain's create_agent or as a LangGraph graph, then wrap it. The graph needs a messages key in its state, which create_agent has.

The CompiledSubAgent syntax

python
from deepagents import CompiledSubAgent

checker = CompiledSubAgent(name="budget-checker", description="...", runnable=my_graph)
agent = create_deep_agent(model=model, subagents=[checker])

A budget checker built with create_agent

The checker is a plain LangChain agent with one tool, add_costs. The main agent must not do sums itself; it sends the amounts to the checker. Start trip.py with both tools, from write_todos: planning with TodoListMiddleware:

python
from langchain.tools import tool

CATALOG = {
    "paris": {
        "flight": ["Return flight Delhi to Paris: 42,000 rupees"],
        "hotel": ["Seine Budget Inn, Latin Quarter: 5,200 rupees a night",
                  "Hotel Lumiere, Montmartre: 7,500 rupees a night",
                  "Le Grand Opera Hotel: 16,000 rupees a night"],
        "sight": ["Eiffel Tower summit: 3,100 rupees", "Louvre Museum: 2,000 rupees",
                  "Seine river cruise: 1,500 rupees", "Versailles day trip: 2,600 rupees",
                  "Montmartre walking tour: free"],
        "food": ["Cafe breakfast and bistro dinner: 3,000 rupees a day"],
    },
}


@tool
def search_travel(city: str, kind: str) -> str:
    """Search the travel catalog. kind is "flight", "hotel", "sight" or "food". Prices are in rupees."""
    entries = CATALOG.get(city.lower(), {}).get(kind)
    return "\n".join(entries) if entries else f"The catalog has no {kind} entries for {city}."


@tool
def add_costs(amounts: list[int]) -> int:
    """Add rupee amounts and return the exact total. Use it for every sum."""
    return sum(amounts)
python
from deepagents import create_deep_agent
from langchain.chat_models import init_chat_model

model = init_chat_model("groq:openai/gpt-oss-120b", temperature=0, max_retries=6)
python
from deepagents import CompiledSubAgent
from langchain.agents import create_agent

budget_graph = create_agent(
    model,
    tools=[add_costs],
    system_prompt="Add the amounts you are given with add_costs. Reply with the total and whether it fits the budget.",
)
budget_checker = CompiledSubAgent(
    name="budget-checker",
    description="Adds up a list of trip costs and checks them against a budget.",
    runnable=budget_graph,
)

The main agent

python
agent = create_deep_agent(
    model=model,
    tools=[search_travel],
    subagents=[budget_checker],
    system_prompt="You plan trips. Look up prices with search_travel. Do not add numbers yourself: send the "
                  "separate amounts and the budget to budget-checker with the task tool. Answer in two short sentences.",
)

Checking a trip against a 60,000 rupee budget

ExampleAPI keytrip.py, continued
request = "Does a Delhi-Paris flight plus 3 nights at Hotel Lumiere fit a budget of 60,000 rupees?"
result = agent.invoke({"messages": [{"role": "user", "content": request}]})

for message in result["messages"]:
    print(f"{message.type:<5}", message.text or [(c["name"], c["args"]) for c in message.tool_calls])

What the run shows

  • The main agent looked up the prices with search_travel. Its first try used Delhi as the city and found nothing, so it searched Paris for the hotels and the flight.
  • It called task with subagent_type budget-checker and put the separate amounts, the nights and the budget in the job description.
  • The checker answered in one word, "no": the job description asked for yes or no.
  • The reply is no, with the total, 64,500 rupees. The main agent worked that figure out for its explanation even though its prompt said not to add numbers itself; a prompt rule is advice, and the checker's verdict is the part it could not change.

Dictionary subagent vs CompiledSubAgent

Dictionary (SubAgent)CompiledSubAgent
You giveName, description, prompt, toolsName, description, a built graph
Deep Agents builds itYes, with file tools and summarizationNo, it runs your graph as it is
Inherits the main agent's interrupt_onYesNo

Where a compiled subagent fits

  • You already have a working LangChain agent or LangGraph workflow.
  • A subagent that must stay small: no file tools, only its own tool.
  • A graph with custom steps that a prompt and tools cannot express.
Watch out. A compiled subagent does not inherit the main agent's human-in-the-loop settings. If it has a risky tool, configure approval inside the graph you wrap.
Try it yourself
  • Raise the budget to 70,000 rupees and read the checker's answer.
  • Swap Hotel Lumiere for Le Grand Opera Hotel in the request.
  • Print budget_graph.get_graph().nodes to see the checker's own nodes.

This is what real progress feels like.