Tools & Agents
Deep dive into tools, the create_agent loop, and streaming/async invocation.
Defining tools
@tool
Docstrings and type hints become JSON Schema for the model.
Plain callables
Any annotated Python function with a docstring can be passed in tools=[...].
Runtime context
Tools can read agent state (e.g. user_id) via runtime APIs; middleware often writes state before tool runs.
create_agent
invoke
State includes full messages for audit/debug.
stream
async
Use in FastAPI / asyncio services.
Multiple tools & parallelism
LangGraph may run multiple tool_calls in parallel when safe. Design read-only tools for parallelism; make writes idempotent.
Errors
Exceptions often become ToolMessage errors for the model to recover. Centralize logging in middleware.
ToolNode in LangGraph
Custom graphs use ToolNode (LangGraph Workflows); create_agent wraps this internally.
Anti-patterns
Vague docstrings, one mega-tool, non-idempotent writes on retry.