Telegram gateway: show tool calls inline during chat turns #961

Closed
opened 2026-10-27 13:38:28 +00:00 by sam · 0 comments
Owner

The Telegram chat agent returns only the final answer. The user cannot see which tools are being called, their parameters, or their results. This makes debugging agent behavior (hallucinations, wrong tool choices, footguns like systemctl stop vs restart) impossible from the chat side.

Desired behavior

After each tool call completes, the gateway sends a compact inline message showing the tool name and a one-line summary of the result, before the next tool call or final answer. Similar to how Hermes surfaces tool calls in Telegram.

Example format:

🔧 memory_edit — added entry
🔧 terminal — systemctl --user stop archied (exit 0)
🔧 terminal — systemctl --user start archied (exit 0)

Then the final answer.

Scope

internal/channels/telegram/ only. Behind a config flag [chat.telegram] show_tool_calls = true so it can be toggled.

Technical approach

Currently the call chain is:

submitTurn → router.RouteStream(turnCtx, gm, draft.onDelta)
           → r.LLMStream(ctx, msg, onDelta)
           → TurnRunner.Run(ctx, msg, onDelta)
           → prepared.Generate(ctx, req, onDelta)

Only onDelta (text streaming) is threaded through. Tool calls happen inside Generate but there's no callback back to the gateway.

What needs to change

  1. Add a tool-call observer callback — either extend LLMStreamResponder signature or add a separate OnToolCall field to gateway.Router struct, plumbing it through TurnRunner → TurnModel/PreparedTurnModel.Generate so model providers can report tool invocations

  2. Model provider integration — the chat turn model (cmd/archied/chat_turn_model.go) and any provider-specific Generate implementations need to call the observer when a tool is executed, passing tool name + result summary

  3. Telegram gateway wiring — in submitTurn (internal/channels/telegram/telegram.go), if show_tool_calls config is true, wire the observer to send a compact inline message via sendMessage before the final reply

  4. Config plumbing — add ShowToolCalls bool to the Telegram gateway config struct and read it from [chat.telegram] show_tool_calls in telegram_setup.go

Key files

File Role
internal/gateway/gateway.go RouteStream, Router struct (add observer field)
internal/gateway/turn.go TurnRunner.Run, PreparedTurnModel.Generate signature
cmd/archied/chat_turn_model.go Model provider Generate — where tool calls execute
internal/channels/telegram/telegram.go submitTurn — wire observer + send messages
cmd/archied/telegram_setup.go Config reading + gateway construction

Imported from beads archie-core-1786637501270-433-dc1a0bc2 · GitHub #467 · type feature · priority P2 · created 2026-08-12 · closed 2026-08-14

The Telegram chat agent returns only the final answer. The user cannot see which tools are being called, their parameters, or their results. This makes debugging agent behavior (hallucinations, wrong tool choices, footguns like `systemctl stop` vs `restart`) impossible from the chat side. ## Desired behavior After each tool call completes, the gateway sends a compact inline message showing the tool name and a one-line summary of the result, before the next tool call or final answer. Similar to how Hermes surfaces tool calls in Telegram. Example format: ``` 🔧 memory_edit — added entry 🔧 terminal — systemctl --user stop archied (exit 0) 🔧 terminal — systemctl --user start archied (exit 0) ``` Then the final answer. ## Scope `internal/channels/telegram/` only. Behind a config flag `[chat.telegram] show_tool_calls = true` so it can be toggled. ## Technical approach Currently the call chain is: ``` submitTurn → router.RouteStream(turnCtx, gm, draft.onDelta) → r.LLMStream(ctx, msg, onDelta) → TurnRunner.Run(ctx, msg, onDelta) → prepared.Generate(ctx, req, onDelta) ``` Only `onDelta` (text streaming) is threaded through. Tool calls happen inside `Generate` but there's no callback back to the gateway. ### What needs to change 1. **Add a tool-call observer callback** — either extend `LLMStreamResponder` signature or add a separate `OnToolCall` field to `gateway.Router` struct, plumbing it through `TurnRunner` → `TurnModel`/`PreparedTurnModel.Generate` so model providers can report tool invocations 2. **Model provider integration** — the chat turn model (`cmd/archied/chat_turn_model.go`) and any provider-specific `Generate` implementations need to call the observer when a tool is executed, passing tool name + result summary 3. **Telegram gateway wiring** — in `submitTurn` (`internal/channels/telegram/telegram.go`), if `show_tool_calls` config is true, wire the observer to send a compact inline message via `sendMessage` before the final reply 4. **Config plumbing** — add `ShowToolCalls bool` to the Telegram gateway config struct and read it from `[chat.telegram] show_tool_calls` in `telegram_setup.go` ### Key files | File | Role | |------|------| | `internal/gateway/gateway.go` | `RouteStream`, `Router` struct (add observer field) | | `internal/gateway/turn.go` | `TurnRunner.Run`, `PreparedTurnModel.Generate` signature | | `cmd/archied/chat_turn_model.go` | Model provider `Generate` — where tool calls execute | | `internal/channels/telegram/telegram.go` | `submitTurn` — wire observer + send messages | | `cmd/archied/telegram_setup.go` | Config reading + gateway construction | --- _Imported from beads `archie-core-1786637501270-433-dc1a0bc2` · GitHub #467 · type feature · priority P2 · created 2026-08-12 · closed 2026-08-14_
sam added the mediumfeature labels 2026-10-27 13:38:28 +00:00
sam self-assigned this 2026-10-27 13:38:28 +00:00
sam closed this issue 2026-10-27 13:38:28 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#961