Skip to content

fix(phonic): Add preserveFunctionCallHistory flag to AgentTasks and use this function call history in Phonic plugin resets#1285

Open
qionghuang6 wants to merge 8 commits intolivekit:mainfrom
Phonic-Co:phonic/turn-history-tool-calls
Open

fix(phonic): Add preserveFunctionCallHistory flag to AgentTasks and use this function call history in Phonic plugin resets#1285
qionghuang6 wants to merge 8 commits intolivekit:mainfrom
Phonic-Co:phonic/turn-history-tool-calls

Conversation

@qionghuang6
Copy link
Copy Markdown
Contributor

@qionghuang6 qionghuang6 commented Apr 22, 2026

Description

We noticed that for Task Groups in typescript, the mergedChatCtx has excludeFunctionCall: true , which could cause the next agent to not realize a tool has already been called when transitioning between tasks. It seems that for the Python SDK, there is a preserve_function_call_history flag.

We would like to add it here and use it in our plugin as well.

buildTurnHistory previously only serialized text messages, dropping tool calls and their outputs from the system prompt sent on mid-session reset. This PR includes the tool calls and changes the format of the turn history to XML.

demo video:

https://screen.studio/share/58lb9tb4

Pre-Review Checklist

  • Build passes: All builds (lint, typecheck, tests) pass locally
  • AI-generated code reviewed: Removed unnecessary comments and ensured code quality
  • Changes explained: All changes are properly documented and justified above
  • Scope appropriate: All changes relate to the PR title, or explanations provided for why they're included
  • Video demo: A small video demo showing changes works as expected and did not break any existing functionality using Agent Playground (if applicable)

Testing

  • Automated tests added/updated (if applicable)
  • All tests pass
  • Make sure both restaurant_agent.ts and realtime_agent.ts work properly (for major changes)

Additional Notes


Note to reviewers: Please ensure the pre-review checklist is completed before starting your review.

buildTurnHistory previously only serialized text messages, dropping tool
calls and their outputs from the system prompt sent on mid-session reset.
Agents handed off mid-session lost access to any state that only existed
in tool return values.

Unify both history-building sites (pre-config postfix and reset) on a
shared chatItemToText helper emitting simple XML-ish tags. Tool outputs
are sliced to 16k chars to bound size.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

🦋 Changeset detected

Latest commit: 9947220

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@livekit/agents-plugin-phonic Patch
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@qionghuang6 qionghuang6 reopened this Apr 22, 2026
@qionghuang6 qionghuang6 changed the title fix(phonic): include tool calls and outputs in reset turn history fix(phonic): Add preserveFunctionCallHistory flag to AgentTasks and use this function call history in Phonic plugin resets Apr 22, 2026
@qionghuang6 qionghuang6 marked this pull request as ready for review April 22, 2026 22:43
Copy link
Copy Markdown
Contributor

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

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 4 additional findings.

Open in Devin Review

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