LangChain Agent Builder's Guide: From create_agent to Streaming Structured Output
LangChain's create_agent bundles the entire tool-calling loop into a single API, which cuts boilerplate for production assistants. The structured output retry and streaming snapshot behavior are the kind of details that determine whether a typed response pipeline works reliably outside a demo.
LangChain's official Agent definition is "model + Harness," where Harness covers everything outside the model loop: prompts, tools, middleware, and state. create_agent is the minimal Harness implementation, letting a developer wire up a working assistant with a few lines. The internal loop runs user input to model decision, optional tool calls, result return, and final reply, all managed without hand-written while loops or manual ToolMessage construction.
The note walks through three practical layers. Tools are defined with the @tool decorator, where docstrings and parameter names become part of the model's visible prompt. Runtime-only data like user IDs goes through a ToolRuntime parameter that stays out of the tool schema. For structured output, ToolStrategy wraps a Pydantic schema as a hidden structured-output tool, with built-in retry on validation failures. Streaming uses stream_events, with projections for message text, toolCalls, and tool lifecycle, but structured output streams arrive as full snapshots rather than deltas, so frontend code must check field completeness before rendering.
A complete example combines DeepSeek via an OpenAI-compatible base URL, two tools, a four-field WeatherAnswer schema, and streaming. The author also recommends a learning path: get the minimal agent running, inspect LangSmith trace trees, add ToolStrategy, switch to stream_events, then combine them.
create_agent's abstraction hides the tool-calling loop so completely that a developer can ship a working agent without understanding LangGraph, but debugging still requires LangSmith trace trees to see the loop's intermediate nodes.
The decision to expose ToolRuntime as a separate parameter is a clean solution to a real problem: keeping secrets and session state out of the model's context window while still letting tools access them.
Streaming structured output as snapshots rather than deltas is a deliberate trade-off: it simplifies backend implementation but pushes completeness checks to the frontend, turning a streaming API into a polling-like pattern for typed data.