Skip to content

plugins/phonic: preserve tool calls and outputs across mid-session reset - #6702

Draft
arunwpm-work wants to merge 1 commit into
livekit:mainfrom
Phonic-Co:arun/phonic-preserve-tool-outputs
Draft

plugins/phonic: preserve tool calls and outputs across mid-session reset#6702
arunwpm-work wants to merge 1 commit into
livekit:mainfrom
Phonic-Co:arun/phonic-preserve-tool-outputs

Conversation

@arunwpm-work

Copy link
Copy Markdown
Contributor

What

When the Phonic realtime session is reset mid-session (e.g. an agent handoff), the plugin rebuilds the conversation history from the agent chat context via _build_turn_history. Two changes:

  1. Render the history with tool calls and outputs as XML tags (<tool_call> / <tool_output>), matching the JS plugin — previously the Python renderer was text-only and dropped tool calls and outputs entirely.
  2. Remember the tool outputs the plugin observes and re-inject them (right after their call), skipping any output the chat context already carries.

Why

onToolExecutionCompleted in the realtime generation path commits the function_call to the agent chat context but not the function_call_output (that only happens on the interrupted path). Providers whose server keeps its own context across the session are unaffected, but Phonic rebuilds the server context from the agent chat context on reset — so the un-persisted output was lost, leaving the model with a tool call and no result after a handoff.

Notes

  • Item (1) is a behavior change: the reset history now includes tool calls/outputs (XML tags) rather than plain role: text. This brings the Python plugin to parity with the JS plugin.
  • Re-injection dedupes against outputs already present, so it's a no-op if the framework ever starts persisting them.

Render the continued-conversation history with tool calls and their outputs (XML tags,
matching the JS plugin) instead of text-only. livekit core commits realtime function_call
items to the agent chat context but not their function_call_output, so remember observed
outputs and re-inject them (right after their call) in _build_turn_history; skip when the
ctx already carries the output.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.

1 participant