Creates an instance of the Agent.
Optionalconfig: AgentConfigThe configuration for the agent.
ReadonlymessagesThe conversation history of messages between user and assistant.
ReadonlystateAgent state storage accessible to tools and application logic. State is not passed to the model during inference.
ReadonlyconversationConversation manager for handling message history and context overflow.
ReadonlyhooksHook registry for managing event callbacks. Hooks enable observing and extending agent behavior.
The model provider used by the agent for inference.
OptionalsystemThe system prompt to pass to the model provider.
The tools this agent can use.
The tool registry for managing the agent's tools.
Invokes the agent and returns the final result.
This is a convenience method that consumes the stream() method and returns only the final AgentResult. Use stream() if you need access to intermediate streaming events.
Arguments for invoking the agent
Promise that resolves to the final AgentResult
Streams the agent execution, yielding events and returning the final result.
The agent loop manages the conversation flow by:
Use this method when you need access to intermediate streaming events. For simple request/response without streaming, use invoke() instead.
An explicit goal of this method is to always leave the message array in a way that the agent can be reinvoked with a user prompt after this method completes. To that end assistant messages containing tool uses are only added after tool execution succeeds with valid toolResponses
Arguments for invoking the agent
Async generator that yields AgentStreamEvent objects and returns AgentResult
Orchestrates the interaction between a model, a set of tools, and MCP clients. The Agent is responsible for managing the lifecycle of tools and clients and invoking the core decision-making loop.