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

# Concurrent Task Agent

> Coordinate multiple parallel task threads with timing constraints and interference avoidance

The hardest level in the Stratus benchmark was **Chaos Protocol** — three independent tasks running simultaneously, each with its own timing window:

1. Type a 5-digit cipher and submit
2. Click a SUPPRESS button at exactly T=15s, T=35s, and T=60s (6-second window each)
3. Toggle grid cells to match a target pattern

The Stratus agent completed all three. The baseline didn't finish level 7 of 10.

The key capability: **tracking multiple state threads independently** without losing context between them. This maps directly to real-world multi-agent coordination, parallel data processing, and concurrent workflow management.

<CardGroup cols={3}>
  <Card title="Independent State Threads" icon="layer-group" color="#34d399">
    Each task maintains its own state embedding. Stratus tracks them in parallel without cross-contamination.
  </Card>

  <Card title="Timing Constraints" icon="stopwatch" color="#fbbf24">
    Models temporal windows across concurrent tasks — knows when a time-sensitive action must preempt a longer-running one.
  </Card>

  <Card title="Interference Avoidance" icon="shield-check" color="#22d3ee">
    Detects when two concurrent operations would collide in shared state and schedules around it automatically.
  </Card>
</CardGroup>

## What We're Building

A research agent that runs three parallel tasks:

1. **Search task** — query 3 data sources simultaneously
2. **Monitor task** — watch for real-time updates and capture them on a schedule
3. **Synthesis task** — build a structured report as results arrive

Each task has independent state, but the synthesis task depends on output from both others. Stratus coordinates this without explicit orchestration logic.

## The Agent

<CodeGroup>
  ```typescript TypeScript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://api.stratus.run/v1',
    apiKey: process.env.STRATUS_API_KEY
  });

  interface TaskState {
    id: string;
    description: string;
    status: 'pending' | 'running' | 'blocked' | 'complete';
    results?: string;
    deadline?: string;
  }

  async function coordinateTasks(tasks: TaskState[], overallGoal: string) {
    const taskSummary = tasks
      .map(t => `${t.id} [${t.status}]: ${t.description}${t.results ? ` | Results so far: ${t.results}` : ''}${t.deadline ? ` | Deadline: ${t.deadline}` : ''}`)
      .join('\n');

    const response = await client.chat.completions.create({
      model: 'stratus-x1ac-base-gpt-4o',
      messages: [
        {
          role: 'system',
          content: `
            Concurrent task coordinator.
            Active tasks:
            ${taskSummary}

            Rules:
            - search-task and monitor-task run independently
            - synthesis-task can only proceed when both others have results
            - monitor-task must capture updates at T+10s, T+30s, T+60s windows
          `.trim()
        },
        { role: 'user', content: overallGoal }
      ]
    });

    return {
      nextActions: response.choices[0].message.content,
      sequence: response.stratus.action_sequence,
      confidence: response.stratus.overall_confidence
    };
  }

  async function runResearchAgent() {
    // Phase 1: Launch parallel tasks
    const phase1 = await coordinateTasks(
      [
        {
          id: 'search-task',
          status: 'pending',
          description: 'Query GitHub, HackerNews, and arXiv for "AI agents 2025"',
          deadline: 'No deadline'
        },
        {
          id: 'monitor-task',
          status: 'pending',
          description: 'Monitor Twitter/X for real-time mentions — capture at T+10s, T+30s, T+60s',
          deadline: 'Must start immediately — first window at T+10s'
        },
        {
          id: 'synthesis-task',
          status: 'blocked',
          description: 'Build structured report from search and monitor results',
          deadline: 'Can start once both other tasks have first results'
        }
      ],
      'Start all tasks. Prioritize monitor-task to hit the first timing window.'
    );

    console.log('Phase 1 plan:', phase1.nextActions);
    console.log('Sequence:', phase1.sequence.join(' → '));

    // Phase 2: Search task has results, monitor task hit T+10s
    const phase2 = await coordinateTasks(
      [
        {
          id: 'search-task',
          status: 'complete',
          description: 'Query GitHub, HackerNews, arXiv for "AI agents 2025"',
          results: '47 GitHub repos, 12 HN posts, 8 papers'
        },
        {
          id: 'monitor-task',
          status: 'running',
          description: 'Monitor Twitter/X for real-time mentions',
          results: '23 mentions captured at T+10s',
          deadline: 'Next window at T+30s — 18 seconds remaining'
        },
        {
          id: 'synthesis-task',
          status: 'pending',
          description: 'Build structured report from search and monitor results',
        }
      ],
      'Begin synthesis with available data. Monitor-task is still running — leave it space to hit T+30s window.'
    );

    console.log('\nPhase 2 plan:', phase2.nextActions);
    console.log('Confidence:', phase2.overall_confidence);
  }

  runResearchAgent();
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.stratus.run/v1",
      api_key=os.environ["STRATUS_API_KEY"]
  )

  def coordinate_tasks(tasks, goal):
      task_summary = "\n".join([
          f"{t['id']} [{t['status']}]: {t['description']}"
          + (f" | Results: {t['results']}" if t.get('results') else "")
          + (f" | Deadline: {t['deadline']}" if t.get('deadline') else "")
          for t in tasks
      ])

      response = client.chat.completions.create(
          model="stratus-x1ac-base-gpt-4o",
          messages=[
              {
                  "role": "system",
                  "content": f"""
                  Concurrent task coordinator.
                  Active tasks:
                  {task_summary}
                  Rules:
                  - search-task and monitor-task run independently
                  - synthesis-task requires results from both others
                  - monitor-task has strict timing windows
                  """.strip()
              },
              {"role": "user", "content": goal}
          ]
      )
      meta = response.stratus
      return {
          "plan": response.choices[0].message.content,
          "sequence": meta.action_sequence,
          "confidence": meta.overall_confidence
      }

  # Phase 1: launch all tasks
  result = coordinate_tasks(
      tasks=[
          {
              "id": "search-task",
              "status": "pending",
              "description": "Query GitHub, HackerNews, arXiv for 'AI agents 2025'",
          },
          {
              "id": "monitor-task",
              "status": "pending",
              "description": "Monitor Twitter/X for real-time mentions",
              "deadline": "First window at T+10s"
          },
          {
              "id": "synthesis-task",
              "status": "blocked",
              "description": "Build report from search + monitor results"
          }
      ],
      goal="Start all tasks. Prioritize monitor-task to hit the first timing window."
  )
  print(f"Plan: {result['plan']}")
  print(f"Sequence: {' → '.join(result['sequence'])}")
  print(f"Confidence: {result['confidence']}")
  ```
