← Back to PRs

#19439: fix(tts): pass audioAsVoice flag through tool result pipeline

by brandonwise open 2026-02-17 20:08 View on GitHub →
agents size: S trusted-contributor
Fixes #14174 ## What The built-in `tts` agent tool now correctly delivers voice messages on Telegram by passing the `audioAsVoice` flag through the tool result pipeline. ## Why The TTS tool was returning `[[audio_as_voice]]` tags in text content, but this flag was being dropped when passing through `onToolResult` callbacks. This caused voice messages to be sent as regular audio file attachments instead of voice bubbles. The parsing in `parseReplyDirectives` / `splitMediaFromOutput` was working correctly to extract the flag, but `emitToolOutput` and the downstream pipeline weren't passing it through. ## How - Added `audioAsVoice?: boolean` to the `onToolResult` callback payload type in `pi-embedded-subscribe.types.ts` - Updated `emitToolOutput` and `emitToolSummary` to pass `audioAsVoice` from `parseReplyDirectives` - Added `extractToolResultAudioAsVoice()` helper to extract the flag for the direct media delivery path (when `shouldEmitToolOutput` is false) - Passes `audioAsVoice` through `agent-runner-execution.ts` to the final delivery ## Testing - [x] Added unit tests for `extractToolResultAudioAsVoice()` - [x] Existing tests pass (`pnpm vitest run`) - [x] `pnpm build` passes ## AI-Assisted 🤖 This PR was built with AI assistance (Claude via OpenClaw). - [x] Code reviewed and understood - [x] Matches existing patterns in the codebase <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR fixes a bug where the `tts` agent tool was delivering voice messages as regular audio file attachments on Telegram instead of voice bubbles. The `[[audio_as_voice]]` flag was being emitted by the TTS tool but dropped when passing through the `onToolResult` callback pipeline. Key changes: - Added `audioAsVoice?: boolean` to `onToolResult` callback payload types in `pi-embedded-subscribe.types.ts` and `pi-embedded-runner/run/params.ts` - Added `extractToolResultAudioAsVoice()` in `pi-embedded-subscribe.tools.ts` to extract the flag for the direct media delivery path (when `shouldEmitToolOutput` is false) - Updated `emitToolSummary` and `emitToolOutput` in `pi-embedded-subscribe.ts` to pass `audioAsVoice` from `parseReplyDirectives` - Propagated `payload.audioAsVoice` through `agent-runner-execution.ts` to the outer `onToolResult` handler - Added unit tests covering edge cases for `extractToolResultAudioAsVoice()` The fix correctly threads the flag through both delivery paths (verbose tool output and direct media delivery). The implementation follows the same patterns used elsewhere in the codebase for `audioAsVoice` propagation. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge - it fixes a clear bug with a minimal, well-scoped change that follows existing codebase patterns. - The changes are small and targeted, threading a single boolean flag through the tool result pipeline. The new `extractToolResultAudioAsVoice()` helper mirrors the existing `extractToolResultMediaPaths()` pattern exactly. Both delivery paths (verbose/emitToolOutput and direct media delivery) are handled. Unit tests cover null/undefined, non-object, missing content, and the TTS format. No pre-existing behavior is altered, and the type changes are backward compatible (optional field added). - No files require special attention <sub>Last reviewed commit: 8979a3b</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs