Skip to content

Bug: gateway sessions expose clarify tool but never wire clarify_callback #12573

@tymrtn

Description

@tymrtn

Summary

clarify is exposed in gateway sessions, but Telegram/gateway-created agents do not wire a clarify_callback, so the tool immediately returns:

Clarify tool is not available in this execution context.

Repro

  1. Start Hermes gateway on Telegram.
  2. In a Telegram DM, ask the agent to use clarify (or trigger it directly).
  3. The tool call fails immediately instead of showing a prompt.

What I verified

  • In this Telegram chat, calling clarify directly reproduces the error live.
  • tools/clarify_tool.py returns that exact error when callback is None.
  • run_agent.py documents the contract: the platform layer must provide clarify_callback, otherwise the tool errors.
  • CLI wires clarify_callback=self._clarify_callback.
  • Gateway _run_agent() did not set agent.clarify_callback, so gateway-created AIAgent instances always saw None.

Root cause

Gateway sessions instantiate and cache AIAgent instances, but only set per-message progress/status/stream callbacks. They never attach a clarify callback, so the tool schema exists but the user-interaction bridge is missing.

Expected behavior

Gateway-created agents should provide a working clarify callback so messaging platforms can collect the next user reply (at minimum via text prompt + reply).

Telegram could later be upgraded to inline buttons, but the immediate regression is simpler: the callback is not wired at all.

Proposed fix

  • Add a gateway-side clarify callback builder.
  • Track pending clarify prompts per session.
  • Intercept the next user message to resolve the pending clarify response.
  • Assign agent.clarify_callback = ... in _run_agent() alongside the other per-message callbacks.

Regression coverage

Add gateway tests proving:

  • the callback round-trips a user response,
  • pending clarify replies are consumed and normalized,
  • _run_agent() wires clarify_callback onto the agent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions