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: 7 additions & 2 deletions livekit-agents/livekit/agents/llm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,21 @@ async def execute_function_call(
function_tool = tool_ctx.function_tools.get(tool_call.name)
if function_tool is None:
logger.warning(f"unknown AI function `{tool_call.name}`")
# Name the available tools so the model can self-correct
msg = (
f"Unknown function: {tool_call.name} - available tools: "
f"{', '.join(tool_ctx.function_tools.keys())}"
)
return FunctionCallResult(
fnc_call=fnc_call,
fnc_call_out=FunctionCallOutput(
name=tool_call.name,
call_id=tool_call.call_id,
output=f"Unknown function: {tool_call.name}",
output=msg,
is_error=True,
),
raw_output=None,
raw_exception=ValueError(f"Unknown function: {tool_call.name}"),
raw_exception=ValueError(msg),
)

try:
Expand Down
6 changes: 5 additions & 1 deletion livekit-agents/livekit/agents/voice/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,11 @@ def _tool_completed(out: ToolExecutionOutput) -> None:
make_tool_output(
fnc_call=fnc_call,
output=None,
exception=ToolError(f"Unknown function: {fnc_call.name}"),
# Name the available tools so the model can self-correct
exception=ToolError(
f"Unknown function: {fnc_call.name} - available tools: "
f"{', '.join(tool_ctx.function_tools.keys())}"
),
)
)
continue
Expand Down
Loading