# Agent Turn And Step Lifecycle This sequence is the visual companion to [architecture.md](architecture.md#loop-lifecycle-session--turn--step). It keeps durable replay facts on `session/event` and live control/status on `agent/*`. ```mermaid sequenceDiagram participant User participant Agent participant Driver participant Hooks as hook listeners participant Prompt as ctx.systemPrompt participant LLM as ctx.llm participant Tools as ctx.tools participant Session participant Persistence participant SDK as UI or SDK listener User->>Agent: send(content) Agent-->>SDK: agent/queued Agent->>Driver: queued work wakes driver Driver-->>SDK: agent/status running Driver->>Session: turn/start Driver->>Hooks: agent/prompt-submit waterfall Hooks-->>Driver: allow, block, or add context Driver->>Session: user/message or rejected turn/end Driver->>Prompt: system-prompt/assemble waterfall Driver-->>Driver: agent/pre-step serial checkpoint Driver->>Session: step/start Driver->>LLM: agent/request waterfall, then llm/stream waterfall LLM-->>Driver: StreamChunk* Driver->>Session: assistant/chunk* Session-->>SDK: session/event assistant/chunk* Driver->>Hooks: agent/step-result waterfall Driver->>Session: assistant/message Driver->>Session: tool/call Driver->>Tools: execute through pre and post waterfalls Tools-->>Session: tool-owned events when applicable Driver->>Session: tool/result and step/end Driver->>Hooks: agent/turn-continuation waterfall Driver->>Hooks: agent/turn-stop serial terminal checkpoint Driver->>Session: turn/end Driver->>Persistence: session/flush parallel checkpoint Driver-->>SDK: agent/status idle ``` SDK users that need replayable transcript data should consume `session/event`; `agent/*` is the live coordination surface for queue/status, prompt interception, request shaping, steering, continuation, and errors. Maintenance mode: curated Mermaid sequence; exact event signatures live in the generated Cordis catalog.