The AgentNode class wraps a pydantic-ai Agent so LLM calls slot into the same Chain-of-Responsibility pattern as any other node. Subclasses implement two methods:
get_agent_config() — returns an AgentConfig describing the model provider, model name, structured output type, tools, and instructions.
process() — runs the underlying Agent, validates outputs against OutputType, and saves them with save_output().
See LLM Providers for per-provider configuration details.
AgentConfig
Notable fields:
instructions — the system prompt for the underlying pydantic-ai Agent. You can also register per-run context via the @self.agent.instructions decorator inside process().
output_type — a Pydantic model (subclass of AgentNode.OutputType) for structured output, or str for plain text.
deps_type — a Pydantic model exposed via RunContext so tools and instruction callbacks can read dependencies the node computes at runtime.
tools, builtin_tools — pydantic-ai tool definitions.
instrument — defaults to True; set False to opt this node out of Langfuse instrumentation even when the workflow is traced.
AgentNode base class
AgentNode runs asynchronously. Call await self.agent.run(...) or async with self.agent.run_stream(...) — pydantic-ai’s run_sync() will not work inside the workflow’s event loop.
Implementation examples
Without dependencies
With dependencies and dynamic instructions
Use deps_type + @self.agent.instructions to inject runtime context (for example, retrieval results in a RAG node) into the system prompt at call time:
Key features
- Type-safe outputs — Pydantic
OutputType validates what the model returns.
- Flexible dependencies —
DepsType + RunContext plug structured context into tools and instructions.
- Seven model providers — switch between OpenAI, Azure OpenAI, Anthropic, Google Gemini, Google Vertex AI, Bedrock, and Ollama by changing one enum.
- Dynamic instructions — augment the system prompt per run via
@self.agent.instructions.
- Tool integration — register pydantic-ai tools or built-in tools via
AgentConfig.tools / builtin_tools.
- Langfuse-ready — tracing is on by default via
instrument=True; the workflow decides whether traces are actually exported.