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:- Build Context: Gather conversation history, system prompts, and available tools
- Model Invocation: Send to AI provider with streaming enabled
- Stream Processing: Handle chunks as they arrive (text or tool calls)
- Tool Execution: Execute any tools the model requests
- Continue Loop: Feed tool results back to model
- 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: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
Use summary mode by default
Use summary mode by default
Subagents return concise summaries to the parent, preventing context overflow:
Scope extensions appropriately
Scope extensions appropriately
Give subagents only the tools they need:
Use sequential_when_repeated for stateful tasks
Use sequential_when_repeated for stateful tasks
Prevent parallel execution when tasks have side effects:
Choose the right model per task
Choose the right model per task
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:- 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:- Network timeouts
- Rate limiting (429)
- Server errors (5xx)
- Transient provider errors
Security and Permissions
Agents enforce security policies before tool execution: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