Files
hermes-agent/gateway/session_bot_state.py
Teknium ef52d34bdb feat(bot-mode): message_agent fans out with one combined reply, sends notify-only, cancels its own request, and reports a blocked teammate
- target accepts up to 8 comma-separated teammates: each is admitted as before, and one
  combined runner joins their reply runners and wakes the sender ONCE with a typed outcome per
  teammate (settled/failed/cancelled/pending + reply/error/reason/target_state).
- expects_reply=false: the message is marked "[no reply needed]" after the attribution colon and
  no reply runner starts (local: the payload and intent go once the owner admitted it; relay: no
  waiter; peer: the sending runner runs unwatched), so nothing wakes the sender.
- cancel=<delivery_id>: the sender withdraws its own queued request, or stops the exact turn it
  started, through the owner's prompt.cancel; the receipt's author must be the caller.
- The owner's deliver answer carries target_state (idle/working/waiting_approval/
  waiting_clarify/paused, never stored); the ack says plainly when the teammate is parked on its
  own user, and a runner whose wait lapses pending re-reads it through a same-id replay instead
  of ending on a silent timeout.
- One reply path (#95074): message_agent refuses a DM to the bot whose delivery this turn
  answers, since its final response already goes back. Protocol v3 names fan-out and notify-only.
2026-11-04 08:01:12 -08:00

28 lines
1.4 KiB
Python

"""A Bot Chat's live state, handed to the teammate whose ``message_agent`` delivery it answers.
A sender that only learns "queued" cannot tell a busy teammate from one parked on its user's
approval or clarify card; it waits out the bound and reports a silent timeout. The deliver answer
(and every same-id replay the waiting runner makes) carries this state instead. Read on the owner
loop, never persisted: a receipt holds outcomes, not a snapshot that is stale a second later.
"""
from gateway.session_contract import SessionRef
# Prompt kinds a running turn parks on, in the order a sender should hear about them.
_WAITING_KINDS = ('approval', 'clarify')
def bot_chat_state(authority, session_id):
"""``paused`` (the owner admits nothing new: a drain for restart/update or retirement),
``idle``, ``working``, or ``waiting_approval`` / ``waiting_clarify`` while the running turn
waits on its user."""
if authority.retiring or authority.runner._draining:
return 'paused'
live = authority.sessions.get(session_id)
if live is None:
return 'idle'
handle = authority._handle(SessionRef(authority.profile_id, session_id))
if handle.execution_state != 'running':
return 'idle'
kinds = {prompt['kind'] for prompt in live.controls.snapshot(session_id, handle.execution_generation)}
return next((f'waiting_{kind}' for kind in _WAITING_KINDS if kind in kinds), 'working')