> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixus.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Management & Verification

> How to pass context between agents and set up multi-stage verification workflows

## Understanding Context Flow

Context in micro-agent chains refers to the data and insights passed between agents. Unlike traditional programming where you explicitly define data structures, agent context is managed through natural language instructions and structured outputs.

## How Context Pass-Through Works

### 1. Initial Context Creation

When Agent A completes its work, it generates output that becomes context for Agent B:

```typescript theme={null}
// Agent A's final output
{
  "summary": "Found 47 customer complaints about shipping delays",
  "categories": {
    "international": 23,
    "domestic": 24
  },
  "urgentCases": ["TICKET-1234", "TICKET-5678"],
  "recommendations": "Prioritize international shipping partner review"
}
```

### 2. Context Transmission Methods

**Method A: Direct Instruction Passing**

```javascript theme={null}
// In Agent A's last step
"Run the 'complaint-resolver' agent with instructions: 'Focus on the 23 international shipping complaints identified, starting with urgent cases TICKET-1234 and TICKET-5678'"
```

**Method B: Full Context Inclusion**

```javascript theme={null}
// Using addContext parameter
findAndRunAgent({
  agentName: 'complaint-resolver',
  instructions: 'Process the shipping complaints analysis',
  addContext: true // Includes last 5 assistant messages
})
```

**Method C: Structured Data Passing**

```javascript theme={null}
// Agent generates structured output
"Run 'report-generator' agent with this data:
{
  metrics: {total: 47, international: 23, domestic: 24},
  priority: ['TICKET-1234', 'TICKET-5678'],
  action: 'partner-review'
}"
```

## Context Scoping Strategies

### Minimal Context (Recommended)

Pass only essential data to reduce token usage:

```
Agent 1 → Agent 2: "Process these 3 high-priority tickets: [IDs]"
Agent 2 → Agent 3: "Generate report for resolved tickets: [resolution summary]"
```

### Rich Context

Include detailed information when downstream agents need full picture:

```
Agent 1 → Agent 2: "Analyze this complete customer profile: [full data dump]"
Agent 2 → Agent 3: "Create personalized campaign using all insights: [complete analysis]"
```

### Progressive Enhancement

Each agent adds to the context:

```
Agent 1: {baseData: "customer list"}
Agent 2: {baseData: "...", enrichment: "company info"}
Agent 3: {baseData: "...", enrichment: "...", scoring: "lead scores"}
```

## Verification Per Stage Explained

Verification allows human oversight at critical decision points without interrupting the entire flow.

### How Verification Works Technically

1. **Setting Verification Requirements**

   ```typescript theme={null}
   {
     name: "contract-processor",
     steps: [
       {
         description: "Extract key terms from uploaded contract",
         requiresVerification: false  // Automated
       },
       {
         description: "Identify potential risks and red flags",
         requiresVerification: true   // Human review required
       },
       {
         description: "Run 'legal-advisor' agent if risks found",
         requiresVerification: false  // Automated after approval
       }
     ]
   }
   ```

2. **Runtime Behavior**

   * Agent executes Step 1 automatically
   * At Step 2, execution pauses
   * System notifies designated reviewer
   * Reviewer sees output and can:
     * Approve to continue
     * Reject and stop
     * Modify and continue
   * Step 3 executes only after approval

3. **Verification UI Flow**
   ```text theme={null}
   ┌─────────────────────────────────────┐
   │ ⚠️  Verification Required           │
   │                                     │
   │ Agent: contract-processor           │
   │ Step 2: Identify risks              │
   │                                     │
   │ Output:                             │
   │ • Unlimited liability clause (§4.2) │
   │ • No termination clause             │
   │ • Automatic renewal without notice  │
   │                                     │
   │ [Approve] [Reject] [Modify Output]  │
   └─────────────────────────────────────┘
   ```

## Multi-Stage Verification Patterns

### Pattern 1: Department-Based Verification

```yaml theme={null}
Sales-Qualifier Agent:
  Step 1: Score lead based on criteria
  Step 2: Recommend discount level (requires: sales-manager)
  Step 3: Run 'contract-drafter' agent

Contract-Drafter Agent:
  Step 1: Generate contract with approved discount
  Step 2: Add special terms (requires: legal-team)
  Step 3: Run 'onboarding-agent'

Onboarding Agent:
  Step 1: Create customer account
  Step 2: Assign implementation team (requires: ops-manager)
  Step 3: Send welcome package
```

