feat(telemetry): emit AgentConfigUpdate in OTLP session logs#1436
feat(telemetry): emit AgentConfigUpdate in OTLP session logs#1436toubatbrian wants to merge 1 commit into
Conversation
Ports livekit/agents#5601 from Python. Adds an AgentConfigUpdate chat item recording changes to the agent's instructions and tools. The initial agent configuration and subsequent updateTools calls insert an AgentConfigUpdate into both the agent's and the session's chat context, and the OTLP chat_history exporter serializes these items so config changes are visible alongside the surrounding conversation. Insertions are skipped when there is no visible diff.
🦋 Changeset detectedLatest commit: 6fb4cc2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
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 |
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6fb4cc21f2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case 'agent_config_update': { | ||
| // The remote session protocol does not yet support agent_config_update items; | ||
| // emit an empty wrapper so the wire format stays valid for older peers. | ||
| return new pb.ChatContext_ChatItem({}); |
There was a problem hiding this comment.
Drop unsupported config updates from remote history responses
When a session has an initial config update or updateTools() is called, handleGetChatHistory and handleGetAgentInfo map every history item through this helper, so remote clients receive a ChatContext_ChatItem whose item oneof is unset. Older peers do not know agent_config_update, but an empty chat item is still a malformed history entry for clients that switch on item.case; filter these items out of remote-session responses until the protobuf supports the new case.
Useful? React with 👍 / 👎.
Summary
Ports livekit/agents#5601 from
livekit/agents(Python) into agents-js.The Python PR makes
AgentConfigUpdateitems reach the OTLPchat_historyexporter so config changes (instructions / tool list) appear alongside the surrounding conversation in session logs, while skipping no-op updates.In agents-js,
AgentConfigUpdatewas not yet ported (existingTODO(parity)markers inchat_context.ts,agent_activity.ts:462, andagent_activity.ts:726), so this PR also lays the prerequisite foundation, then layers PR #5601's behavior on top.cc @toubatbrian @livekit/agent-devs
What changed
Foundation (prerequisite, not in #5601 itself but required to make it meaningful in JS):
agents/src/llm/chat_context.tsAgentConfigUpdateclass (id, optionalinstructions, optionaltoolsAdded/toolsRemoved,createdAt, in-memory_toolsToolContext that is intentionally not serialized).ChatItemunion now includesAgentConfigUpdate.ChatContext.copy()andChatContext.merge()gain anexcludeConfigUpdateoption (mirroring Python'sexclude_config_update).agents/src/llm/index.ts— re-exportsAgentConfigUpdate.agents/src/llm/provider_format/utils.ts— provider formatters skipagent_config_updateitems (same behavior asagent_handoff); they aren't serialized into the model input.agents/src/llm/utils.ts— chat-history pretty printer formatsagent_config_updateitems.agents/src/voice/remote_session.ts—chatItemToProtoreturns an emptyChatContext_ChatItemwrapper foragent_config_updatesince the remote-session protobuf does not yet have a corresponding case (keeps wire compat with peers that don't know the type).Equivalent of PR #5601:
agents/src/telemetry/traces.tsProtoAgentConfigUpdateshape andagentConfigUpdatefield onProtoChatItem.chatItemToProtoemits the new field foragent_config_updateitems so they appear in the OTLPchat_historylog records.agents/src/voice/agent_activity.tsTODO(parity)at line 462): records an initialAgentConfigUpdate(instructions + tool names) into bothagent._chatCtxandagentSession._chatCtx— skipped when there are no instructions and no tools.updateTools(replaces theTODOat line 726): computestoolsAdded/toolsRemovedagainst the previous tool set, inserts anAgentConfigUpdateinto both contexts, and skips when the diff is empty.agents/src/voice/agent_session.ts—_chatCtxswitched fromprivateto/** @internal */soAgentActivitycan insert into it (matches the existing pattern onAgent._chatCtx).Implementation nuances (where 1:1 parity wasn't possible)
agent_idfield: the Python construction sites passagent_id=self._agent.id, but the PythonAgentConfigUpdatePydantic model does not declare anagent_idfield — it is silently dropped. The JS port omitsagentIdaccordingly.update_instructionsinsertion: the Python PR also wiresself._session._chat_ctx.insert(config_update)insideupdate_instructions. agents-js does not currently have an equivalentupdateInstructionsmethod onAgentActivity(instructions are read offagent.instructionsand re-applied viaupdateInstructions(...)fromgeneration.ts— not a config-mutating user-facing API). Therefore only the initial-config andupdateToolsinsertion sites were ported. If/when anupdateInstructionsmethod is added toAgentActivity, the same dual-insertion should be wired there.agent_config_updatecase inchatItemToProtofor exhaustiveness. Returning an empty wrapper is the least-invasive option untilpb.AgentConfigUpdatelands in@livekit/protocol.get_fnc_tool_namesequivalent: Python computesget_fnc_tool_names(self.tools) or None(returns names of function-tools, excluding toolsets). agents-js'sToolContextis{ [name: string]: FunctionTool }, soObject.keys(this.tools)is the direct equivalent.Test plan
pnpm build:agents— clean build, no type errors.pnpm lint— no new errors (only pre-existing warnings unrelated to this change).pnpm test -- agents/src/llm/ agents/src/voice/agent_activity— all 284 tests pass.updateToolsand verifyagent_config_updateitems appear in the uploaded session report / OTLP chat history withtoolsAdded/toolsRemovedpopulated and that no-op calls are skipped.Generated by Claude Code