Skip to content

fix(workflows): return corrective instructions as tool output instead of generate_reply#6372

Open
u9g wants to merge 5 commits into
mainfrom
jason/workflows-return-tool-output
Open

fix(workflows): return corrective instructions as tool output instead of generate_reply#6372
u9g wants to merge 5 commits into
mainfrom
jason/workflows-return-tool-output

Conversation

@u9g

@u9g u9g commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What

The data-capture workflows' confirm_* tools (and credit_card's update_* validation branches) called session.generate_reply() from inside tool execution to voice corrective messages — scheduling a separate speech that competes with the turn's own tool_response reply and leaves nothing in the chat context. This PR returns the instruction as the tool's output instead, so it flows through the normal tool-response reply and merges with sibling tool outputs in the same turn.

on_enter hooks and the DTMF event handlers keep generate_reply — they run outside tool execution where there is no tool-output channel.

Testing

Adds a simulation harness (examples/data_capture_sim) — an intake agent exposing one collect_* tool per data-capture workflow (email, phone, address, DOB with time, name, credit card), all with require_confirmation=True so text-only simulations still exercise the confirm_* paths, plus an lk agent simulate scenarios file driving each corrective branch: value corrected at the confirmation step, time of birth before the date, and the card number length / repeat-mismatch / expired-date validations. Expectations grade the two regressions this refactor could introduce: going silent where generate_reply used to speak, and completing with a stale value.

The sim runs in CI (.github/workflows/data-capture-sim.yml) on any change to livekit-agents/livekit/agents/beta/workflows/** or the sim harness itself.

u9g added 3 commits July 9, 2026 10:51
… of generate_reply

The confirm_* tools (and credit_card's update_* validation branches) called
session.generate_reply() from inside tool execution to voice corrective
messages - scheduling a separate speech that competes with the turn's own
tool_response reply and leaves nothing in the chat context. Return the
instruction as the tool's output instead, so it flows through the normal
tool-response reply and merges with sibling tool outputs in the same turn.

on_enter hooks and the DTMF event handlers keep generate_reply - they run
outside tool execution where there is no tool-output channel.
An intake agent exposing one collect_* tool per data-capture workflow
(email, phone, address, DOB with time, name, credit card), all with
require_confirmation=True so text-only simulations still exercise the
confirm_* tool paths, plus an `lk agent simulate` scenarios.yaml driving
each corrective branch: value corrected at the confirmation step, time of
birth before the date, and the card number length / repeat-mismatch /
expired-date validations. Expectations grade the two regressions the
tool-output refactor could introduce: going silent where generate_reply
used to speak, and completing with a stale value.
@u9g u9g requested a review from a team as a code owner July 9, 2026 19:15
Comment thread examples/data_capture_sim/agent.py Fixed
Comment thread examples/data_capture_sim/agent.py Outdated
async def collect_date_of_birth(self, context: RunContext) -> str:
"""Collect the user's date of birth (and time of birth if they know it)."""
result = await beta.workflows.GetDOBTask(include_time=True, require_confirmation=True)
logger.info(f"captured dob: {result.date_of_birth} time: {result.time_of_birth}")

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

u9g and others added 2 commits July 9, 2026 16:08
…f sensitive information'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…f sensitive information'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants