Orchestrator and Workers¶
The worker system provides structured delegation for complex tasks. The Orchestrator coordinates multi-step conversation turns, while the Background Task Runner handles long-running web research independently of the main generation loop.
Orchestrator¶
Orchestrator (core/worker/orchestrator.py) is the primary conversational coordinator — a single orchestrator with helper worker delegation. It replaces the multi-agent loop (preserved as legacy_mode).
Flow per Conversation Turn¶
- Intent detection — The orchestrator analyzes incoming messages for patterns:
_PLANNER_KEYWORDS→ spawn PLANNER worker for complex task planning_SUMMARIZER_THRESHOLD(500 chars) → SUMMARIZER for long context compression-
memory_modeactive → RETRIEVER for vector memory lookup -
Helper worker spawn — Workers dispatched via
WorkerPool.delegate()with typed configurations -
Primary agent generation — Main agent generates response enriched with worker results
-
Return result —
OrchestratorResult(frozen dataclass) containing: response_text— final generated responseworker_results— outputs from each helper workercorrelation_id— unique trace identifierduration_ms— total turn durationprimary_agent_name— which agent handled the turnworker_count— number of helper workers spawnedfirst_token_ms— time to first generated token
Key Classes¶
Orchestrator—orchestrate()for full turn execution,delegate()for single-worker delegationOrchestratorResult— Frozen result with traces and timing dataOrchestratorProtocol— Defined inservice_protocols.pyfor dependency injection
Worker System¶
WorkerPool (core/worker/worker_system.py) manages non-speaking internal workers that communicate through typed events:
| Worker Type | Purpose |
|---|---|
PLANNER |
Breaks complex requests into step-by-step plans |
RETRIEVER |
Queries vector memory for relevant context |
SUMMARIZER |
Compresses long conversation history |
INDEXER |
Organizes and indexes knowledge bases |
TOOL_PREPARER |
Pre-validates tool availability |
REASONER |
Independent reasoning pass for complex logic |
The worker pool provides bounded concurrency, per-type limits, token budgets, timeouts, cancellation support, and trace event publishing.
Background Task Runner¶
BackgroundTaskRunner (core/worker/background_task_runner.py) executes long-running operations independently of the main generation loop. Primary use case: deep web research.
Web Research Protocol¶
The three-phase protocol replaces title-only results with full-page deep research:
- Search —
web_searchreturns DuckDuckGo titles and URLs only (no snippets or summaries) - Fetch —
fetch_urlextracts full page content viacurl_cffiwith Chrome TLS impersonation - Synthesize — Agent generates comprehensive response from full-page content
Quality Guards¶
Four guards prevent wasteful or redundant research:
| Guard | Purpose |
|---|---|
| Duplicate URL guard | Won't re-fetch the same URL within a task |
| Near-dup query detection | Avoids semantically similar search queries |
| Consecutive search guard | Enforces fetching content between searches |
| Multi-topic awareness | Tracks distinct topics for broad coverage |
Task Queue¶
TaskQueue (core/worker/task_queue.py) is a bounded async queue with:
- Priority ordering (semaphore + size limit)
- Retry with exponential back-off
- Per-task timeouts and cancellation
- Result futures for async completion
- EventBus integration for status updates
- Bounded history retention
Telemetry¶
| Metric | Description |
|---|---|
queue.depth |
Current queue depth (gauge) |
queue.task_ms |
Task execution duration |
Worker spawn/complete events publish via EventBus with correlation IDs for end-to-end tracing.
See Also¶
- Agent System — how agents delegate to background workers
- Security Pipeline — background tasks route through RealToolHost
- API Reference: Workers — class and function reference