Skip to content

Bot: a Turn that answers in plain text without SendUser or sleep leaves the answer out of Chat #6711

Open

Description

What happened

@M4n5ter A Bot Turn wrote a complete answer as ordinary text, did not call SendUser or sleep, and ended normally. Chat shows only the muted line from #6514, "The Bot did not reply this time". The answer is visible only under Execution.

The Bot's reasoning for that Turn ends with "I'll use SendUser.", and the next part is the answer as plain text. The system prompt is explicit ("the user sees only the messages you send with the SendUser tool… To respond to the user, call SendUser"), so the instruction is there and the model still did not follow it.

From the event log of that Turn (a fresh Root, the first Turn of the Bot):

  • One model_completed with two parts: thinking (1385 reasoning tokens) and text (the full answer, about 1900 output tokens in total).
  • finish_reason: stop, no tool call in the step.
  • Then invocation_ended. No SendUser, no sleep.

So by #6514's table this is the "neither SendUser nor sleep (completed)" case, and the UI behaves as designed. This issue is about that outcome itself: the user asked a question, the model produced the answer, and it never reached them. They only find it by switching to Execution, where it sits among the reasoning and tool steps.

This is different from #6622, which was about text followed by sleep. You closed that one as deliberate silence, and that makes sense: the Bot chose to stop. Here it did not choose anything; the Turn just ran out.

How to reproduce

Not deterministic. It happens with K3.1 Pro on an Anthropic-compatible endpoint, mostly on long analytical questions. Ask the Bot an open-ended question in Chinese, for example a multi-year macro scenario question. In some Turns the answer is written as plain text and the Turn ends.

Environment

  • rust-preview 1cba85e (desktop, macOS). The local build also carries an unrelated Chat prototype that does not touch the Bot engine or Bot UI.
  • Model: k3.1-pro through a Kimi coding-plan connection (Anthropic Messages protocol).

Possible directions

  1. Remind once at the end of the Turn. When a Bot step finishes with final text and no tool call, and the Turn has sent nothing and not slept, the engine adds one short reminder ("Your text is not visible to the user. Send it with SendUser, or call sleep if nothing needs their attention.") and runs one more step. At most once per Turn, so a model that keeps ignoring it still ends. The answer then goes through SendUser and the outbox as usual. The cost is one more model call that repeats the text.
  2. Show the unsent text in Chat. Keep the muted line, and let it expand to show what the Bot wrote, marked as not sent. UI only and free, but the text is still not delivered: it never goes into the outbox.
  3. Leave it and treat it as a model-quality issue.

I lean towards 1, since it keeps "only SendUser reaches the user" intact and fixes the delivery, not just the display. Is this something you want to handle, or should we open a PR for the direction you prefer?

