StaticcreateCreate a new AgentBuilder instance
The name of the agent (defaults to "default_agent")
New AgentBuilder instance
StaticwithConvenience method to start building with a model directly
The model identifier (e.g., "gemini-2.5-flash")
New AgentBuilder instance with model set
Set the model for the agent
The model identifier (e.g., "gemini-2.5-flash")
This builder instance for chaining
Add tools to the agent
Rest...tools: BaseTool[]Tools to add to the agent
This builder instance for chaining
Set the planner for the agent
The planner to use
This builder instance for chaining
Set the code executor for the agent
The code executor to use for running code
This builder instance for chaining
Add sub-agents to the agent
Sub-agents to add to the agent
This builder instance for chaining
Set the before agent callback
Callback to invoke before agent execution
This builder instance for chaining
Set the after agent callback
Callback to invoke after agent execution
This builder instance for chaining
Set the before model callback for LLM interaction
Callback to invoke before calling the LLM
This builder instance for chaining
Set the after model callback for LLM interaction
Callback to invoke after receiving LLM response
This builder instance for chaining
Set the before tool callback for tool execution
Callback to invoke before running a tool
This builder instance for chaining
Set the after tool callback for tool execution
Callback to invoke after running a tool
This builder instance for chaining
Add plugins to the agent for lifecycle hooks and behavior extensions
Rest...plugins: BasePlugin[]Plugin instances to add to the agent
This builder instance for chaining
Configure fallback models to use when the primary model hits rate limits. Models will be tried in order when the primary model fails with a 429 error.
Rest...models: string[]Fallback model names in priority order
This builder instance for chaining
StaticwithConvenience method to start building with an existing agent
The agent instance to wrap
New AgentBuilder instance with agent set
Provide an already constructed agent instance. Further definition-mutating calls (model/tools/instruction/etc.) will be ignored with a dev warning.
Configure as a sequential agent
Sub-agents to execute in sequence
This builder instance for chaining
Configure as a parallel agent
Sub-agents to execute in parallel
This builder instance for chaining
Configure as a loop agent
Sub-agents to execute iteratively
Maximum number of iterations
This builder instance for chaining
Configure as a LangGraph agent
Graph nodes defining the workflow
The starting node name
This builder instance for chaining
Configure session management with optional smart defaults
Session service to use
Session configuration options (userId and appName)
This builder instance for chaining
Configure with an existing session instance
Existing session to use
This builder instance for chaining
Configure memory service for the agent
Memory service to use for conversation history and context
This builder instance for chaining
Configure event compaction for automatic history management
Event compaction configuration
This builder instance for chaining
Configure with an in-memory session with custom IDs Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
Session configuration options (userId and appName)
This builder instance for chaining
Build the agent and optionally create runner and session
Built agent with optional runner and session
Type-safe build method for agents with output schemas Provides better type inference for the ask method return type
Quick execution helper - build and run a message
Message to send to the agent (string or full message object)
Agent response
AgentBuilder - A fluent interface for creating AI agents with automatic session management
Provides a simple, chainable API for building different types of agents (LLM, Sequential, Parallel, Loop, LangGraph) with tools, custom instructions, and multi-agent workflows. Sessions are automatically created using in-memory storage by default.
Example