Beginner7 min
System Prompt
Shape how your agent approaches tasks with a system prompt. Static strings for fixed personas, SystemMessage for provider features like prompt caching, and @dynamic_prompt for runtime-generated prompts.
Quick Reference
- →system_prompt='...' sets a static instruction for every invocation
- →Pass SystemMessage instead of str for provider-specific features (e.g. Anthropic cache_control)
- →@dynamic_prompt middleware generates the prompt at runtime from state or context
- →No system_prompt = agent infers task from messages only
- →Dynamic prompts via context_schema: pass user_role or other metadata at invoke time
Static System Prompt
The simplest form: pass a string to system_prompt and it becomes the first message in every conversation. Use it to set the agent's persona, define its scope, and establish behavioral constraints.
String system prompt