Repository navigation
Description
Problem
Agents running data pipelines (e.g., prediction systems, ETL, monitoring) need to react to events from other agents. Today the only option is polling via cron schedules or wiring everything through chat_with_agent (which spins up a full LLM conversation just to pass structured data — expensive and slow).
Example: Agent A resolves a prediction → Agent B should extract assumptions → Agent C should check for surprises. Currently this requires manual cron scheduling or chaining chat_with_agent calls.
Proposal
A lightweight event pub/sub system where:
- Agents emit named events via a new MCP tool (
emit_event) - Agents subscribe to events from other agents (respecting existing
agent_permissions) - Subscriptions trigger agent tasks when matching events fire
Emit (MCP Tool)
emit_event(
event_type: "prediction.resolved", // namespaced string
payload: { pred_id: "123", outcome: "win", domain: "energy" } // structured data
)
Subscribe (API)
POST /api/agents/{name}/event-subscriptions
{
"source_agent": "cleon",
"event_type": "prediction.resolved",
"target_message": "Process resolved prediction {{payload.pred_id}} with outcome {{payload.outcome}}",
"enabled": true
}
When the event fires, Trinity sends the templated message to the subscribing agent via the existing /task endpoint (parallel, async).
Permission Model
Uses existing agent_permissions table — agent B can only subscribe to events from agent A if B has permission to call A (or vice versa — TBD which direction makes sense).
What This Enables
- Data pipelines: resolve → extract → deduplicate → update metrics (each step triggers the next)
- Cross-agent learning: agent A discovers something → notifies agent B to update its knowledge
- Monitoring: agent health events trigger remediation agents
- Loose coupling: agents don't need to know who's listening, just emit events
Implementation Notes
- Could build on top of the existing notifications infrastructure (notifications already have types, categories, metadata, persistence, WebSocket broadcast) — add a subscription/trigger layer
- Could also be a new lightweight table + simple matching logic
- Does NOT need the process engine — this is agent-to-agent, not workflow orchestration
- The existing event bus (process engine
InMemoryEventBus) is a separate concern for workflow step events; this is for agent-emitted domain events - Should be simple enough that an agent can emit and subscribe with one MCP tool call each
Relationship to #22
Issue #22 describes a full Redis Streams event bus. This issue is a pragmatic first step — SQLite-backed, no new infrastructure, focused specifically on agent-to-agent event triggers. If #22 lands later, subscriptions created here could migrate to that backend.
Acceptance Criteria
- New MCP tool:
emit_event(event_type, payload)— persists event and triggers matching subscriptions - New API: CRUD for event subscriptions (source agent, event type, target message template)
- Subscription trigger: matching event → async task sent to subscribing agent with payload interpolated into message
- Permission-gated: only permitted agent pairs can subscribe
- UI: subscription management in agent detail page (stretch)
- Events visible in agent activity stream
Activity
vybe commentedon Mar 26, 2026
Implementation Complete: Agent Event Subscriptions (EVT-001)
What was built
Lightweight SQLite-backed pub/sub for inter-agent event pipelines:
MCP Tools (4 new):
emit_event(event_type, payload)— emit named events with structured datasubscribe_to_event(source_agent, event_type, target_message)— subscribe with{{payload.field}}templateslist_event_subscriptions(direction)— list subscriptionsdelete_event_subscription(subscription_id)— remove subscriptionsAPI Endpoints (9 new):
POST /api/agents/{name}/event-subscriptions— Create subscription (permission-gated)GET /api/agents/{name}/event-subscriptions— List (subscriber/source/both)GET/PUT/DELETE /api/event-subscriptions/{id}— CRUD by IDPOST /api/events— Emit event (source from MCP auth context)POST /api/agents/{name}/emit-event— Emit for specific agentGET /api/agents/{name}/events+GET /api/events— Event historyKey design:
agent_permissions— subscriber must be permitted to call source{{payload.field}}interpolationTests
44 tests, all passing (auth, CRUD, emit, history, triggers, permissions)
Acceptance criteria
emit_event(event_type, payload)agent_permissionsfeat: Agent Event Subscriptions — lightweight pub/sub for inter-agent…
feat: Agent Event Subscriptions — lightweight pub/sub for inter-agent…
merge: Resolve changelog conflict after merging upstream/main
merge: integrate upstream/main into feature branch