Prompt Management#
System Prompts#
Agents can be initialized with a static system prompt. You can provide a single string or a list of strings:
Dynamic Prompts#
On conversation startup#
System prompts can be generated dynamically when a conversation starts. This is useful when the prompt depends on external state or initial context. You can achieve this by using the @my_agent.prompt decorator or passing a synchronous or asynchronous function.
Dynamic prompt functions support the same powerful execution context capabilities as Agent Tools. For more detailed information on specific context features, see Dependency Injection, Context Variables, and Human-in-the-loop.
Dynamic prompts are evaluated only once at the beginning of the conversation, and their results are appended to the static prompts and reused for subsequent turns.
Alternatively, you can pass a callable directly to the prompt parameter, or mix static strings and callables in a list:
On each conversation turn#
While dynamic prompt hooks are evaluated once per conversation, you might need to update the prompt dynamically on each turn. You can do this by mutating the prompt list within the Context directly between calls to reply.ask().
You can also completely override the agent's default prompt for a specific run or turn by passing the prompt parameter directly to ask():
Plugins for one invocation#
Plugins normally attach when an agent is built. Pass plugins= to Agent.ask(), Agent.run(), Agent.resume(), or a reply's ask() / run() to add capabilities for one call instead. For example, build a fresh SkillPlugin to refresh a long-lived agent's catalog and tool schemas:
Invocation plugins contribute prompts, tools, middleware, observers, policies, context defaults, and HITL. Their rules are:
- Prompt fragments append to the resolved prompt; plugin dynamic hooks run once per call. Explicit
prompt=still replaces the agent's base and dynamic prompts. - Existing context values beat plugin defaults. Later plugins override earlier defaults and same-named tools; explicit
tools=override plugin tools. - Policies follow agent policies in one assembler. HITL uses the explicit call hook, then the agent hook, then the first plugin hook.
- Scope exit removes the plugin's bound prompt fragments and unreplaced defaults, including failure or cancellation. Prompt updates and reassigned defaults persist. Pass the plugin again for a continuation; constructor plugins remain attached to the agent. Arbitrary side effects of plugin code are not rolled back.
The agent is unchanged, so separate streams can use different plugins concurrently. Reusing a SkillPlugin preserves its snapshot.
Invocation plugins add to constructor plugins
They do not replace them. A SkillPlugin attached to the agent and another passed to plugins= render two catalogs in the prompt, so attach a refreshed skill catalog in only one place.
Note
Cleanup of a default compares by identity: if code later assigns the identical object to the same key, the value is treated as the plugin's own and removed.
Prompt updates#
For continuous and event-driven prompt updates, you can mutate context.prompt dynamically from an event subscriber. This allows you to respond to specific events in the stream and adjust the agent's behavior on the fly during an ongoing conversation. See the Stream documentation for more details on this advanced feature.