last_stop_reason into a concise, user-safe note so a chat user learns why a turn stopped early — instead of getting a silently truncated or empty reply.
A deep-research agent hits its step limit; instead of a truncated answer, the reply ends with ⏳ I stopped after reaching the step limit — reply "continue" to carry on.
surface_completion_reason is a BotSessionManager constructor parameter — not a BotConfig field. Enable it where the session manager is built.Quick Start
1
Enable the notes on the gateway
Construct the session manager with
surface_completion_reason=True. Clean completed turns still surface nothing.2
Customise a note per turn
Override the default note for a turn by returning an
AgentReply with a TurnCompletion that carries detail.How It Works
After each turn the session manager reads the agent’slast_stop_reason, wraps it in a TurnCompletion, and — when enabled — appends the note to the reply.
extract_completion recognises an AgentReply with a completion, a serialised dict, or any object exposing completion / last_stop_reason (including a bare Agent). append_completion_note returns the text unchanged when disabled, when there is no completion, or when the turn completed cleanly.
Reasons and Default Notes
TurnCompletion.note() maps each stop reason to a user-safe message. A clean completion is intentionally silent.
Configuration Options
TurnCompletion and append_completion_note take these fields:
Off by default: existing deployments and clean completions are byte-for-byte unchanged.
Common Patterns
Long research agents with a highmax_steps — enable the note so "continue" becomes a discoverable UX:
/stop and sees the cancelled note instead of no reply:
Best Practices
Leave off for internal bots
Leave off for internal bots
Enable it for public-facing gateways. Internal bots often prefer silence, so keep the default
False there.Use detail to stay on-brand
Use detail to stay on-brand
TurnCompletion.detail overrides the default note per turn — use it to keep messages localised and on-brand.Happy paths stay quiet
Happy paths stay quiet
Notes never surface on a clean completion, so enabling this adds no noise to successful turns.
Pair with max_steps
Pair with max_steps
Combine with the step-limit docs so users understand the “reply continue” flow when a turn hits its budget.
Related
Max Steps
Cap tool-use steps and detect graceful truncation with
last_stop_reason.Error Handling
Detect and recover from turns that end early with
last_stop_reason.
