C-10 Event Triggers
Brick C: Agents, autonomy, execution. French version: C-10-event-triggers
1. Role and responsibilities
Starts runs on events: POST /v1/events/publish writes the event to eai.event_outbox, publishes it on NATS JetStream when EAI_NATS_URL is set, and creates a run for every trigger (eai.triggers) whose subject and filter match. The server worker python -m eai.worker drains the outbox of unpublished events.
2. Position in the architecture and interactions
- Created runs are picked up by
AgentLoop.serve(); on the engine side,NatsMessageBuscan also consume events as inbound messages.
3. Open source component and developed part
- Engine: Navin architecture of the Python SDK, with no declared graph.
enterprise_ai.loop.AgentLooptakes in messages, prepares the context, manages sessions, resumes a run after a crash, handles stop, cron and heartbeat, and exposesserve();enterprise_ai.runtime.AgentRunnerruns one turn;enterprise_ai.subagents.SubagentManagerruns sub-agents in parallel;enterprise_ai.loop.plan.RunPlancarries the plan;enterprise_ai.runtime.bus.MessageBuslinks channels and engine. - Optional adapters: LangGraph (
enterprise_ai.runtime.langgraph.build_graph) and Temporal (enterprise_ai.runtime.temporal.build_workflow) reuse the same steps; neither is required. - Server side,
python -m eai.workerruns the periodic jobs: scheduler tick, event outbox drain, quota reservation expiry, stale heartbeat detection, retention.
4. Data model
Tables (schema eai, tenant_id RLS):
eai.triggers
Common columns: id uuid, tenant_id uuid NOT NULL, created_at, updated_at; RLS policy current_setting('app.tenant_id', true)::uuid.
5. Contract
- Applied contract: agent-manifest
- JSON Schema:
contracts/v1/agent-manifest.schema.json - Key fields:
spec.triggers[].subject, filter - Validation:
POST /v1/contracts/{name}/validate; manifest apply:POST /v1/manifests/apply.
6. API endpoints
GET /v1/triggersPOST /v1/triggersDELETE /v1/triggers/{id}POST /v1/events/publish
Request POST /v1/events/publish:
{
"subject": "crm.ticket.created",
"data": {
"ticket_id": "T-981",
"priority": "high"
}
}
Response:
{
"event_id": "1b6c2f0e-5d1a-4c55-9a51-2f7f6d0c9e11",
"subject": "tickets.created",
"backend": "nats",
"status": "published",
"ack": {"stream": "EAI_AGENT_RUNS", "seq": 10422},
"triggered": [{"trigger_id": "4f1e7b7a-8f43-4a43-b8a3-3c5f1f4c2d10", "run_id": "9a0c5e8b-2c1d-4e4f-8a6b-1d2e3f4a5b6c"}]
}
7. SDK examples
Python:
from enterprise_ai import EnterpriseAI
client = EnterpriseAI(base_url="<control-plane-url>", api_key="eai_xxx_secret")
client.triggers.create(agent_id="agt_support", subject="crm.ticket.created")
client.triggers.publish("crm.ticket.created", {"ticket_id": "T-981"})
TypeScript:
import { EnterpriseAI } from "@enterprise-ai/sdk";
const client = new EnterpriseAI({ baseUrl: "<control-plane-url>", apiKey: process.env.EAI_API_KEY });
await client.events.publish("crm.ticket.created", { ticketId: "T-981" });
Java:
EnterpriseAIClient client = EnterpriseAIClient.builder()
.baseUrl("<control-plane-url>")
.apiKey(System.getenv("EAI_API_KEY"))
.build();
client.events().publish(Map.of("subject", "crm.ticket.created", "payload", Map.of("ticket_id", "T-42")));
Go:
c, _ := eai.NewClient(eai.WithBaseURL("<control-plane-url>"), eai.WithAPIKey(os.Getenv("EAI_API_KEY")))
c.Events.Publish(ctx, "crm.ticket.created", data)
8. Configuration
- Environment variables:
EAI_NATS_URL,EAI_DATABASE_URL - Helm keys:
nats.enabled,worker.enabled
9. Security controls
- Subjects prefixed by tenant
- Publishing requires scope events:publish
- Every request carries the tenant resolved from the credential; PostgreSQL RLS
- Every mutation and policy decision writes a hash-chained audit event
10. Observability
- Prometheus metrics:
eai_events_published_total,eai_trigger_matches_total - Traces: OpenTelemetry spans with GenAI semantic conventions (
gen_ai.operation.name,gen_ai.agent.id,gen_ai.tool.name), attributeseai.tenant_id,eai.run_id,traceparentpropagation. - Audit actions:
event.publish
11. FinOps units
- Published messages, triggered runs.
- Emitted as Usage Event (
POST /v1/finops/usage) with tenant, project, agent and run.
12. Failure modes and resilience
- Nats-Msg-Id deduplication
- Outbox for transactional publishing
- Normalized errors (error envelope, message_i18n en/fr)
13. Standalone adoption (client of a client)
- enterprise_ai.scheduler + NATS.
- SDK:
enterprise_ai.agent(AgentsClient,RunsClient,SessionsClient) - Minimal deployment: Helm chart with
controlPlane.enabled=trueand PostgreSQL; disabled external components use their in-process fallback.
14. Acceptance tests
- Matching event -> one run created
- Duplicate message -> a single run
- Cross-tenant access refused
- Error returned in fr with Accept-Language: fr