fix(gateway_tools,conversations): say refused in user turns, the reply reaches the human itself

This commit is contained in:
hh
2026-08-30 02:26:35 +02:00
parent cc32307921
commit d57f660a30
3 changed files with 52 additions and 1 deletions
+5
View File
@@ -883,6 +883,11 @@ class Conversations:
self._ensure_worker(cast("int", conv.id))
return item
def turn_origin(self, conv: Conversation) -> str | None:
"""Origin of the running turn (``user``, ``inject``, ...); None when idle."""
runner = self._runners.get(cast("int", conv.id))
return runner.origin if runner is not None and runner.turn_id else None
async def say(self, conv: Conversation, text: str) -> dict[str, Any]:
runner = self._runners.get(cast("int", conv.id))
_log.info("say[%s]: %s", conv.external_id, text[:200])
+9 -1
View File
@@ -26,6 +26,11 @@ __all__ = ["SERVER_NAME", "TOOL_NAMES", "build_tool_server"]
_log = logging.getLogger("beaver_gateway.core.gateway_tools")
SERVER_NAME = "gateway"
SAY_IN_USER_TURN = (
"not delivered: this turn was started by the human's message, so your "
"reply text reaches them by itself - put what you wanted to say into the "
"reply instead of repeating it here"
)
TOOL_NAMES = ("read_conversation", "spawn", "say", "schedule", "inject", "close_chat")
@@ -118,11 +123,14 @@ def _tools(conversations: Conversations, key: str) -> list[SdkMcpTool[Any]]:
"say",
"Say something to the human in the frontend this conversation is bound "
"to. The only way an inject-started turn can speak; silence is simply "
"not calling it.",
"not calling it. Refused in a turn started by the human's own message: "
"there your reply text reaches them by itself, so just write the reply.",
{"text": str},
)
async def say(args: dict[str, Any]) -> dict[str, Any]:
conv = await current()
if conversations.turn_origin(conv) == "user":
return _error(SAY_IN_USER_TURN)
await conversations.say(conv, str(args["text"]))
return _text("ok")