Skip to content

Agent Event Subscriptions: lightweight pub/sub for inter-agent pipelines #169

Closed

Description

@vybe

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:

  1. Agents emit named events via a new MCP tool (emit_event)
  2. Agents subscribe to events from other agents (respecting existing agent_permissions)
  3. 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

  1. added
    priority-p1
    type-feature
    on Mar 25, 2026
  2. vybe commented on Mar 26, 2026

    @vybe
    ContributorAuthor

    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 data
    • subscribe_to_event(source_agent, event_type, target_message) — subscribe with {{payload.field}} templates
    • list_event_subscriptions(direction) — list subscriptions
    • delete_event_subscription(subscription_id) — remove subscriptions

    API 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 ID
    • POST /api/events — Emit event (source from MCP auth context)
    • POST /api/agents/{name}/emit-event — Emit for specific agent
    • GET /api/agents/{name}/events + GET /api/events — Event history

    Key design:

    • Permission model: uses existing agent_permissions — subscriber must be permitted to call source
    • Trigger: matching event → async task to subscriber with {{payload.field}} interpolation
    • Events persisted + broadcast via WebSocket for real-time visibility

    Tests

    44 tests, all passing (auth, CRUD, emit, history, triggers, permissions)

    Acceptance criteria

    • New MCP tool: emit_event(event_type, payload)
    • New API: CRUD for event subscriptions
    • Subscription trigger: matching event → async task with payload interpolation
    • Permission-gated via agent_permissions
    • UI: subscription management (stretch — not in this PR)
    • Events visible in activity stream (WebSocket broadcast)
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-p1type-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions