Policies let you inject logic at each step of agent execution. Add instructions, modify behavior, enforce constraints—all based on runtime context like step count, previous outputs, or external state.Documentation Index
Fetch the complete documentation index at: https://docs.dedaluslabs.ai/llms.txt
Use this file to discover all available pages before exploring further.
Basic Policy
A policy is a function that receives context and returns modifications:Policy Context
Thectx dict contains:
| Field | Type | Description |
|---|---|---|
step | int | Current execution step (1-indexed) |
messages | list | Conversation history so far |
tools_called | list | Tools invoked in previous steps |
Policy Returns
Policies can return:| Field | Effect |
|---|---|
message_prepend / messagePrepend | Messages added before the next model call |
message_append / messageAppend | Messages added after the conversation |
max_steps / maxSteps | Override the maximum step count |
stop | Boolean to halt execution early |
Use Cases
Rate limiting: Track API calls across steps, pause if limits approached. Guardrails: Check outputs for policy violations, inject correction prompts. Dynamic instructions: Change behavior based on intermediate results. Cost control: Stop execution after a certain number of expensive operations.Tool Event Callbacks
Monitor tool execution withon_tool_event:
Next steps
Tools
Define the tools policies can control