</CodeGroup>

## Tracking Independent State Threads

The secret to reliable concurrent coordination is **describing each task's state independently** in the system message. Stratus builds a separate embedding context for each thread.

```typescript theme={null}
// ❌ Mixing task state into one blob
const badState = "Doing search, monitoring Twitter, building report, next window in 18s";

// ✅ Clear per-task state
const goodState = `
  SEARCH-TASK [complete]: 47 GitHub repos, 12 HN posts, 8 arXiv papers retrieved.
  MONITOR-TASK [running]: 23 mentions at T+10s. Next window in 18s (T+30s).
  SYNTHESIS-TASK [unblocked]: Can begin. Has search results. Monitor results partial.
  DEPENDENCY: Synthesis must not block monitor's T+30s capture window.
`;
```

## Handling Priority Preemption

When a time-sensitive task needs to interrupt a lower-priority one:

```typescript theme={null}
const response = await client.chat.completions.create({
  model: 'stratus-x1ac-base-gpt-4o',
  messages: [
    {
      role: 'system',
      content: `
        Task coordinator. Two concurrent tasks.
        BACKGROUND-TASK [running]: Processing 500 records, 40% complete, non-urgent.
        URGENT-TASK [triggered]: Alert received — must acknowledge within 30 seconds.
        CONSTRAINT: Only one task can hold the write lock at a time.
        Current lock holder: BACKGROUND-TASK.
      `
    },
    {
      role: 'user',
      content: 'Handle the urgent alert without corrupting the background task state'
    }
  ]
});

// Stratus predicts: pause-background → checkpoint-state → acquire-lock → handle-alert → release-lock → resume-background
console.log('Preemption plan:', response.stratus.action_sequence);
```

## Interference Matrix

For complex multi-agent scenarios, make the interference rules explicit:

```typescript theme={null}
const interferenceMatrix = `
  Shared resources:
  - write-lock: only one holder at a time
  - api-rate-limit: max 10 req/s across all tasks
  - memory-budget: 2GB total across all tasks

  Current allocations:
  - task-a: holds write-lock, using 800MB, 4 req/s
  - task-b: queued for write-lock, using 600MB, 3 req/s
  - task-c: no lock needed, using 400MB, 2 req/s
`;
```

## Real-World Applications

<CardGroup cols={2}>
  <Card title="Parallel Data Pipelines" icon="database" color="#22d3ee">
    Multiple ETL jobs sharing write targets — schedule around lock contention automatically.
  </Card>

  <Card title="Multi-Agent Research" icon="magnifying-glass" color="#c084fc">
    Agents querying different sources simultaneously, synthesizing as partial results arrive.
  </Card>

  <Card title="Webhook Orchestration" icon="bolt" color="#fbbf24">
    Multiple async event handlers that must not double-process or race on shared state.
  </Card>

  <Card title="Test Suite Coordination" icon="flask" color="#34d399">
    Parallel test runners with shared fixtures — isolate state, manage teardown ordering.
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={3}>
  <Card title="Temporal Sequencing" icon="clock" color="#fbbf24" href="/docs/tutorials/temporal-sequencing">
    When task order matters — avoiding conflicts in sequential workflows.
  </Card>

  <Card title="Cascade Prediction" icon="diagram-project" color="#c084fc" href="/docs/tutorials/cascade-prediction">
    Actions that trigger downstream waves of effects.
  </Card>

  <Card title="Rollout API" icon="crystal-ball" color="#22d3ee" href="/docs/api-reference/rollout">
    Simulate multi-task plans before any task fires.
  </Card>
</CardGroup>
