Skip to main content
Agents are the core orchestration component of Goose. They manage the conversation flow between users, AI models, and tools, coordinating complex multi-step tasks autonomously.

What is an Agent?

An agent in Goose is a stateful orchestrator that:
  • Maintains conversation context and history
  • Invokes AI models with appropriate prompts and tools
  • Executes tool calls returned by the model
  • Manages permissions and security checks
  • Handles errors and retries
  • Coordinates with subagents for complex workflows

Agent Lifecycle

The typical lifecycle of an agent interaction:

1. Initialization

When an agent is created, it:

2. Message Processing

When a user sends a message:
  1. Build Context: Gather conversation history, system prompts, and available tools
  2. Model Invocation: Send to AI provider with streaming enabled
  3. Stream Processing: Handle chunks as they arrive (text or tool calls)
  4. Tool Execution: Execute any tools the model requests
  5. Continue Loop: Feed tool results back to model
  6. Completion: Return final response to user

3. Tool Execution

When the model requests a tool:

Agent Configuration

Agents can be configured through multiple mechanisms:

Session Config

Recipe-Based Config

Recipes provide pre-configured agent behaviors:

Runtime Config

Subagents

Subagents are independent agent instances spawned to handle specific sub-tasks. This enables:
  • Parallel execution: Multiple tasks running simultaneously
  • Context isolation: Prevent context window overflow
  • Specialized behaviors: Different instructions per task
  • Composed workflows: Break complex tasks into manageable pieces

Creating Subagents

Subagents can be created in two ways:

1. Ad-hoc Subagents

Create on-the-fly with custom instructions:
The model uses the subagent tool:

2. Sub-recipes

Predefined subagent templates:

Subagent Architecture

Subagent Implementation

Parallel Subagent Execution

Multiple subagent calls in one model response run in parallel:

Subagent Best Practices

Subagents return concise summaries to the parent, preventing context overflow:
Give subagents only the tools they need:
Prevent parallel execution when tasks have side effects:
Use cheaper/faster models for simple subagent tasks:

Agent Modes

Goose supports different operational modes:

Chat Mode

  • Interactive back-and-forth conversation
  • User can interrupt and provide feedback
  • Agent asks for clarification when needed
  • Suitable for exploratory tasks

Execute Mode

  • Recipe-driven execution
  • Runs to completion with minimal interaction
  • Uses final_output tool to return structured results
  • Suitable for automated workflows

Turn Management

Agents limit conversation length to prevent runaway execution:
Turns can be configured via:
  • Recipe settings.max_turns
  • Session config
  • Subagent parameters

Context Management

Agents automatically compact conversation history when approaching token limits:

Error Handling and Retries

Agents include sophisticated retry logic for transient failures:
Retryable errors include:
  • Network timeouts
  • Rate limiting (429)
  • Server errors (5xx)
  • Transient provider errors

Security and Permissions

Agents enforce security policies before tool execution:
See Sessions for session isolation and Extensions for tool sandboxing.

Next Steps

Providers

Learn how agents interact with AI models

Extensions

Understand the tools agents can use

Recipes

Create pre-configured agent behaviors

Sessions

Manage agent state and history