Skip to main content
The 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

Source: crates/goose/src/agents/agent.rs:136-153

Configuration

AgentConfig

Configuration for Agent initialization.
Source: 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 Agentic
bool
required
Whether to disable automatic session naming
GoosePlatform
required
Platform type: GooseCli or GooseDesktop

GoosePlatform

Source: crates/goose/src/agents/agent.rs:91-94

Constructor Methods

new()

Create a new Agent with default configuration.
Returns: Agent instance with default settings Source: crates/goose/src/agents/agent.rs:205-216 Example:

with_config()

Create an Agent with custom configuration.
AgentConfig
required
Custom agent configuration
Returns: Configured Agent instance Source: 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
Returns: Stream of AgentEvent including messages, tool calls, and system notifications Source: crates/goose/src/agents/agent.rs:871-1078 Example:

provider()

Get the current LLM provider.
Returns: Arc reference to the active provider Source: 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
Source: 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
Source: crates/goose/src/agents/agent.rs:818-830

list_extensions()

Get all active extensions.
Returns: Vector of extension names Source: 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
Returns: Vector of available MCP tools Source: 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
Returns: Tuple of (request_id, result) Source: 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
Source: crates/goose/src/agents/agent.rs:843-862

Events

AgentEvent

Events emitted during agent execution.
Source: 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
Source: crates/goose/src/agents/agent.rs:591-611

load_extensions_from_session()

Restore extensions from session metadata.
&Session
required
Session containing extension metadata
Returns: Vector of load results indicating success/failure per extension Source: crates/goose/src/agents/agent.rs:638-713