Control
Policies
Policies are the rules that govern how the Niitaka policy engine intervenes in agent runs. They let you define cost and step budgets, automatic retry strategies, and model fallbacks — without touching your agent code.
Each policy is evaluated in real time on every incoming event. When a condition is met, the configured action executes and a signal is emitted to the feed.
Policy types
cost_limit
Tracks cumulative LLM spend for the session and fires when total_cost crosses the threshold. Two tiers are standard: a warn action at a lower threshold (emits a signal, continues running) and an abort action at a higher threshold (stops the session).
| Field | Type | Description |
|---|---|---|
| condition.cost_exceeded | float | USD threshold that triggers this rule. |
| action.type | string | "warn" — emit signal and continue. "abort" — stop the session. |
| priority | int | Higher priority wins when multiple rules match the same event. |
step_limit
Counts the number of steps (events) in the session and fires when the count reaches the threshold. Same two-tier warn/abort pattern as cost_limit.
| Field | Type | Description |
|---|---|---|
| condition.steps_exceeded | int | Step count threshold. |
| action.type | string | "warn" or "abort". |
| priority | int | Higher priority wins. |
retry
Automatically retries the last event when the agent reports an error. Supports exponential, linear, and constant back-off algorithms.
| Field | Type | Description |
|---|---|---|
| action.max_retries | int | Maximum number of retry attempts. |
| action.backoff | string | "exponential" | "linear" | "constant". |
| action.backoff_seconds | float | Base delay in seconds. Exponential: delay × 2^attempt. Linear: delay × attempt. Constant: fixed delay. |
| action.on_errors | list | Optional list of error type strings to match. Empty = match all errors. |
fallback
Switches to a different model when retries are exhausted or a specific error occurs. Useful for ensuring continuity when a primary provider is unavailable.
| Field | Type | Description |
|---|---|---|
| action.fallback_model | string | Model identifier to switch to (e.g. "gpt-4o-mini"). |
| action.on_errors | list | Optional error type filter. Empty = match all errors. |
UI policies vs file-based policies
Policies can be created in two ways:
niitaka.configure(policy_file=...). Shown as read-only in the UI — you can view and delete them but not edit inline. The source of truth is your version-controlled file.Policy YAML format
version: "1"
policies:
# Warn at $0.10, hard-abort at $0.25
- agent_id: report-summariser
type: cost_limit
priority: 5
condition:
cost_exceeded: 0.10
action:
type: warn
- agent_id: report-summariser
type: cost_limit
priority: 10
condition:
cost_exceeded: 0.25
action:
type: abort
# Warn at 30 steps, abort at 50
- agent_id: report-summariser
type: step_limit
priority: 5
condition:
steps_exceeded: 30
action:
type: warn
- agent_id: report-summariser
type: step_limit
priority: 10
condition:
steps_exceeded: 50
action:
type: abort
# Retry up to 3 times with exponential back-off
- agent_id: report-summariser
type: retry
priority: 3
condition:
on_error: true
action:
max_retries: 3
backoff: exponential
backoff_seconds: 2.0
# Fall back to a cheaper model after retries fail
- agent_id: report-summariser
type: fallback
priority: 1
condition:
on_error: true
action:
fallback_model: gpt-4o-mini# Push policy file to the backend (replaces any existing UI-defined policies)
python -m sdk.cli push agents/report-summariser/policies.yaml
# Or configure the SDK to load from file at runtime
niitaka.configure(policy_file="policies.yaml")Priority and conflict resolution
When multiple policies match the same event, the one with the highest priority value wins. Typical convention:
priority 10— hard abort (highest urgency)priority 5–8— warn-level guardrailspriority 1–4— soft actions (retry, fallback)
Audit log
Every policy change is recorded in the Audit Log tab on the Policies page. Each entry shows the action taken (create, delete, replace), the before and after state as expandable JSON, the source (UI or file), and the timestamp.
Next steps
- Policy Evaluation — understand how the engine evaluates policies on each event.
- Signals & Alerts — see the signals your policies emit and configure external notifications.