Smart Context Management
When working with Large Language Models (LLMs), there are limits to how much conversation history they can process at once. Goose provides smart context management features to help you maintain productive sessions even when reaching these limits. Here are the key concepts:
- Context Length: The amount of conversation history the LLM can consider
- Context Limit: The maximum number of tokens the model can process
- Context Management: How Goose handles conversations approaching these limits
Smart Context Management Features
When a conversation reaches the context limit, Goose offers different ways to handle it:
Feature | Description | Best For | Impact |
---|---|---|---|
Summarization | Condenses conversation while preserving key points | Long, complex conversations | Maintains most context |
Truncation | Removes oldest messages to make room | Simple, linear conversations | Loses old context |
Clear | Starts fresh while keeping session active | New direction in conversation | Loses all context |
Using Smart Context Management
- Goose Desktop
- Goose CLI
Goose Desktop exclusively uses summarization to manage context, preserving key information while reducing size.
- Automatic
- Manual
When you reach the context limit in Goose Desktop:
- Goose will automatically start summarizing the conversation to make room.
- You'll see a message that says "Preparing summary...", followed by "Session summarized."
- Once complete, you'll have the option to "View or edit summary."
- You can then continue the session with the summarized context in place.
You can proactively summarize your conversation before reaching context limits:
- Click the scroll text icon () in the chat interface
- Confirm the summarization in the modal
- View or edit the generated summary if needed
The CLI offers three context management options: summarize, truncate, or clear your session.
Default Context Strategy
You can configure Goose to automatically handle context limits without prompting by setting the GOOSE_CONTEXT_STRATEGY
environment variable:
# Set default strategy (choose one)
export GOOSE_CONTEXT_STRATEGY=summarize # Automatically summarize (recommended)
export GOOSE_CONTEXT_STRATEGY=truncate # Automatically remove oldest messages
export GOOSE_CONTEXT_STRATEGY=clear # Automatically clear session
export GOOSE_CONTEXT_STRATEGY=prompt # Always prompt user (default)
Default behavior:
- Interactive mode: Prompts user to choose (equivalent to
prompt
) - Headless mode (
goose run
): Automatically summarizes (equivalent tosummarize
)
- Automatic
- Manual
When you hit the context limit, the behavior depends on your configuration:
With default settings (no GOOSE_CONTEXT_STRATEGY
set), you'll see this prompt to choose a management option:
◇ The model's context length is maxed out. You will need to reduce the # msgs. Do you want to?
│ ○ Clear Session
│ ○ Truncate Message
│ ● Summarize Session
final_summary: [A summary of your conversation will appear here]
Context maxed out
--------------------------------------------------
Goose summarized messages for you.
With GOOSE_CONTEXT_STRATEGY
configured, Goose will automatically apply your chosen strategy:
# Example with GOOSE_CONTEXT_STRATEGY=summarize
Context maxed out - automatically summarized messages.
--------------------------------------------------
Goose automatically summarized messages for you.
# Example with GOOSE_CONTEXT_STRATEGY=truncate
Context maxed out - automatically truncated messages.
--------------------------------------------------
Goose tried its best to truncate messages for you.
# Example with GOOSE_CONTEXT_STRATEGY=clear
Context maxed out - automatically cleared session.
--------------------------------------------------
To proactively trigger summarization before reaching context limits, use the /summarize
command:
( O)> /summarize
◇ Are you sure you want to summarize this conversation? This will condense the message history.
│ Yes
│
Summarizing conversation...
Conversation has been summarized.
Key information has been preserved while reducing context length.
Token usage
After sending your first message, Goose Desktop and Goose CLI display token usage.
- Goose Desktop
- Goose CLI
The Desktop displays a colored circle next to the model name at the bottom of the session window. The color provides a visual indicator of your token usage for the session.
- Green: Normal usage - Plenty of context space available
- Orange: Warning state - Approaching limit (80% of capacity)
- Red: Error state - Context limit reached
Hover over this circle to display:
- The number of tokens used
- The percentage of available tokens used
- The total available tokens
- A progress bar showing your current token usage
The CLI displays a context label above each command prompt, showing:
- A visual indicator using dots (●○) and colors to represent your token usage:
- Green: Below 50% usage
- Yellow: Between 50-85% usage
- Red: Above 85% usage
- Usage percentage
- Current token count and context limit