> ## Documentation Index
> Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain DeepAgents

> Trace multi-agent research pipelines built with DeepAgents

Automatically capture the full multi-agent hierarchy of [DeepAgents](https://github.com/langchain-ai/deepagentsjs) pipelines. DeepAgents builds on LangChain, so traceroot instruments it via the LangChain callback manager.

## Install

> [tab] Python
>
> ```bash theme={null}
> pip install traceroot deepagents langchain-core langchain-anthropic
> ```

> [tab] TypeScript
>
> ```bash theme={null}
> npm install @traceroot-ai/traceroot deepagents @langchain/core @langchain/anthropic
> ```

## Set up

> [tab] Python
>
> ```python theme={null}
> import traceroot
> from traceroot import Integration
>
> traceroot.initialize(integrations=[Integration.LANGCHAIN])
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import * as lcCallbackManager from '@langchain/core/callbacks/manager';
> import { TraceRoot } from '@traceroot-ai/traceroot';
>
> TraceRoot.initialize({
>   instrumentModules: { langchain: lcCallbackManager },
> });
> ```

## Usage

> [tab] Python
>
> ```python theme={null}
> from traceroot import observe, using_attributes
> from deepagents import create_deep_agent
>
> research_subagent = {
>     "name": "research-agent",
>     "description": "Searches the web to gather information on a topic.",
>     "system_prompt": "You are a thorough research agent. Cite sources and organise findings clearly.",
>     "tools": [web_search],
> }
>
> supervisor = create_deep_agent(
>     model="claude-sonnet-4-6",
>     system_prompt="You are a research supervisor. Delegate tasks to sub-agents and synthesise their outputs.",
>     subagents=[research_subagent],
> )
>
> @observe(name="research_session", type="agent")
> def run_research(query: str) -> str:
>     result = supervisor.invoke({"messages": [{"role": "user", "content": query}]})
>     messages = result.get("messages", [])
>     return messages[-1].content if messages else ""
>
> with using_attributes(user_id="demo-user", session_id="research-session"):
>     report = run_research("What are the latest AI agent frameworks in 2025?")
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import { observe, usingAttributes } from '@traceroot-ai/traceroot';
> import { createDeepAgent, type SubAgent } from 'deepagents';
> import { ChatAnthropic } from '@langchain/anthropic';
> import { HumanMessage } from '@langchain/core/messages';
>
> const llm = new ChatAnthropic({ model: 'claude-sonnet-4-20250514', temperature: 0 });
>
> const researchSubAgent: SubAgent = {
>   name: 'research-agent',
>   description: 'Researches a specific topic in depth.',
>   systemPrompt: 'You are a thorough research agent. Gather comprehensive, current information and cite sources.',
>   tools: [internetSearch],
> };
>
> const supervisor = createDeepAgent({
>   model: llm,
>   tools: [internetSearch],
>   systemPrompt: 'You are a research supervisor. Delegate tasks to sub-agents and synthesise their outputs.',
>   subagents: [researchSubAgent],
> });
>
> await usingAttributes(
>   { userId: 'demo-user', sessionId: 'research-session' },
>   () =>
>     observe({ name: 'research_session', type: 'agent' }, async () => {
>       const result = await supervisor.invoke(
>         { messages: [new HumanMessage('What are the latest AI agent frameworks in 2025?')] },
>         { recursionLimit: 100 },
>       );
>       const messages = result.messages ?? [];
>       console.log(messages[messages.length - 1]?.content);
>     }),
> );
> ```

## Verify

Run your code and confirm the trace arrives:

1. **In the traceroot UI**: Navigate to **Tracing > Traces** in [traceroot Cloud](https://app.traceroot.ai). You should see a trace with root span `research_session`, the name passed to `observe`.
2. **Via the CLI**: Run `traceroot traces list` to inspect your recent traces from the terminal.

## What gets captured

| Attribute | Description |
| - | - |
| Supervisor steps | Each supervisor reasoning and delegation step |
| Sub-agent calls | Each sub-agent invocation with its own span |
| Tool calls | Tool inputs and outputs within sub-agents |
| LLM calls | All LLM calls across the full agent hierarchy |
| Token usage | Aggregated across all agents and LLM calls |
| Cost | Aggregated when the underlying model IDs match traceroot's pricing table |

## Limitations

* DeepAgents is built on LangChain. For TypeScript projects, `instrumentModules` must be configured with `@langchain/core/callbacks/manager`.

## Run the example

Clone the repo and run a complete agent end-to-end.

> [card] [Python](https://github.com/traceroot-ai/traceroot/tree/main/examples/python/deepagents)
>
> Run the Python example

> [card] [TypeScript](https://github.com/traceroot-ai/traceroot/tree/main/examples/typescript/deepagents)
>
> Run the TypeScript example

## Next steps

> [card] [Python SDK Reference](https://traceroot.ai/docs/tracing/python-sdk.md)
>
> Explore the full Python SDK reference and instrumentation options.

> [card] [TypeScript SDK Reference](https://traceroot.ai/docs/tracing/typescript-sdk.md)
>
> Explore the full TypeScript SDK reference and configuration options.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.