### Pattern 2: Risk-Based Verification

```typescript theme={null}
// Only require verification for high-value transactions
{
  description: "Process payment and update records",
  requiresVerification: "{{amount > 10000}}"  // Conditional verification
}
```

### Pattern 3: Parallel Verification

```
                  ┌→ Technical Review (CTO)
Proposal Agent ───┤
                  └→ Budget Review (CFO)
                           ↓
                    Both must approve
                           ↓
                    Execution continues
```

## Context Preservation Strategies

### 1. Chat History Integration

Each agent's chat preserves full execution context:

```javascript theme={null}
// In evaluation agent
searchChatHistory({
  query: 'contract-processor risks identified',
  sort: 'recent'
})
// Returns all risk assessments from recent runs
```

### 2. Explicit State Management

Agents can write to shared knowledge base:

```
Step 1: "Save analysis results to knowledge base with tag #q4-sales"
Step 2: "Run 'quarterly-reporter' agent"

// Quarterly reporter can then:
Step 1: "Retrieve all analyses tagged #q4-sales from knowledge base"
```

### 3. Execution Metadata

System automatically tracks:

* Parent agent that triggered execution
* Timestamp and duration
* User who approved verifications
* Complete input/output for each step

## Advanced Context Patterns

### Context Transformation

```javascript theme={null}
// Agent 1 outputs unstructured text
'I found several issues with the codebase...'

// Agent 2 transforms to structured data
{
  issues: [
    { type: 'security', severity: 'high', file: 'auth.js' },
    { type: 'performance', severity: 'medium', file: 'api.js' }
  ]
}

// Agent 3 consumes structured data efficiently
;('Generate JIRA tickets for 2 issues: ...')
```

### Context Filtering

```javascript theme={null}
// Agent 1 produces verbose output
// Agent 2's first step: "Summarize key findings from previous agent"
// Reduces 5000 tokens to 500 tokens before processing
```

### Context Enrichment

```javascript theme={null}
// Each agent adds its specialty
Agent 1: {customerId: "123"}
Agent 2: {customerId: "123", creditScore: 750}
Agent 3: {customerId: "123", creditScore: 750, riskProfile: "low"}
```

## Best Practices

1. **Context Size Management**

   * Keep passed context under 1000 tokens when possible
   * Use summaries instead of full documents
   * Reference IDs rather than full records

2. **Verification Placement**

   * Add verification before irreversible actions
   * Group related decisions in one verification step
   * Avoid verification on data gathering steps

3. **Context Security**

   * Never pass passwords or API keys in context
   * Sanitize PII when not needed downstream
   * Use references to sensitive data instead of values

4. **Error Context**
   * Include error handling instructions in context
   * Pass failure reasons to recovery agents
   * Maintain audit trail of verification decisions

## Example: Complete Order Processing Chain

```yaml theme={null}
Order-Validator:
  Step 1: Validate order details and inventory
  Step 2: Calculate pricing and discounts
  Step 3: Run 'payment-processor' with order total and customer ID

Payment-Processor:
  Step 1: Charge customer payment method
  Step 2: Verify payment success (requires: finance-team if >$5000)
  Step 3: Run 'fulfillment-agent' with order ID and payment confirmation

Fulfillment-Agent:
  Step 1: Reserve inventory items
  Step 2: Generate shipping label
  Step 3: Run 'notification-agent' with tracking number

Notification-Agent:
  Step 1: Send order confirmation to customer
  Step 2: Update CRM with order status
  Step 3: Schedule follow-up check-in for 7 days
```

Each agent receives only the context it needs, and verification happens only for high-value payments.

## Related Documentation

* [Micro-Agent Concepts](micro-agent-concepts) - Core architecture and chaining patterns
* [KPI Monitoring](micro-agent-kpi-monitoring) - Performance tracking with search-chat-history
* [Multi-User Verification](micro-agent-multi-user-verification) - Distributed approval workflows
* [Advanced Use Cases](micro-agent-use-cases-tips) - Creative applications and optimization tips

***

*Need help setting up verification workflows? Check our [agent creation guide](/agents/creating) or contact [support](/support/contact).*
