Skip to content

Events and observability ​

Event stream ​

Agentweaver records each run as an ordered, durable stream of facts. The stream lets clients reconstruct timelines, graphs, approvals, status, and diagnostics after a restart or reconnection.

Each event has a run-local cursor. The normal append path obtains its sequence from durable storage before local delivery; subscribers resume from their last observed sequence. See the durable write-through and replay sequence.

Production uses EfRunEventStream to write events to PostgreSQL and poll by cursor across replicas. Local development uses SqliteRunEventStream. Process-local channels provide local delivery only; they are not the production cross-replica transport.

Telemetry ​

When APPLICATIONINSIGHTS_CONNECTION_STRING is configured, the API calls .UseAzureMonitor() to export OpenTelemetry data to Azure Monitor. The runtime also records explicit Agentweaver counters and histograms for operational metrics.

Model turns emit activities and agentweaver.token.usage metrics. Despite its name, that counter measures nano-AIU cost, not token count. Project metrics and run traces query telemetry when available; Azure Monitor export is separate from durable operational-event persistence.

Each provider agent turn also emits an agent.runtime_context durable event. It reports only run/project correlation, scalar sizes for the assembled base prompt, run context, assigned-skill block, separators, task, and provider declarations, plus a fixed skill delivery mode and ceil(totalCharacters / 4) planning estimate. Its section sizes always sum to totalCharacters. It is separate from memory.context_composition, which records the #1241 structured-context selection and omission results rather than prompt sizing.

Copilot SDK turns also emit agent.system_prompt from the same composition evidence. This includes the AgentHost-backed operator assistant path, for both GitHub Copilot and BYOK, as well as coordinator/project turns. The durable event contains the same bounded metadata plus callableMemoryGuidanceIncluded, which records whether the actual prompt-composition branch added callable project-memory guidance. Its provider field is only the canonical copilot or byok token; provider/configuration identifiers, types, model names, endpoints, prompt text and hashes, task/skill/charter content, tool names or schemas, credentials, PII, and unknown fields are never part of the public contract. REST and SSE rebuild a strict allowlisted projection, including for historical rows.

Operational use ​

Use the run stream to explain a specific run. Use GET /api/projects/{id}/metrics for project performance and GET /api/metrics/runs/{runId}/traces for trace details. Use cluster diagnostics for runtime dependencies and sandbox inventory.

Source ​

  • apps/Agentweaver.Api/Infrastructure/EfRunEventStream.cs
  • apps/Agentweaver.Api/Infrastructure/SqliteRunEventStream.cs
  • apps/Agentweaver.Api/Infrastructure/AzureMonitorBootstrap.cs
  • apps/Agentweaver.Api/Infrastructure/AgentWeaverMetrics.cs
  • packages/Agentweaver.AgentRuntime/CopilotAIAgent.cs

Visual model ​

Durable events ​

UML sequence showing events committed with a per-run sequence before local notification, SSE replay from Last-Event-ID, live polling with the same cursor, local snapshot delivery, and transport completion distinct from business success.

Structured source · Editable draw.io

Diagram details and constraints
ElementContract
titleDurable allocation, then cursor replay
takeawayCross-replica delivery polls shared rows; local notifications are not a distributed bus.
RecordNextRecordNext
RecordNextRequest sequence allocation
RecordNextAppend with Sequence = 0
EF appendEF append
EF appendReadCommitted + advisory lock
EF appendSerialize allocation per run
RunEventsRunEvents
RunEventsMAX+1 / insert / commit
RunEventsReturn assigned sequence
Local historyLocal history
Local historyUpdated after durable ack
Local historyNotify only local waiters
Web replica AWeb replica A
Web replica ARead Sequence > lastSeen
Web replica A250 ms delay only when empty
Browser watcherBrowser watcher
Browser watcherSSE sequence IDs
Browser watcherRemember last event cursor
Reconnect cursorReconnect cursor
Reconnect cursorLast-Event-ID
Reconnect cursorNot tied to original web pod
Web replica BWeb replica B
Web replica BOrdered replay and live tail
Web replica BRead same shared RunEvents
Resumed watcherResumed watcher
Resumed watcherReceive rows after cursor
Resumed watcherNo PostgreSQL NOTIFY required
arrow-1append
arrow-2commit
arrow-3ack
arrow-4poll
arrow-5SSE
arrow-6resume
note-0Rows: write-through / live delivery / reconnect on another replica.
note-1Explicit historic sequence: identical content is idempotent; conflicts fail.
note-2SQL commits before local history update; polling reads the shared table.
notesRows: write-through / live delivery / reconnect on another replica.; Explicit historic sequence: identical content is idempotent; conflicts fail.; SQL commits before local history update; polling reads the shared table.