At Sangam, we build with Deep Agents. I wanted to go beyond using it and understand what really happens under the hood: how it plans, delegates and manages context. Siddhant suggested the best way to learn it: build something. So I took LangChain Academy’s Introduction to Deep Agents course, turned every lesson into a feature of my own project, and traced each one in LangSmith to see exactly how it works.
The project is TripMate, a weekend-trip planner. You tell it “Plan a 2-day trip from Pune, budget ₹6,000, I’m vegetarian and I hate long drives”. It checks the weather, finds places, works out a budget, writes a day-by-day plan, and can even “book” a hotel (a fake booking, after you approve it).

The lesson that changed how I think about agents was the last one: asynchronous subagents. To see why, you first need to see what normal subagents do.
1. A deep agent is a normal agent with a few extra parts
A basic agent is a loop: the model picks a tool, the tool runs, and that repeats until the model answers. That works for one or two steps. It falls apart on a long task: the context fills with raw tool output, and the model forgets what it was doing.
create_deep_agent keeps the same loop and adds a set of built-in parts around it:
- Planning — What it gives the agent: a
write_todostool to plan and track steps; In TripMate: “check weather → pick city → find places → write plan” - Filesystem — What it gives the agent:
ls,read_file,write_file,edit_file,glob,grep; In TripMate: notes, drafts, memory files - Subagents — What it gives the agent: a
tasktool to hand work to helper agents; In TripMate: weather, places, budget and critic agents - Skills — What it gives the agent: step-by-step guides the agent reads only when it needs them; In TripMate:
itinerary-writer,budget-planner - Memory — What it gives the agent: files that last after the chat ends; In TripMate:
/memories/user_preferences.md
2. The system prompt: the agent’s job description
An AI model doesn’t remember anything between calls. On every request you send it text: instructions first, then the conversation so far. The instructions part is called the system prompt. It’s the only way to tell the model who it is and how to behave.
TripMate’s system prompt starts like this:
You are TripMate, a weekend-trip planner.Your job: turn a request like "Plan a 2-day trip, budget ₹8,000" into asimple day-by-day itinerary, starting from the user's home city.
Then it has one short section per feature: Planning, Subagents, Skills, Memory, Booking, Rules. A rule like “Places come from places-agent. Only recommend places it returned.” stops the model from inventing a restaurant that doesn’t exist.
I learned to treat it like an API contract. Every time I added a feature in code, I also added a few lines to the prompt saying when to use it. Without those lines, the model mostly ignored the new feature.
3. Tools: what the agent can actually do
Before any subagents, TripMate needed real abilities. A tool is a Python function with the @tool decorator. The docstring is what the model reads to decide when to call it, so writing a clear docstring matters as much as writing the code.
@tooldef get_weather(city: str, days: int = 3, country_code: str = "") -> str: """Get the real daily weather forecast for a city (up to 16 days ahead).""" ...
TripMate has three:
get_weather— What it does: real forecast from the free Open-Meteo APIsearch_places— What it does: web search (Tavily) for places to visit in a citybook_hotel— What it does: a fake booking that returns a confirmation id; it exists so I could practise human approval
The first version had just these tools and one agent, and it worked. The agent called get_weather for two cities, picked the better one, then called search_places. The problem showed up later: every forecast and search result piled into the same context.
4. MCP: tools someone else already wrote
Writing every tool yourself gets old fast. MCP (Model Context Protocol) is a standard way for a service to offer its tools to any AI agent. You connect to an MCP server, and its tools show up as normal tools for the agent: same name, description and arguments as a @tool function.
Coming next in TripMate: your trip in your calendar. I’m planning to use MCP to connect TripMate to Google Calendar. Once your trip is planned, you’ll be able to say “add my Lonavala plan to my calendar”, and TripMate will add each part of the itinerary as its own event at the right time. Then your calendar reminds you of everything during the trip, so you don’t have to keep checking the plan. The idea is to load a Google Calendar MCP server with langchain-mcp-adapters (MultiServerMCPClient) and give its tools to a new calendar-agent subagent. This part isn’t built yet; it’s next on my list. I also want to try out more MCP servers like this to give TripMate more useful abilities. If you have ideas for MCP servers a trip planner should use, I’d love to hear them!
5. Planning: a to-do list the agent writes for itself
“Plan a 2-day trip” isn’t one step. It’s: check the weather, pick a city, find places, work out the budget, write the plan. On long tasks like this, models tend to skip steps or lose track halfway.
deepagents gives the agent a write_todos tool. Its first move is to write its own checklist, then update each item as it goes:
[completed] Check weather for Lonavala and Mahabaleshwar[in_progress] Find places in Mahabaleshwar[pending] Estimate the budget[pending] Write the itinerary
The tool doesn’t run any code against the outside world. It just saves the list into the agent’s state, and the list goes back to the model on every step. Seeing “2 of 4 done” keeps it on track. It also helps me: my Streamlit app shows this list under each answer, so I can see what the agent planned and what it actually did.
6. Skills: instructions read only when needed
The problem. An AI model doesn’t remember anything between calls. Everything it should know has to be sent as text on every single request. This text is called the context, and the instructions at the top of it are the system prompt.
Say I want TripMate to write itineraries a certain way: realistic timings, a backup plan for rain, costs marked as estimates. Plus a second set of rules for budgets. If I put all of that in the system prompt, it gets sent on every request, even when the user only asked “what’s the weather?”. That costs more, it’s slower, and the model gets distracted by rules that don’t apply.
The fix. Move those instructions out of the system prompt into a separate file, a skill. It’s a Markdown file with a short header:
---name: budget-plannerdescription: How to split a weekend-trip budget into travel / stay / food / buffer and show it as a cost table. Read this before estimating the cost of any trip.---
# Budget planner1. Check the inputs: home city, destination, days, budget...2. Split the money like this...3. Show a table with a "fits budget?" verdict...
How it works:
- deepagents puts only the name and description of each skill in the system prompt. That’s a couple of lines per skill.
- When the model reaches a step that matches a description (“I’m about to estimate costs”), it uses its file tool to read the full
SKILL.md. - It follows those steps for that task only.
So a skill is just instructions in a file. The only “AI” part is that the model decides when to open it, based on the description, the same way it decides when to call a tool.
TripMate has two skills:
itinerary-writer: how to turn weather, places and budget into a realistic day-by-day plan.budget-planner: how to split a budget into travel, stay, food and buffer, and show it as a table.
7. Memory: within a chat, and across chats
There are two kinds of memory, and they solve different problems.
Short-term: remembering this conversation. Without it, every message is a fresh start. You say “from Pune”, then “make it 3 days”, and the agent asks “from where?”. The fix is a checkpointer, which saves the conversation after every step under a thread_id:
agent = create_deep_agent(..., checkpointer=InMemorySaver())agent.invoke({"messages": [...]}, config={"configurable": {"thread_id": "chat-1"}})
Same thread_id means the same conversation. A new id starts a new chat.
Long-term: remembering the user. I don’t want to tell it “I’m vegetarian” in every new chat. So the agent saves lasting facts to /memories/user_preferences.md, and the system prompt tells it to read that file at the start of each request. Files under /memories/ are kept in a store, which survives across chats. Other files the agent writes disappear when the chat ends.
There’s also memory/AGENTS.md: defaults for all users (prices in ₹, a mid-range budget if none is given). It’s loaded into every run, and only I edit it.
8. Context management: what happens when the chat gets long
Everything the model sees on each call (prompt, chat, tool results) has a size limit, measured in tokens. A deep agent fills it fast: one web search can return pages of text. deepagents handles this for you in two ways:
- Offloading big results. When a tool returns a huge result, deepagents saves it to a file and shows the model a short preview with the file path. The model can
read_filethe parts it actually needs. - Summarization. When the conversation gets close to the model’s limit, older messages are replaced by a summary. The recent messages stay as they are.
You don’t write code for either; both are on by default. The thing to remember is that anything only in old messages can get summarized away. That’s why important data belongs in files, memory or state, not just in the chat. This comes up again with async subagents.
9. Where the agent’s files live, and letting it run code
Every deep agent has file tools (ls, read_file, write_file, edit_file…). A backend decides where those files really go. You choose it once, and the agent’s code doesn’t change:
- State — Files live…: inside the current chat only; In TripMate: scratch notes, drafts
- Filesystem — Files live…: in a real folder on your machine; In TripMate:
skills/,memory/AGENTS.md - Store — Files live…: in a database shared across chats; In TripMate:
/memories/ - Sandbox — Files live…: in an isolated machine that can also run code; In TripMate: not yet; the course’s advanced lesson
Sandboxes are where it gets powerful. A sandbox lets the agent write its own code and run it safely, instead of being limited to the tools you gave it. For example, say a user asks TripMate, “Show my trip budget as a pie chart.” There’s no chart tool, but with a sandbox the agent could write a few lines of Python, run them, and hand back the chart. The same goes for a packing checklist as a file, or a cost comparison of two destinations: no new tool is needed for each one. A few things worth knowing about sandboxes:
- One sandbox per chat thread. It’s created on the first run, woken up if it went idle, and recreated if it was deleted. A new sandbox gets a copy of the agent’s skills and
AGENTS.md, so editing a skill only affects new chats. - Treat everything from the sandbox as untrusted. Code output and even error messages could contain a prompt injection (text that tries to give the model new orders). So the sandbox holds no secrets, and files come out through a plain download button, not through the agent.
- The agent is built when the run starts. The mail tools and the sandbox only exist at runtime, so the course builds the agent in a factory function (
make_graph) instead of at import time. - Locally, there’s
LocalShell. It runs commands directly on your machine, with no isolation, so it only makes sense for your own experiments. - The interpreter. With
CodeInterpreterMiddleware, the agent can write a short script that calls its own tools in a loop. For example, it writes one file per customer in a single step, instead of making a separate tool call for each one.
10. Human-in-the-loop: ask before doing something real
Some actions shouldn’t happen without a person saying yes. Booking a hotel is one of them. Adding a rule for that tool was all it took:
interrupt_on={"book_hotel": {"allowed_decisions": ["approve", "reject"]}}
When the agent calls book_hotel, the run pauses before the tool runs. My Streamlit app shows the booking with Approve and Reject buttons. Clicking one resumes the run:
agent.invoke(Command(resume={"decisions": [{"type": "approve"}]}), config=config)
This needs a checkpointer (chat memory), because pausing means saving the run and loading it again later. If I reject the booking, the agent is told not to retry, and it asks what I’d like to change.
11. Subagents: helpers with their own clean context
What is a subagent?
A subagent is another agent that the main agent can hand a job to. It has its own instructions and its own tools. It does the job in a separate, fresh context, then sends back only a short answer.
Think of a manager and specialists. The manager doesn’t read every weather table or search result. They ask the weather specialist, “Which is better this weekend, Lonavala or Mahabaleshwar?”, and get back two lines. That keeps the main agent’s context small and focused on the plan.
In deepagents, the main agent gets a built-in task tool for this. You describe the subagents, and the model decides when to call task and which one to use.
The main agent waits
I wrote four subagents as plain dictionaries:
WEATHER_AGENT = { "name": "weather-agent", "description": "Weather for one or more cities, and comparing them.", "system_prompt": "You check weather... reply in 5 lines max + a verdict.", "tools": [get_weather],}
When the main agent decides to delegate, it calls the built-in task tool:
task(subagent_type="weather-agent", description="Compare this weekend's weather in Lonavala and Mahabaleshwar")
In LangSmith, I could follow the whole thing:
- A new agent starts with only the weather agent’s prompt and tools.
- It sees only the
descriptiontext, nothing from my chat. - It calls
get_weatherand gets a big block of forecast data back. - Only its final short message goes back to the main agent.
The forecast data never reaches the main agent. That’s the real point of subagents: they keep the main agent’s context clean. The main agent gets a summary, not the raw data.

