Purpose
Define the single-chat turn model. A turn is one chat unit:- one inbound chat event
- one runtime execution path
- one outbound result (or denial/failure)
Turn Identity
Required:turnIdsessionIdchatIdtraceIdcorrelationId
idempotencyKeycausationId
Single-Chat Turn Model
1) Receive
- gateway forwards normalized chat event
- runtime validates required fields
- runtime acquires per-session turn lock
2) Understand
- load current context (recent messages + workspace contracts + memory pointers)
- build minimal objective for this turn
3) Decide
- run model inference through pi adapter
- choose response path:
- direct response
- tool-assisted response
- deny/fail with reason
4) Execute (optional tools)
- run approved tool calls (if needed)
- feed tool results back to model
- keep execution bounded by timeout/call limits
5) Respond
- emit one terminal result:
completedfaileddenied
- include
reasonandnextActionwhen not completed
6) Record
- append events and terminal result to JSONL
- update checkpoint/cursor
- release turn lock
Runtime Invariants
- Exactly one terminal status per turn
- No sender-type branch (same path for all
sender.agentId) - Bounded execution (token/tool/time limits)
- Persist-before-finish (record succeeds before turn closes)
- Restart-recoverable from local files only
Tool Execution Rules
- All tools pass policy + schema validation first
- Tool failures are structured (
tool_runtime_error) - Tool loop is bounded (
maxToolCallsPerTurn, timeout caps)
- turn ends as
failed nextActionmust suggest recovery
Queue Behavior During Active Turn
Default:- new events are queued (
collect) for next turn
steerpolicy can inject after safe boundary
- current turn must end with terminal status
- partial/half-committed turn is invalid
Failure Classes
invalid_inputpolicy_deniedtool_runtime_errortimeoutprovider_errorreport_missing
Local-First Recovery
On restart:- load last checkpoint
- inspect last turn entry in JSONL
- if last turn is non-terminal, close as recovered failure
- continue from next inbound event
Acceptance Criteria
- Turn follows the 6-step single-chat model
- One terminal status is always emitted
- Same runtime path is used for Agent↔Human and Agent↔Agent
- JSONL + checkpoint recovery works locally