Deep Agents
Trace LangChain Deep Agents with cetra from Python, through the OpenInference LangChain instrumentation. Deep Agents have no instrumentor of their own: the langchain one covers them, as it covers LangChain and LangGraph.
Install
Section titled “Install”pip install "cetra-sdk[langchain]" deepagents langchain-openaiSet up
Section titled “Set up”import jsonimport os
import cetrafrom deepagents import create_deep_agentfrom langchain.tools import toolfrom langchain_core.messages import HumanMessagefrom langchain_openai import ChatOpenAIfrom pydantic import SecretStr
cetra.init(instrument=["langchain"])
@tooldef get_weather(city: str) -> str: """Look up the weather for a city.""" return json.dumps({"temperature_c": 18, "conditions": "sunny", "city": city})
model = ChatOpenAI(model="gpt-4o-mini", api_key=SecretStr(os.environ["OPENAI_API_KEY"]))agent = create_deep_agent( model=model, tools=[get_weather], system_prompt="You are a weather assistant.",)agent.invoke({"messages": [HumanMessage("What's the weather in Paris?")]})
cetra.flush()What you get
Section titled “What you get”- The run is the LangGraph tree: a
LangGraphchainspan as the root, achainspan per node (model,tools), anllmspan per model call and atoolspan per tool call. - Each model call’s token counts and cost, computed from the built-in prices, are on its
llmspan. - Deep Agents’ built-in file and sub-agent tools are sent with every model call.
- Nothing in the trace’s columns identifies Deep Agents:
ls_integration=deepagentsstays in the root span’s metadata.
Limits
Section titled “Limits”- Middleware steps appear as
agentspans. - The fixture was captured with deepagents 0.7.32, langchain-openai 1.7.3 and openinference-instrumentation-langchain 0.1.81.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.