There’s a catch, and I ran into it right away: the subagent knows nothing you didn’t put in the task. If the main agent writes “check the weather” without naming a city, the subagent can’t do it. So I added a rule to the system prompt: “Subagents see ONLY the task description. Put everything they need in it.”
Two more things I learned while building:
"tools": []means no tools, but leavingtoolsout means the subagent gets all of the main agent’s tools. Those are very different.- Subagents don’t get the main agent’s skills automatically. My budget agent needed
"skills": ["/skills/"]before it could read thebudget-plannerguide.
Fork mode: a subagent that has already read the chat
My critic agent kept missing things. The draft had a 4-hour drive, and the critic said “ok”. Why? It never saw “I hate long drives”, because the main agent forgot to copy that into the task.
The fix was one line:
CRITIC_AGENT = {"name": "critic-agent", "mode": "fork", ...}
A fork copies the main agent’s whole conversation into the subagent, along with the main system prompt, then adds the critic’s own instructions at the end. Now the critic reads my actual words, and it caught both the long drive and a non-vegetarian dinner spot.
The cost: every critic call resends the whole conversation.
Regular or forked, all these subagents share one thing: while they work, the main agent sits and waits.
12. Async subagents: the main agent keeps talking
For a weather lookup that takes 3 seconds, waiting is fine. But imagine a train-finder that searches several booking sites and takes two minutes. With a regular subagent, the user stares at a spinner for two minutes and can’t even say “actually, make it Saturday”.
Async subagents fix this. The main agent starts a background task, gets an id back right away, and keeps chatting with the user. It can check progress, send new instructions or cancel the task at any time.
Two ways to call a subagent
- How it’s called — Regular subagent: the built-in
tasktool; Async subagent:start_async_taskand four other tools - Where it runs — Regular subagent: in the same process; Async subagent: on a remote Agent Protocol server, through the LangGraph SDK
- Main agent — Regular subagent: waits until it returns; Async subagent: carries on right away
- How you refer to it — Regular subagent: you don’t; it’s just one tool call; Async subagent: a
task_idsaved in state - Good for — Regular subagent: quick work the main agent needs before its next step; Async subagent: long or parallel work it shouldn’t wait for
Setting one up
An async subagent has no prompt and no tools. It points to an agent that’s already deployed:
from deepagents import AsyncSubAgent, create_deep_agent
subagents = [ AsyncSubAgent( name="train-finder", description="Finds trains/buses from the home city. Slow — run in background.", graph_id="train_finder", url="http://127.0.0.1:2024", ),]agent = create_deep_agent(model=model, subagents=subagents)
The two settings are things you already know if you’ve run langgraph dev:
graph_idis the key under"graphs"inlanggraph.json, the same namelanggraph devuses to decide which graph to serve.urlis the server’s address. Forlanggraph dev, that’shttp://127.0.0.1:2024.
So an async subagent is just another deployed graph. It can run on a LangSmith deployment, a self-hosted server, or langgraph dev on your laptop.
It goes in the same subagents= list as the regular dictionaries. You don’t need separate lists, and you don’t add any middleware yourself. deepagents works out which is which and adds AsyncSubAgentMiddleware for you.
Five new tools, next to task
start_async_task— What it does: creates a thread on the remote server, starts a run on it, and returns atask_idright awaycheck_async_task— What it does: gets the current status of a task; if it’s finished, the result comes back tooupdate_async_task— What it does: sends new instructions to a running task. It stops the current run and starts a fresh one on the same thread, so the subagent sees the full history plus the new instructions. Thetask_idstays the same.cancel_async_task— What it does: stops a running tasklist_async_tasks— What it does: the live status of every tracked task, optionally filtered by status
These are added next to task, not instead of it. deepagents already adds a general-purpose regular subagent by default, so the main agent ends up with six tools for delegating. In one chat, it can send a quick job to an in-process subagent and a long one to a remote server.
What a conversation looks like
You: Plan a weekend in Mahabaleshwar from Pune.Agent: start_async_task(train-finder, "Pune → Mahabaleshwar, Sat morning") → task_id abc123Agent: "I've started looking for trains (task abc123). Meanwhile, here's the weather..."
... you keep chatting; train-finder keeps working on its own ...
You: How are the trains coming along?
Agent: check_async_task(abc123) → status: running
Agent: "Still searching."
You: Any update?
Agent: check_async_task(abc123) → status: success, result: "..."
Agent: "Here are the trains."
Notice that each “check” is a separate step, later on. Nothing happens automatically in between. The subagent doesn’t tell the main agent when it’s done; the main agent finds out only when it calls check_async_task.
Where the task lives: state, not messages
Each started task is saved as an AsyncTask record in the main agent’s state, under async_tasks. The record holds:
- the
task_id(the thread id on the server); - which subagent it belongs to;
- the
run_idand status; - when it was created, last checked and last updated.
This is my favourite detail. Because the record lives in state, it survives context compaction. When a chat gets long, old messages are summarized away, but the task record stays. You can ask about the trains twenty messages later and the agent still knows abc123.
When to use which
- Regular subagent — When: the job is quick, and the main agent needs the answer before its next step (weather, a budget estimate)
- Fork — When: the subagent needs the whole conversation (a reviewer or critic)
- Async subagent — When: the job is slow, you want several long jobs running while the user keeps chatting, or it fits better on its own separate deployment
13. What the experiments taught me
- LangSmith is the real teacher. Every lesson made more sense once I opened the trace and saw the nested subagent run: what went in, what came out, how many tokens.
- LangGraph Studio shows the graph and the state live. Watching a
taskcall happen is far clearer than any diagram. - Async needs a running server. Even locally, the subagent’s graph has to be listed in
langgraph.jsonandlanggraph devhas to be up, or the main agent has nothing to call.
14. What I’m building next
- Async
train-findersubagent - Scheduled jobs (e.g. a weather re-check the evening before the trip)
- Live streaming in the UI
- Self-checking with
RubricMiddleware - Evals in LangSmith
- OAuth per user
- …and many more
The biggest lesson from the course: a deep agent is mostly about managing context and time. Once I saw it that way, every feature made sense.
You’ll soon be able to try TripMate for your own next weekend trip. I’ll share the repo link once it’s done.