Skip to content

feat: Fan-out primitive for parallel self-invocation #230

Closed

Description

@vybe

Summary

Agents need a way to fan out N independent tasks to themselves (or other agents) in parallel and collect results. Today chat_with_agent(self, parallel=true, async=true) works for individual calls, but there's no batch-and-collect orchestration — the caller must dispatch N calls and poll N execution IDs manually with no unified timeout, failure handling, or result aggregation.

Motivation

An agent doing batch work (predictions, analysis, content generation) is stuck in one monolithic session. Each subtask shares a degrading context window. A fan-out primitive lets each subtask get a fresh context and run concurrently, with results collected back to the parent for aggregation. This is map-reduce for agents.

Use cases:

  • Oracle generating N predictions in parallel instead of serially
  • Batch analysis across multiple topics/datasets
  • Ensemble methods, counterfactuals, A/B comparisons
  • Any agent workload that's embarrassingly parallel

Proposed Design

New backend endpoint: POST /api/agents/{name}/fan-out

New MCP tool: fan_out

Request

{
  "tasks": [
    { "id": "task_a", "message": "Predict topic A with context" },
    { "id": "task_b", "message": "Predict topic B without context" }
  ],
  "agent": "self",
  "timeout_seconds": 300,
  "policy": "best-effort"
}

Semantics (opinionated defaults, loosen later)

Concern Default
Timeout Per-task, inherited from agent config (overridable)
Deadline Overall fan-out deadline = max(task timeouts) + buffer
Retries None. Failed tasks return error status, not retried
Partial results Always collected. Caller gets results for whatever completed
Failure mode Best-effort: return all results with per-task status

Response

{
  "fan_out_id": "fo_abc123",
  "status": "completed",
  "completed": 8,
  "failed": 2,
  "results": [
    { "id": "task_a", "status": "completed", "response": "..." },
    { "id": "task_b", "status": "failed", "error": "timeout" }
  ]
}

Implementation Notes

  • Reuses existing parallel task execution infrastructure (slot service, execution engine)
  • Backend owns the coordination: dispatch N executions, barrier-wait, collect results
  • Single response back to MCP — caller doesn't poll individual executions
  • Slot service enforces concurrency limits; excess tasks queue behind available slots
  • agent: "self" is the primary use case but the same primitive works for any target agent

What This Deliberately Does NOT Include (Yet)

  • Retry policies (add later if needed)
  • DAG/dependency ordering between tasks
  • Streaming/incremental results
  • All-or-nothing transaction semantics
  • Cross-agent scatter-gather (works mechanically but not a design goal for v1)

Acceptance Criteria

  • POST /api/agents/{name}/fan-out endpoint accepts task array, dispatches parallel executions, waits, returns collected results
  • fan_out MCP tool exposes the endpoint to agents
  • Per-task timeout enforced; overall deadline prevents indefinite waits
  • Failed/timed-out tasks return error status without blocking successful tasks
  • Slot service concurrency limits respected (tasks queue if slots full)
  • Self-targeting (agent: "self") works correctly
  • Integration test: fan out 5 tasks, verify all results collected

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-p2type-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions