Agent Optimizations
Four composable techniques that improve agent output quality, reduce hallucinations, and keep responses grounded — plus granular per-step reasoning control. All run through your existing router with no hardcoded models.
Overview
| Optimization | What it does | Overhead | Best for |
|---|---|---|---|
| Adaptive Clarification | Asks the user for missing info before running | ~13% | Ambiguous inputs |
| Context Distillation | Summarizes context between steps | ~18% | 3+ step pipelines |
| Constraint Verification | Extracts requirements, verifies each step | ~22% | Compliance, specs |
| Dual Persona | Skeptic critiques, author revises | ~28% | High-stakes content |
All optimizations default to off. Enable them in the dashboard under Workflow → Optimize Agent, or via the API in settings.optimizations.
Configuration
{
"settings": {
"optimizations": {
"adaptiveClarification": false,
"contextDistillation": false,
"constraintHashing": false,
"dualPersona": false,
"dualPersonaScope": "final" // "final" | "all"
}
}
}Adaptive Clarification Gate
Runs before the step pipeline. A single LLM call evaluates whether the user's input contains enough information to produce a quality response.
- User sends a message to the agent
- ACG asks: “Is this request sufficient?”
- If yes → agent runs normally
- If no → returns up to 3 clarifying questions and halts
The agent does not execute any steps until the user provides additional context. Questions are streamed as a clarification_request event.
// SDK: handle clarification responses
const response = await client.agents.run({
agentId: 'my-agent',
messages: [{ role: 'user', content: 'Write something' }],
});
// If ACG fires, response.choices[0].finish_reason === 'clarification_needed'
// response.choices[0].message.content contains the questions
// Re-call with the user's answers appended to messagesContext Distillation Layer
Runs after each step in a multi-step pipeline. Produces a structured JSON summary of facts, open questions, decisions, and constraints — then injects it as a system message into the next step.
This replaces raw {{previous_output}} bloat with a clean structured summary. Template variables still work as before — CDL augments, it doesn't replace.
System: Running context (distilled from prior steps):
{ "facts": [...], "openQuestions": [...], "decisions": [...], "constraints": [...] }
Constraint Verification
Phase 1 — Extraction (before steps execute): An LLM call extracts requirements from the user's input as a JSON array. A SHA-256 fingerprint is stored for drift detection.
Phase 2 — Per-step verification: Each LLM step's prompt is appended with instructions to include a ## Constraint Satisfaction section. After the LLM responds, a check confirms the section exists. If missing, the step is retried once with feedback.
Dual Persona
Runs after a step completes. A skeptic LLM call critiques the output, then a resolution call revises the answer.
- Step produces output
- Skeptic: “Find flaws and missing facts” → returns
{ flaws: [...], missingFacts: [...] } - Resolution: feeds original + critique back → revised answer
- Revised output replaces the original
Per-Step Reasoning
Instead of a global reasoning toggle, you can now enable chain-of-thought planning on individual steps. When enabled, the orchestrator runs a per-step planning call before executing the step.
Toggle it in the Step Editor modal, or set it via the API:
{
"steps": [
{
"name": "research",
"prompt": "Research {{input}} thoroughly",
"reasoning": { "enabled": true }
},
{
"name": "format",
"prompt": "Format the research as a report",
"reasoning": { "enabled": false }
}
]
}Migration from global reasoning
The global enableReasoning toggle in Agent Settings is deprecated. Existing agents with it enabled are automatically migrated — all steps receive reasoning: { enabled: true }. The Settings panel now directs you to the Workflow tab.
Execution Order
When multiple optimizations are enabled, they execute in this order:
1. ACG check → may halt with clarification questions
2. Constraint extraction → stores requirements on context
3. Initial planning (if planningMode = 'initial_plan')
4. For each step:
a. Per-step reasoning (if step.reasoning.enabled)
b. Execute step (with constraint prompt injection if active)
c. Record result
d. CDL distillation → updates structured context
e. Dual Persona skeptic + resolution → replaces output
f. Notify step complete
5. Return final outputInternal Step IDs
Optimization steps appear in stepResults with these IDs (marked isInternal: true). They are billed normally.
| ID pattern | Optimization |
|---|---|
acg_check | Adaptive Clarification Gate |
constraint_extraction | Constraint Verification (extraction) |
cdl_{stepId} | Context Distillation Layer |
skeptic_{stepId} | Dual Persona (critique) |
resolution_{stepId} | Dual Persona (resolution) |
Composability
All four optimizations compose freely. Turning on ACG + Constraint Verification + Dual Persona gives you: clarification upfront, requirement tracking through every step, and a skeptic/resolution pass on the final output. Token overhead is additive — monitor your cost in the execution metrics.