Skip to main content
LangChain’s create_agent and a LangGraph StateGraph own the agent loop: the framework calls the model and runs the tools. Hue ships no LangChain instrumentation. Record the loop with the Python SDK: a request span around invoke, and a middleware that opens a Hue model span around each model call and a tool span around each tool call. Keep your model provider, prompts and tools as they are. create_agent and AgentMiddleware are LangChain 1.x APIs; this page was verified with langchain 1.4.6, langgraph 1.2.16 and hue-run 0.13.2.

Record the loop

model, tools and prompt are your existing agent’s; pass the provider name you use ("openai", "anthropic"). For ainvoke and astream, implement awrap_model_call and awrap_tool_call with the same bodies and await handler(request). Each model and tool span becomes a child of the request span: LangGraph runs its nodes in copies of the caller’s context, in threads and in asyncio tasks alike. In a hand-built StateGraph, open hue.model and hue.tool inside the nodes that call the model and run tools; the request span around graph.invoke is the same.

What Hue stores

  • The request span holds the user’s question and the final reply, the session and the user ID; Hue titles the trace from the question.
  • Each model span holds the messages the framework sent and the messages it got back, in the OpenAI chat shape convert_to_openai_messages produces (gen_ai.input.messages, gen_ai.output.messages), the tool definitions (gen_ai.tool.definitions), the system prompt (gen_ai.system_instructions), the model name and the usage. A tool-calling step keeps its tool_calls in the output message.
  • Each tool span holds the arguments the agent passed and the result it got back, under the tool call ID the model issued, so the tool call and its result are linked in the trace.
Pass capture_content=False to record only metadata; see Content capture. Flush and verify as the Python SDK page describes: Verify, and Async servers when the agent serves from FastAPI.