feat(telegram): display tool execution status messages

Telegram bot now shows tool status during execution:
- Sends status message when tool starts (tool name + args snippet)
- Edits status message with result on completion
- Keeps typing indicator active during tool execution
- Adds setOnToolUse() to NativeAgent for per-message callback control
This commit is contained in:
William Valentin
2026-02-05 17:53:54 -08:00
parent 5088f7a6be
commit ad7fc241f1
2 changed files with 40 additions and 0 deletions
+4
View File
@@ -190,4 +190,8 @@ export class NativeAgent {
getModelTier(): ModelTier {
return this.currentTier;
}
setOnToolUse(callback: ((event: ToolUseEvent) => void) | undefined): void {
this.onToolUse = callback;
}
}
+36
View File
@@ -97,9 +97,44 @@ export function createTelegramBot(config: TelegramBotConfig): Bot {
// Show typing indicator
await ctx.replyWithChatAction('typing');
// Set up tool status display for this message
let statusMsgId: number | undefined;
config.agent.setOnToolUse(async (event) => {
try {
if (event.type === 'start') {
const argsSnippet = event.args ? ` ${JSON.stringify(event.args).slice(0, 100)}` : '';
const statusText = `${event.tool}${argsSnippet}`;
const msg = await ctx.reply(statusText);
statusMsgId = msg.message_id;
// Keep typing indicator active
await ctx.replyWithChatAction('typing');
} else if (event.type === 'end' && event.result && statusMsgId) {
const icon = event.result.success ? '✓' : '✗';
const detail = event.result.success
? `${event.result.output.split('\n').length} lines`
: (event.result.error ?? 'error');
try {
await ctx.api.editMessageText(
ctx.chat.id,
statusMsgId,
`${icon} ${event.tool}: ${detail}`,
);
} catch {
// Edit may fail if message was deleted; ignore
}
statusMsgId = undefined;
}
} catch {
// Don't let status display errors break the tool loop
}
});
try {
const response = await handleMessage(text);
// Clear tool use callback
config.agent.setOnToolUse(undefined);
// Telegram has a 4096 character limit per message
if (response.length <= 4096) {
await ctx.reply(response, { parse_mode: 'Markdown' });
@@ -111,6 +146,7 @@ export function createTelegramBot(config: TelegramBotConfig): Bot {
}
}
} catch (error) {
config.agent.setOnToolUse(undefined);
console.error('Error processing message:', error);
await ctx.reply('Sorry, an error occurred while processing your message.');
}