Repository navigation
Description
Overview
Today, agent-to-agent communication in Trinity is synchronous — the caller blocks until the target agent responds. The chat_with_agent MCP tool has an async: true flag that returns an execution_id, but there is no way to retrieve the result later. This means agents cannot submit work to each other and continue independently.
This spike proposes an Agent Task Backlog — a persistent, ordered queue of tasks per agent that any actor (human, agent, schedule) can submit to, with results retrievable by execution ID.
Problem
- Blocking calls limit throughput — Agent A calls Agent B and waits 2+ minutes for a response. A can't do anything else.
- No shared work queue — Humans can trigger tasks from the UI, but there's no concept of a persistent backlog that agents also submit to.
- No result retrieval — The
async: truemode returns an execution_id, but no MCP tool exists to fetch the result. The async path is a dead end. - No pipeline pattern — Without submit + retrieve, agents can't form asynchronous pipelines (A submits to B, B submits to C, A checks results later).
Current State
| Component | What Exists | Gap |
|---|---|---|
Execution Queue (services/execution_queue.py) |
Redis-backed, max 3 queued, 600s TTL | Ephemeral, not a deliberate backlog |
chat_with_agent MCP tool |
async: true returns execution_id |
No get_execution_result tool |
/api/agents/{name}/task |
Stateless parallel execution | No queue semantics, no persistence |
schedule_executions table |
Stores execution results with IDs, status, response, cost | Only for schedule-triggered executions |
| Process Engine | Multi-step YAML workflows | Heavyweight for ad-hoc task submission |
| Tasks UI panel | Manual task triggering | No backlog view, no queue status |
Proposed Design
New Concept: Agent Task Backlog
A persistent, per-agent queue where tasks are submitted and processed FIFO (with optional priority). Every actor uses the same queue.
Backend Changes
-
POST /api/agents/{name}/backlog— Submit a task, returnsexecution_idimmediately- Accepts:
message,priority(optional),metadata(optional) - Persists to database (not just Redis)
- Source tracking: who submitted (human user, agent, schedule)
- Accepts:
-
Backlog Worker — Background loop per agent
- Picks next pending task from backlog (FIFO or priority-ordered)
- Executes via existing
task_execution_service.execute_task() - One task at a time per agent
- Marks completion with result, cost, duration
-
GET /api/agents/{name}/backlog— List pending + recent completed tasks- Filterable by status:
pending,running,completed,failed - Pagination support
- Filterable by status:
-
GET /api/agents/{name}/executions/{id}— Generalize the existing schedule execution detail endpoint to serve any execution source
MCP Tools (Key Enabler)
submit_task— Add task to an agent's backlog, returns execution_id. Non-blocking. Respects agent permissions.get_execution_result— Fetch result by execution_id. Returns status + response if completed.list_backlog(optional) — View queued/completed tasks for an agent.
Frontend Changes
- Tasks panel becomes a backlog view showing queued → running → completed tasks
- Humans can add tasks that land in the same queue agents use
- Status indicators and result inspection on click
Async Pipeline Pattern This Enables
Agent A Agent B Agent C
| | |
|-- submit_task(B, "analyze X") →| |
|← execution_id: abc123 | |
| |-- (processes when ready) -- |
| ... does other work ... | |
| |-- submit_task(C, "summarize") →|
| |← execution_id: def456 |
|-- get_execution_result(abc123) | |
|← status: completed, result:...| |
Design Decisions to Resolve
| Decision | Options | Leaning |
|---|---|---|
| Persistence | Redis (ephemeral) vs SQLite (durable) | SQLite — backlog should survive restarts |
| Queue depth | Fixed cap vs configurable per-agent | Configurable, default 50 |
| Priority | FIFO only vs priority levels | Start FIFO, add priority later |
| Result retrieval | Polling only vs webhook/notification | Polling via MCP first, webhooks later |
| Task context | Stateless (like /task) vs conversational (like /chat) |
Stateless — work queue items are independent |
| Relationship to Process Engine | Replace vs complement | Complement — process steps can submit to backlogs |
Reuse schedule_executions |
Extend existing table vs new table | Extend with new triggered_by="backlog" source |
Acceptance Criteria
MVP (Phase 1)
-
POST /api/agents/{name}/backlogendpoint accepts tasks, returns execution_id - Background worker processes backlog tasks FIFO, one at a time
-
GET /api/agents/{name}/executions/{id}returns status + result for any execution - MCP tool
submit_tasksubmits to backlog with permission checks - MCP tool
get_execution_resultretrieves result by ID - Tasks UI shows backlog (pending/running/completed)
- Humans can add tasks to backlog from UI
Phase 2 (Follow-up)
- Priority levels for backlog tasks
- Configurable queue depth per agent
- WebSocket notifications when task completes
-
list_backlogMCP tool - Batch task submission
- Result expiry / cleanup policy
Related
- Execution Queue:
src/backend/services/execution_queue.py - Task Execution Service:
src/backend/services/task_execution_service.py - MCP Chat Tool:
src/mcp-server/src/tools/chat.ts - Execution Origin Tracking:
docs/feature-flows/AUDIT-001-execution-origin-tracking.md - Process Engine:
src/backend/services/process_engine/
Activity
m13v commentedon Mar 26, 2026
the blocking call problem is brutal in practice. we run a tmux-based agent orchestration system where a parent agent spawns 3-5 child agents in separate sessions, and the original version just waited for each one sequentially - turning a 2 minute parallel task into 10 minutes. the pattern that worked for us: parent agent fires off all sub-agents, then polls their output files on a short interval instead of blocking. results get written to a known path per execution ID. the key insight was separating "submit" from "retrieve" at the IPC level, not just adding async flags. your Redis queue approach is cleaner than our file-based version, but watch out for the result TTL - we had agents that submitted work, got compacted (context window full), resumed, and then couldn't find results because the 600s TTL had expired. bumped ours to 1 hour and the failure rate dropped to near zero.
m13v commentedon Mar 26, 2026
our tmux-based agent orchestration that handles the async submit/poll pattern for parallel agent sessions: https://github.com/m13v/tmux-background-agents/blob/main/SKILL.md
and the browser lock script that prevents resource contention when multiple agents share a browser instance: https://github.com/m13v/browser-lock/blob/main/playwright-lock.sh
vybe commentedon Mar 30, 2026
Actualization (2026-03-30)
Current state: Partially addressed by MCP-007 (MCP Execution Query Tools, req 7.3):
What exists:
list_recent_executions— query execution historyget_execution_result— poll async results by execution_idget_agent_activity_summary— monitor agent activitychat_with_agent(async=true)returnsexecution_idimmediatelyget_execution_resultto retrieve completed resultsWhat this issue proposes beyond MCP-007:
Recommendation: Update issue description to note that the basic async polling pattern is implemented via MCP-007. The remaining value is the persistent queue/backlog concept with ordering and dependencies. Keep open but clarify scope.
m13v commentedon Mar 30, 2026
nice actualization. the persistent task store with retry semantics is the big missing piece - without it you lose in-flight work on any restart. we solved this with a simple SQLite-backed queue where each task has a state machine (pending -> claimed -> running -> completed/failed). the key insight was separating the "submit" from the "claim" so multiple agents can compete for work without duplicating effort. for the callback/webhook pattern, we found polling with exponential backoff was more reliable in practice since webhook delivery is never guaranteed. curious if you're planning to build the persistent store on top of the existing MCP execution tracking or as a separate subsystem?
vybe commentedon Apr 4, 2026
Closing — superseded by #260 (feat: Persistent task backlog for async execution). The spike informed the full feature issue.
ci(a2a): fix gitleaks FP + the #1310 inline-auth guard for the A2A in…
ci(gitleaks): allowlist docs/user-docs as a documented curl-example zone
ci(a2a): fix gitleaks FP + the #1310 inline-auth guard for the A2A in…
ci(gitleaks): allowlist docs/user-docs as a documented curl-example zone
fix(a2a): re-chain the Alembic revision onto dev head 0028 after reba…
ci(a2a): fix gitleaks FP + the #1310 inline-auth guard for the A2A in…
1 remaining item
fix(a2a): re-chain the Alembic revision onto dev head 0028 after reba…
fix(a2a): re-chain the Alembic revision onto dev head 0030 after reba…
ci(a2a): fix gitleaks FP + the #1310 inline-auth guard for the A2A in…
ci(gitleaks): allowlist docs/user-docs as a documented curl-example zone
fix(a2a): re-chain the Alembic revision onto dev head 0028 after reba…
fix(a2a): re-chain the Alembic revision onto dev head 0030 after reba…
ci(a2a): fix gitleaks FP + the #1310 inline-auth guard for the A2A in…
ci(gitleaks): allowlist docs/user-docs as a documented curl-example zone
fix(a2a): re-chain the Alembic revision onto dev head 0028 after reba…
fix(a2a): re-chain the Alembic revision onto dev head 0030 after reba…
ci(a2a): fix gitleaks FP + the #1310 inline-auth guard for the A2A in…
ci(gitleaks): allowlist docs/user-docs as a documented curl-example zone
fix(a2a): re-chain the Alembic revision onto dev head 0028 after reba…
fix(a2a): re-chain the Alembic revision onto dev head 0030 after reba…
feat(a2a): A2A interoperability — inbound server (well-known + JSON-R…