Skip to main content
Agentsv1.1.0

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

OptimizationWhat it doesOverheadBest for
Adaptive ClarificationAsks the user for missing info before running~13%Ambiguous inputs
Context DistillationSummarizes context between steps~18%3+ step pipelines
Constraint VerificationExtracts requirements, verifies each step~22%Compliance, specs
Dual PersonaSkeptic 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

json
{
  "settings": {
    "optimizations": {
      "adaptiveClarification": false,
      "contextDistillation": false,
      "constraintHashing": false,
      "dualPersona": false,
      "dualPersonaScope": "final"   // "final" | "all"
    }
  }
}

Adaptive Clarification Gate

Pre-execution check

Runs before the step pipeline. A single LLM call evaluates whether the user's input contains enough information to produce a quality response.

  1. User sends a message to the agent
  2. ACG asks: “Is this request sufficient?”
  3. If yes → agent runs normally
  4. 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.

javascript
// 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 messages

Context Distillation Layer

Between-step summarization

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

Two-phase requirement tracking

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

Disagreement injection

Runs after a step completes. A skeptic LLM call critiques the output, then a resolution call revises the answer.

  1. Step produces output
  2. Skeptic: “Find flaws and missing facts” → returns { flaws: [...], missingFacts: [...] }
  3. Resolution: feeds original + critique back → revised answer
  4. Revised output replaces the original
scope: "final"Only runs on the last step (default)
scope: "all"Runs on every LLM step

Per-Step Reasoning

Granular chain-of-thought control

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:

json
{
  "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:

text
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 output

Internal Step IDs

Optimization steps appear in stepResults with these IDs (marked isInternal: true). They are billed normally.

ID patternOptimization
acg_checkAdaptive Clarification Gate
constraint_extractionConstraint 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.