Agent is the main orchestrator in Goose that manages conversations, extensions, tools, and provider interactions.
Overview
The Agent is responsible for:- Managing conversation flow and message handling
- Coordinating tool execution (both platform and extension tools)
- Managing extensions (MCP servers, frontend tools)
- Handling permission checks and confirmations
- Processing retry logic and error recovery
- Auto-compaction of conversation history
Struct Definition
crates/goose/src/agents/agent.rs:136-153
Configuration
AgentConfig
Configuration for Agent initialization.crates/goose/src/agents/agent.rs:106-113
Arc<SessionManager>
required
Manages session persistence and retrieval
Arc<PermissionManager>
required
Handles permission policies for tool execution
Option<Arc<dyn SchedulerTrait>>
Optional scheduler for recurring tasks
GooseMode
required
Operating mode:
Auto, Chat, or Agenticbool
required
Whether to disable automatic session naming
GoosePlatform
required
Platform type:
GooseCli or GooseDesktopGoosePlatform
crates/goose/src/agents/agent.rs:91-94
Constructor Methods
new()
Create a new Agent with default configuration.crates/goose/src/agents/agent.rs:205-216
Example:
with_config()
Create an Agent with custom configuration.AgentConfig
required
Custom agent configuration
crates/goose/src/agents/agent.rs:218-252
Example:
Core Methods
reply()
Process a user message and generate a streaming response.Message
required
The user’s input message
SessionConfig
required
Session configuration including ID and settings
Option<CancellationToken>
Token to cancel the operation
AgentEvent including messages, tool calls, and system notifications
Source: crates/goose/src/agents/agent.rs:871-1078
Example:
provider()
Get the current LLM provider.crates/goose/src/agents/agent.rs:447-452
Extension Management
add_extension()
Add a new extension to the agent.ExtensionConfig
required
Configuration for the extension (MCP, STDIO, or Frontend)
&str
required
Session ID to associate the extension with
crates/goose/src/agents/agent.rs:715-734
Example:
remove_extension()
Remove an extension from the agent.&str
required
Name of the extension to remove
&str
required
Associated session ID
crates/goose/src/agents/agent.rs:818-830
list_extensions()
Get all active extensions.crates/goose/src/agents/agent.rs:832-837
list_tools()
Get all available tools for a session.&str
required
Session ID
Option<String>
Optional filter for specific extension
crates/goose/src/agents/agent.rs:796-816
Tool Execution
dispatch_tool_call()
Execute a single tool call.CallToolRequestParams
required
Tool call parameters (name, arguments)
String
required
Unique request identifier
Option<CancellationToken>
Token to cancel the operation
&Session
required
Current session context
crates/goose/src/agents/agent.rs:495-587
Permission Handling
handle_confirmation()
Handle user confirmation for a tool execution.String
required
The tool request ID awaiting confirmation
PermissionConfirmation
required
User’s permission decision
crates/goose/src/agents/agent.rs:843-862
Events
AgentEvent
Events emitted during agent execution.crates/goose/src/agents/agent.rs:156-161
Message
A conversation message (user, assistant, tool results)
(String, ServerNotification)
Notification from an MCP server
{ model: String, mode: String }
The active model changed (for lead-worker providers)
Conversation
Conversation history was replaced (e.g., after compaction)
Session State Management
save_extension_state()
Persist extension state to session metadata.&SessionConfig
required
Session configuration
crates/goose/src/agents/agent.rs:591-611
load_extensions_from_session()
Restore extensions from session metadata.&Session
required
Session containing extension metadata
crates/goose/src/agents/agent.rs:638-713
Related Types
- Session - Session management
- Conversation - Message history
- Config - Configuration system