clean-dinner-53786
08/26/2025, 2:14 PMtall-airline-16756
08/26/2025, 2:14 PMtall-airline-16756
08/26/2025, 2:15 PMmake_tool_output function. It’s designed to take the raw output from a function and wrap it up into a ToolExecutionOutput object. This object includes the function call itself, the output or any exceptions that popped up, plus some extra metadata to help with processing.
Here’s a quick rundown of what make_tool_output does:
• It gracefully handles any exceptions during the function execution and formats them nicely.
• It checks that the output type is valid—like strings, numbers, booleans, lists, or dictionaries.
• If your output includes Agent instances, it knows how to process those too, letting you return one agent task along with other valid outputs.
• It converts the function output into a string so it fits perfectly into the FunctionCallOutput.
And if you’re working with the JavaScript SDK, there’s a handy method called ChatMessage.createToolFromFunctionResult. This lets you create a ChatMessage directly from your function’s result, turning that output into a tool message that works great in chat contexts.
Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | ChatMessage | LiveKit Agentsclean-dinner-53786
08/26/2025, 2:15 PMtall-airline-16756
08/26/2025, 2:16 PMmake_tool_output to turn a function call’s output into a ToolExecutionOutput object:
from livekit.agents.llm import FunctionCall
from livekit.agents.voice.generation import make_tool_output
# Example function call from an LLM
fnc_call = FunctionCall(
id="call_12345",
call_id="tool_call_abc",
name="lookup_weather",
arguments='{"location": "San Francisco"}'
)
# Simulated function output
function_result = "It is currently 65°F and sunny in San Francisco."
# Create ToolExecutionOutput using make_tool_output
tool_output = make_tool_output(
fnc_call=fnc_call,
output=function_result,
exception=None
)
# The resulting tool_output contains:
# - fnc_call: The original function call
# - fnc_call_out: FunctionCallOutput with output string and success status
# - raw_output: The original result
# - raw_exception: None (no error)
# - agent_task: None (no agent handoff)
# - reply_required: True (since output is non-empty)
print(f"Tool output: {tool_output.fnc_call_out.output}")
print(f"Error status: {tool_output.fnc_call_out.is_error}")
This example walks you through handling a function call, processing its output, and wrapping it up nicely in a ToolExecutionOutput object. If you want me to go over anything in more detail or need another example, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/run_result.pyclean-dinner-53786
08/26/2025, 2:19 PMtall-airline-16756
08/26/2025, 2:19 PMmake_tool_output with the agent lifecycle in LiveKit, the framework takes care of it all behind the scenes. Whenever a tool call pops up in the LLM output, the framework smoothly handles it during the tool execution phase. This is where make_tool_output wraps up the results — including the function call details, the outcome, and any exceptions.
As a developer, you won’t need to yield make_tool_output directly from the llm_node. Instead, you just focus on defining your tool functions, and the framework handles running them and managing the output. If you want to tweak how your agent behaves, you can always override the llm_node method in your custom Agent subclass. This lets you adjust the chat context or add your own logic before or after the usual LLM processing.
Feel free to ask if you'd like me to walk you through any examples or clarify how to customize the `llm_node`—I’m here to help!
Sources: pipeline-llm/replacing_llm_output.py | Pipeline nodes and hooks | LiveKit Docs | Voice pipeline nodes | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...