How can I check if the LLM returned any speech alo...
# ask-ai
w
How can I check if the LLM returned any speech along with its tool call?
t
Thanks for reaching out, Alex. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to check whether the LLM returned speech along with its tool call, you can keep an eye on the conversation item added events and function tools executed events that the session emits: • Speech Messages: When the LLM generates speech, it creates a
ChatMessage
with the role "assistant". This message comes through as a
ConversationItemAddedEvent
containing the speech content. • Tool Calls: Tool calls from the LLM show up as
FunctionCall
and
FunctionCallOutput
events, which are emitted as
FunctionToolsExecutedEvent
. Here’s a simple example to help you capture these events:
Copy code
conversation_events = []
tool_executed_events = []

session.on("conversation_item_added", lambda ev: conversation_events.append(ev))
session.on("function_tools_executed", lambda ev: tool_executed_events.append(ev))

# After processing...

# Check speech messages
for event in conversation_events:
    if event.item.role == "assistant":
        print("LLM Speech:", event.item.text_content)

# Check tool calls and outputs
for event in tool_executed_events:
    for fnc_call in event.function_calls:
        print("Tool Call:", fnc_call.name)
    for fnc_output in event.function_call_outputs:
        print("Tool Output:", fnc_output)
Hopefully, this makes it easier for you to verify both the speech responses and the tool executions from the LLM. If you have any questions or need a hand, just let me know!