Why System Prompts Matter
System prompts give the LLM real-time awareness of:- Agent state - Is it running, processing, or encountering errors?
- Available capabilities - What commands can be invoked right now?
- Current context - What conversation or task is active?
- Recent activity - What just happened?
Setting System Prompt
On Initialization
Set an initial prompt when your agent starts:Update Anytime
Update the prompt whenever significant state changes occur:When to Update
On Significant State Changes
After Commands Execute
On Lifecycle Events
You can update system prompts in response to agent lifecycle events. Learn more about available events in Lifecycle Events.Keep it Concise
The LLM processes your system prompt with every message. Keep it brief and focused.Structure Guidelines
Use Sections for Clarity
Key Information First
Dynamic State Updates
Track real-time state and update the prompt accordingly. For persisting state across agent restarts, see State Management.Capability Listing
Inform the LLM about what your agent can do:Context-Aware Prompts
Adapt prompts to different contexts:Error States
Clearly communicate errors to help the LLM provide appropriate responses:Complete Example
Agent that updates prompt throughout its lifecycle:Prompt Templates
Use a centralized builder for consistent prompts:Best Practices
Update on state changes, not constantly
Update on state changes, not constantly
Good: Update when something changesBad: Update every iteration
Use helper method for updates
Use helper method for updates
Good: Centralized logicBad: Duplicated logic
Summarize lists, don't enumerate
Summarize lists, don't enumerate
Good: SummaryBad: Full list
Show recent items only
Show recent items only
Good: Last 3 itemsBad: Full history
Common Mistakes
Too much detailDon’t include implementation details or verbose descriptions:
Static informationDon’t include information that never changes:
**Forgetting to strip()Always use
.strip() to remove leading/trailing whitespace:Quick Reference
System Prompt Purpose
- Inform LLM of current agent state
- List available capabilities
- Show context and recent activity
- Communicate errors or warnings
Update Triggers
- Significant state changes
- After command execution
- On lifecycle events (activated, deactivated)
- When capabilities change
Keep it Concise
- Summarize, don’t enumerate
- Show recent items only (last 3-5)
- Key information first
- Use sections for organization
Best Practices
- Centralize prompt building logic
- Update on changes, not constantly
- Use helper methods
- Group related information
- Always use
.strip()