Console Agent Pipeline
Agent interactions route through /api/ai/agent-chat and stream back over Server-Sent Events.
The pipeline’s job is to get a request into a sandbox safely and stream what happens.
The pipeline
- Validate the session with
requireAuth().
- Verify chat ownership for the org — a valid session for the wrong org is still a rejection.
- Resolve sandbox auth context and credentials.
- Load chat context and recent messages.
- Run the agent in the sandbox runtime.
- Stream events as they happen.
Steps 1–3 are all authorisation, in widening scope: is this a real session, does it own this chat,
and what may it reach. A failure at step 2 is the interesting one — it means a legitimate user
reached someone else’s conversation.
SSE event types
Handle error and stream_end as separate cases. An error may be followed by stream_end, so
treating either as “the stream is over” without distinguishing them loses the reason it ended.
The risk ladder
Tool calls are classified, and the classification decides whether a human confirms. This is the
mechanism, not a policy setting:
Confirmation is required at level 3 and above.
An unrecognised tool classifies as unknown at level 2 — below the confirmation threshold. So a
tool the classifier doesn’t know about executes without a human, and the safe-looking default is not
actually fail-closed for novel tools.If you add a tool that moves money or deletes data, make sure it classifies as financial,
destructive, or bulk rather than relying on the default.
Confirmation tokens
A sensitive tool call emits a confirmation event rather than executing. The client returns a
confirmation_token, and only then does the action run. Tokens are single-use, so a captured token
can’t be replayed to authorise a second action.
Guardrails
Tool calls are validated against policy before execution, backed by
NSR guardrails. The console’s risk ladder is the coarse gate; NSR is
where per-action authorisation with a cited proof happens.