Activity

  1. M4n5ter commented on Nov 9, 2026

    @M4n5ter
    Member
    EnglishI think this should be addressed by completing the Bot execution contract discussed in #6464.

    Bot model requests should require a tool call where the provider supports it (tool_choice: required or the equivalent). The Bot can continue working with its other tools, use SendUser when it needs to communicate, and call sleep when it is done for now. Ordinary model text should not silently end the Bot turn.

    We already added sleep in #6505, but the required tool choice was left out. Connecting it should address the text-only completion described here for providers that support it, without adding a separate reminder and extra model step as the primary path.

    We still need an explicit fallback for providers or thinking modes that cannot enforce tool choice, and should verify the behavior against the K3.1 Pro endpoint used in this report.

    中文 我认为这里应该补全之前在 #6464 讨论过的 Bot 执行契约。

    对于支持强制工具调用的 provider,Bot 模型请求应使用 tool_choice: required 或对应配置。Bot 可以继续调用其他工具完成工作,需要告知用户时调用 SendUser,暂时完成时调用 sleep。普通模型文本不应该让 Bot 这一轮静默结束。

    #6505 已经加入了 sleep,但强制工具调用当时没有纳入。把它接上后,应该能解决支持该能力的 provider 在这里出现的纯文本结束问题,而不必首先通过额外提醒和增加一次模型调用来处理。

    对于无法强制工具调用的 provider 或思考模式,仍需要明确的兜底策略;也需要针对这次报告使用的 K3.1 Pro 端点验证实际行为。

  2. YongGoose commented on Nov 11, 2026

    @YongGoose
    Member

    Hi @UncertaintyDeterminesYou4ndMe, thank you for the detailed report.

    If you haven't started on this yet, would you mind if I took it? I'd follow the direction suggested above: require a tool call for Bot requests where the provider supports it, with an explicit fallback for providers or thinking modes that can't enforce it.

    If you'd rather open the PR yourself, that's completely fine. Just let me know.

  3. jackeyfaker77 commented on Nov 18, 2026

    @jackeyfaker77
    Contributor
    English

    Picking this up (take above, as it is still unassigned) — happy to coordinate if @YongGoose already has work in progress.

    Following @M4n5ter's direction to complete the #6464 / #6505 Bot execution contract on rust-preview:

    1. Primary path — require a tool call on Bot turns (ToolChoiceMode::Required):

      • Add Required to ToolChoiceMode (maka-agent-facts / maka-model) and set it on Bot main-turn requests (leaving non-Bot sessions on Auto and summary repair on None).
      • Wire Required across the protocol adapters: Anthropic Messages (WireChoice::Any when policy.forced_choice holds), Chat Completions ("required"), and OpenAI Responses ("required").
    2. Explicit fallback for thinking modes / providers that cannot enforce tool_choice:

      • On Anthropic Messages, PreparedTools::build (anthropic/request.rs) already downgrades Required → Auto (ForcedToolChoiceIgnored) when budgeted thinking or reject_forced adaptive thinking is active — which matches the reported k3.1-pro (Anthropic protocol + thinking) trace. Other compatible relays may also reject or ignore forced tool choice.
      • If a request has to degrade to Auto (or a provider rejects forced tool_choice / still finishes a step with stop, plain text, and zero tool calls while the Bot Turn has neither called SendUser nor sleep), run at most one bounded follow-up step reminding the Bot to deliver via SendUser or finish with sleep (and if an endpoint rejects forced tool_choice at HTTP level, retry once with Auto before applying that guard). If the follow-up still produces no SendUser/sleep, let the Turn settle normally without looping.
    3. Verification:

      • Focused Rust behavior tests covering Required wire encoding across protocols, thinking-mode downgrade + single-step fallback recovery, non-looping termination when the fallback is still ignored, and sleep / steering interaction.
      • Live verification against k3.1-pro on kimi-coding-plan (Anthropic Messages, with and without thinking), or explicit reporting if a specific endpoint combination behaves differently.
    中文

    看当前还没有分配,我先 take 认领推进(如果 @YongGoose 已有在途改动欢迎随时同步)。

    按 @M4n5ter 指出的方向,在 rust-preview 上补全 #6464 / #6505 的 Bot 执行契约:

    1. 主路径 —— Bot 请求默认强制工具调用(ToolChoiceMode::Required):

      • 在 ToolChoiceMode(maka-agent-facts / maka-model)补充 Required,仅对 Bot 主循环请求启用(普通会话保持 Auto,summary repair 保持 None)。
      • 贯通三套协议适配器:Anthropic Messages(policy.forced_choice 允许时发 WireChoice::Any)、Chat Completions("required")与 OpenAI Responses("required")。
    2. 不支持强制工具调用的思考模式 / Provider 显式兜底:

      • 在 Anthropic Messages 下,当开启 budgeted thinking 或 reject_forced adaptive thinking 时,PreparedTools::build 已会将 Required 降级为 Auto(ForcedToolChoiceIgnored)——这正对应本单 k3.1-pro(Anthropic 协议 + 1385 推理 token)的场景;部分兼容网关也可能拒绝或忽略强制 tool_choice。
      • 当请求因思考模式/网关限制降级为 Auto(若网关对强制 tool_choice 直接报参数错误则单次降级 Auto 重试),或模型仍在零工具调用、未调 SendUser 且未 sleep 的情况下以纯文本 stop 结束时,在引擎侧执行每轮最多一次的受限追问步,提示通过 SendUser 发送或调用 sleep 结束;若追问步仍未调用,则正常收敛结束,绝不死循环。
    3. 验证:

      • 补齐跨协议 Required 编码、思考模式降级 + 单次兜底恢复、二次忽略不死循环以及与 sleep/steering 交互的行为测试。
      • 针对报告中的 kimi-coding-plan k3.1-pro(含开关思考模式)做实测验证并附上结果。
  4. jackeyfaker77 commented on Nov 18, 2026

    @jackeyfaker77
    Contributor

    untake

  5. YongGoose commented on Nov 18, 2026

    @YongGoose
    Member

    If @UncertaintyDeterminesYou4ndMe isn't planning to proceed, please feel free to go ahead!
    I'm happy to step aside and let you take this one. Just let me know if you'd like me to review it!

  6. added 4 commits that reference this issue on Nov 18, 2026
    cc904e7
    f48a286
    2152d14
    e8962c0
  7. Prathmesh010190 commented on Nov 22, 2026

    @Prathmesh010190

    Complete solution approach, grounded in the codebase

    Hi @UncertaintyDeterminesYou4ndMe and @M4n5ter, I've read through the full execution path in the local source and want to lay out a precise, self-contained fix. Happy to open a PR for this.


    Root cause (confirmed from source)

    Three files tell the whole story:

    plugins/agent/facts/src/model/request.rs (line 100)
    ToolChoiceMode currently has only two variants: Auto (the default) and None. There is no Required variant, so there is no way to tell the wire layer to force a tool call.

    plugins/agent/native/src/owner/driver_model.rs (lines 801 and 1765)
    Both PromptSettings construction sites for Bot main turns hard-code tool_choice: ToolChoiceMode::Auto. Auto lets the model decide, so a thinking-mode model (e.g. k3.1-pro via Anthropic Messages) can finish reasoning, write the answer as plain text, and return finish_reason: stop with zero tool calls. SendUser is never called, so the answer is invisible to the user.

    plugins/agent/model/src/adapters/request.rs (lines 118–121 and 201–203)
    The Anthropic and Chat Completions adapter match arms only cover Auto and None. There is no code path that emits {"type":"any"} or "required" today.


    The fix: 4 coordinated changes

    1. Add Required to ToolChoiceMode

    File: plugins/agent/facts/src/model/request.rs

    // BEFORE (line 100)
    pub enum ToolChoiceMode {
        #[default]
        Auto,
        None,
    }
    
    // AFTER
    pub enum ToolChoiceMode {
        #[default]
        Auto,
        None,
        /// Force the model to call a tool. Set on Bot main-turn requests where
        /// SendUser and sleep are both present in the tool surface.
        /// Downgraded to Auto when the provider or thinking mode cannot enforce it.
        /// A single bounded fallback step runs if the step still closes with
        /// stop + no tool call.
        Required,
    }

    Backward-compatible: the serde tag is "required" (snake_case). Old frozen inputs serialized as "auto" continue to deserialize correctly.


    2. Set Required at both PromptSettings sites

    File: plugins/agent/native/src/owner/driver_model.rs

    The CompositionSurface struct (from plugins/agent/facts/src/composition.rs) already holds tools: Vec<Arc<ToolDefinition>>. Check whether both SendUser and sleep are present in that list; if so, and it is a main (non-summary) turn, use Required.

    // Site A: line 801 (primary path)
    // BEFORE
    tool_choice: ToolChoiceMode::Auto,
    
    // AFTER
    tool_choice: if !summary
        && surface_has_send_user_and_sleep(&definitions)
    {
        ToolChoiceMode::Required
    } else {
        ToolChoiceMode::Auto
    },
    // Site B: line 1765 (continuation/replay path)
    // BEFORE
    tool_choice: ToolChoiceMode::Auto,
    
    // AFTER
    tool_choice: if surface_has_send_user_and_sleep(&definitions) {
        ToolChoiceMode::Required
    } else {
        ToolChoiceMode::Auto
    },
    // Helper: check by tool name, since ToolDefinition.name is the stable identity
    fn surface_has_send_user_and_sleep(tools: &[Arc<ToolDefinition>]) -> bool {
        let has_send = tools.iter().any(|t| t.name == "SendUser");
        let has_sleep = tools.iter().any(|t| t.name == "sleep");
        has_send && has_sleep
    }

    Note: summary_repair.rs lines 263–266 already correctly set ToolChoiceMode::None for repair and excerpted passes. Leave those untouched.


    3. Wire Required through all three protocol adapters

    File: plugins/agent/model/src/adapters/request.rs

    Anthropic Messages (lines 118–121):

    // BEFORE
    let choice = (!tools.is_empty()).then_some(match request.tool_choice {
        ToolChoiceMode::Auto => anthropic::ToolChoice::Auto,
        ToolChoiceMode::None => anthropic::ToolChoice::None,
    });
    
    // AFTER
    let (choice, forced_choice) = if tools.is_empty() {
        (None, false)
    } else {
        match request.tool_choice {
            ToolChoiceMode::Auto => (Some(anthropic::ToolChoice::Auto), false),
            ToolChoiceMode::None => (Some(anthropic::ToolChoice::None), false),
            // Any = {"type":"any"}: call some tool, model's choice which one
            ToolChoiceMode::Required => (Some(anthropic::ToolChoice::Any), true),
        }
    };

    Chat Completions (lines 201–203):

    // AFTER
    let tool_choice = (!tools.is_empty()).then_some(match request.tool_choice {
        ToolChoiceMode::Auto => chat_completions::request::ToolChoice::Auto,
        ToolChoiceMode::None => chat_completions::request::ToolChoice::None,
        // serialized as the string "required" per OpenAI spec
        ToolChoiceMode::Required => chat_completions::request::ToolChoice::Required,
    });

    OpenAI Responses (adapters/responses/request.rs, lines 362–363):

    // AFTER
    ToolChoiceMode::Auto => wire::request::ToolChoice::Auto,
    ToolChoiceMode::None => wire::request::ToolChoice::None,
    ToolChoiceMode::Required => wire::request::ToolChoice::Required,

    Add matching Required variants to the wire types in maka-provider-protocol.


    4. Thinking-mode downgrade + single-step bounded fallback

    This is the critical path for the reported k3.1-pro case (Anthropic Messages + 1385 reasoning tokens). Anthropic rejects {"type":"any"} when budgeted or reject_forced thinking is active.

    Static downgrade in PreparedTools::build (Anthropic request path):

    // When thinking config is incompatible with forced tool_choice, downgrade silently.
    // The fallback guard below catches the resulting plain-text stop.
    if forced_choice && (has_budgeted_thinking || has_reject_forced_thinking) {
        choice = Some(anthropic::ToolChoice::Auto);
        tracing::debug!(
            reason = "ForcedToolChoiceIgnored",
            "Required downgraded to Auto: thinking mode active"
        );
    }

    Dynamic retry for providers that reject at HTTP level:

    // On HTTP 400 where the body mentions "tool_choice", retry once with Auto.
    // Cache the incapable (transport, endpoint, model) tuple in a bounded set (1024 entries).
    if status == 400 && forced_choice && body.contains("tool_choice") {
        endpoint_caps.insert(endpoint_key, EndpointCap::CannotForceToolChoice);
        return retry_with_auto(request).await;
    }

    Engine-level fallback (the safety net for both downgrade paths):

    When a main-turn model step closes with finish_reason: Stop, zero tool calls, no SendUser output recorded, no sleep called, and no fallback has fired for this Turn yet:

    1. Publish a durable Fact::PlaintextFallbackFired { attempt: ModelAttemptId } (new variant added to the Fact enum in durable.rs; tagged plaintext_fallback_fired).
    2. Inject one synthetic reminder message: "Your answer above was written as plain text and is not visible to the user. Call SendUser to deliver it, or sleep if you are done."
    3. Run one more model step.
    4. If the follow-up also produces no tool call, settle normally. There is no loop: the durable flag ensures at most one fallback per Turn.
    // New Fact variant in plugins/agent/facts/src/durable.rs, appended to the Fact enum:
    PlaintextFallbackFired {
        attempt: ModelAttemptId,
    },
    // is_late()       -> true (matches the existing pattern for ModelClosed etc.)
    // is_admission()  -> false
    // content_refs()  -> vec![]

    Summary of what changes where

    File Change
    facts/src/model/request.rs Add Required variant to ToolChoiceMode
    facts/src/durable.rs Add PlaintextFallbackFired to Fact enum
    native/src/owner/driver_model.rs (lines 801, 1765) Set Required on Bot main turns
    model/src/adapters/request.rs (lines 118–121, 201–203) Wire Required in Anthropic + Chat Completions
    model/src/adapters/responses/request.rs (lines 362–363) Wire Required in Responses
    Anthropic request path Static thinking-mode downgrade
    HTTP retry layer Dynamic HTTP 400 downgrade + cache
    engine/src/driver.rs PlaintextFallbackFired detection + single bounded follow-up

    Required tests (to prevent regression)

    • ToolChoiceMode::Required serializes as "required" and round-trips
    • Anthropic wire: Required → {"type":"any"}
    • Chat Completions wire: Required → "required"
    • Responses wire: Required → "required"
    • Bot main turn → Required; ordinary session → Auto; summary repair → None
    • Thinking-mode active → downgrade to Auto before send
    • HTTP 400 on tool_choice → retry with Auto, endpoint cached
    • Stop + 0 tool calls + no SendUser → fallback fires once → SendUser called → reaches outbox
    • If the fallback step also ignores the reminder → Turn settles, no loop
    • PlaintextFallbackFired correctly classified as is_late(), not is_admission()

    Happy to open a PR for this. Let me know which direction works best for the team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions