Skip to content
Merged
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
12 changes: 12 additions & 0 deletions livekit-agents/livekit/agents/llm/chat_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def copy(
exclude_instructions: bool = False,
exclude_empty_message: bool = False,
exclude_handoff: bool = False,
exclude_config_update: bool = False,
tools: NotGivenOr[Sequence[Tool | Toolset | str]] = NOT_GIVEN,
) -> ChatContext:
items = []
Expand Down Expand Up @@ -343,6 +344,9 @@ def get_tool_names(
if exclude_handoff and item.type == "agent_handoff":
continue

if exclude_config_update and item.type == "agent_config_update":
continue

if (
is_given(tools)
and (item.type == "function_call" or item.type == "function_call_output")
Expand Down Expand Up @@ -389,6 +393,7 @@ def merge(
*,
exclude_function_call: bool = False,
exclude_instructions: bool = False,
exclude_config_update: bool = False,
) -> ChatContext:
"""Add messages from `other_chat_ctx` into this one, avoiding duplicates, and keep items sorted by created_at."""
existing_ids = {item.id for item in self._items}
Expand All @@ -407,6 +412,9 @@ def merge(
):
continue

if exclude_config_update and item.type == "agent_config_update":
continue

if item.id not in existing_ids:
idx = self.find_insertion_index(created_at=item.created_at)
self._items.insert(idx, item)
Expand All @@ -422,6 +430,7 @@ def to_dict(
exclude_timestamp: bool = True,
exclude_function_call: bool = False,
exclude_metrics: bool = False,
exclude_config_update: bool = False,
) -> dict[str, Any]:
items: list[ChatItem] = []
for item in self.items:
Expand All @@ -431,6 +440,9 @@ def to_dict(
]:
continue

if exclude_config_update and item.type == "agent_config_update":
continue

if item.type == "message":
item = item.model_copy()
if exclude_image:
Expand Down
Loading