Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions livekit-agents/livekit/agents/telemetry/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ def _to_proto_chat_item(item: ChatItem) -> dict: # agent_pb.agent_session.ChatC
ah.new_agent_id = item.new_agent_id
ah.created_at.FromMilliseconds(int(item.created_at * 1000))

elif item.type == "agent_config_update":
acu = item_pb.agent_config_update
acu.id = item.id
if item.instructions is not None:
acu.instructions = item.instructions
acu.tools_added[:] = item.tools_added or []
acu.tools_removed[:] = item.tools_removed or []
acu.created_at.FromMilliseconds(int(item.created_at * 1000))

return MessageToDict(item_pb, preserving_proto_field_name=True)


Expand Down
39 changes: 22 additions & 17 deletions livekit-agents/livekit/agents/voice/agent_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ async def update_instructions(self, instructions: str) -> None:
agent_id=self._agent.id,
)
self._agent._chat_ctx.insert(config_update)
self._session._chat_ctx.insert(config_update)

if self._rt_session is not None:
await self._rt_session.update_instructions(instructions)
Expand All @@ -407,15 +408,16 @@ async def update_tools(self, tools: list[llm.Tool | llm.Toolset]) -> None:
tools = list({tool.id: tool for tool in tools}.values())
self._agent._tools = tools

# Record the configuration change
config_update = llm.AgentConfigUpdate(
tools_added=tools_added,
tools_removed=tools_removed,
agent_id=self._agent.id,
)
# Store full tool definitions in-memory (not serialized)
config_update._tools = llm.ToolContext(tools).flatten()
self._agent._chat_ctx.insert(config_update)
# Record the configuration change (skip if no visible diff)
if tools_added or tools_removed:
config_update = llm.AgentConfigUpdate(
tools_added=tools_added,
tools_removed=tools_removed,
agent_id=self._agent.id,
)
config_update._tools = llm.ToolContext(tools).flatten()
self._agent._chat_ctx.insert(config_update)
self._session._chat_ctx.insert(config_update)

if self._rt_session is not None:
await self._rt_session.update_tools(llm.ToolContext(self.tools).flatten())
Expand Down Expand Up @@ -766,14 +768,17 @@ async def _setup_toolset(toolset: llm.Toolset) -> None:
except ValueError:
logger.exception("failed to update the instructions")

# Record initial agent configuration
initial_config = llm.AgentConfigUpdate(
instructions=self._agent.instructions,
tools_added=get_fnc_tool_names(self.tools) or None,
agent_id=self._agent.id,
)
initial_config._tools = llm.ToolContext(self.tools).flatten()
self._agent._chat_ctx.insert(initial_config)
# Record initial agent configuration (skip if empty)
initial_tools = get_fnc_tool_names(self.tools) or None
if self._agent.instructions or initial_tools:
initial_config = llm.AgentConfigUpdate(
instructions=self._agent.instructions,
tools_added=initial_tools,
agent_id=self._agent.id,
)
initial_config._tools = llm.ToolContext(self.tools).flatten()
self._agent._chat_ctx.insert(initial_config)
self._session._chat_ctx.insert(initial_config)

await self._resume_scheduling_task()
self._audio_recognition = AudioRecognition(
Expand Down
Loading