Quick Start
1
Turn the note on
Pass A truncated turn now ends with
surface_completion_reason=True to the session manager. A turn that stops early appends a note to the reply.⏳ I stopped after reaching the step limit — reply "continue" to carry on.2
Emit a custom TurnCompletion yourself
Return an
AgentReply with your own TurnCompletion when the agent already knows why it stopped.detail overrides the default note verbatim — it’s already user-safe, no template applied.How It Works
The gateway reads the turn’s completion after each reply and appends a note only when the turn stopped early and the flag is on.Configuration Options
surface_completion_reason is a parameter on BotSessionManager — there is no BotConfig field for it today, and build_session_manager does not forward it. Construct the session manager directly, or use the raw helpers below in a custom reply path.Completion reason vocabulary
The reasons mirrorAgent.last_stop_reason and the built-in _COMPLETION_NOTES map.
.truncated is True for anything not in {"completed", ""}.
The TurnCompletion Contract
TurnCompletion wraps the coarse stop reason into a portable value the reply path can render.
Gateway Integration
Operators wiring a custom reply path use the two raw helpers directly.extract_completion checks, in order:
AgentReply.completionif the result is anAgentReply.dict["completion"]if the result is a serialised dict.result.completionattribute on any object.result.last_stop_reasonstring on any object (the plain-text-agent fallback).None.
append_completion_note returns the text untouched when enabled=False, when there is no completion, or when the turn completed cleanly — so turning it on only affects truncated turns.
Common Patterns
Turn on notes for early stops on public bots
One flag on the session manager, matching the Quick Start.Return an AgentReply with a custom detail
For agent code that already knows why it’s stopping.Serialise across a network hop
Round-trip viato_dict() / from_dict() on both TurnCompletion and AgentReply.
Best Practices
Keep the flag off unless you want early-stop notes
Keep the flag off unless you want early-stop notes
Clean completions never surface a note, so turning
surface_completion_reason on only affects truncated turns. Leave it off for bots where a silent reply is fine.Prefer TurnCompletion.detail over rewriting the default note
Prefer TurnCompletion.detail over rewriting the default note
detail is user-safe, agent-authored, and localisable per turn. Set it when the agent knows the specific reason instead of relying on the generic default.Combine with a low max_steps for debugging
Combine with a low max_steps for debugging
Set
max_steps=5 so ⏳ step limit notes surface fast while you tune step budgets.Emit cancelled yourself when a user interrupts
Emit cancelled yourself when a user interrupts
The gateway’s default
cancelled note is generic — set your own detail to replace it.Related
Messaging Bots
All supported platforms: Telegram, Discord, Slack, WhatsApp
Max Steps
Bound how many steps an agent turn may take
Error Handling
Retries, fallbacks, and graceful failure
Bot Streaming Replies
Live streaming responses for Telegram, Slack, and Discord

