how to check if agent is triggering a function too...
# ask-ai
a
how to check if agent is triggering a function tool
t
Thanks for reaching out, Harshita. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking how to check whether an agent actually triggers a function tool. I’ll walk you through the practical ways to verify that during tests and what to look for. Short answer: use the testing utilities on the agent session to assert a function call occurred, then inspect the function call event and its output. How to check (step-by-step) 1. Run the agent session for the user input that should trigger the tool. ◦ Example: call your
AgentSession
or whatever test harness you use with the relevant prompt (e.g., "Book an appointment for tomorrow"). 1. Assert the next event is a function call. ◦ Use the test helper
expect.next_event().is_function_call()
to confirm the agent made a function/tool call and to check the function name and arguments. ◦ Example:
Copy code
result = await sess.run(user_input="Book an appointment for tomorrow")
     await result.expect.next_event().is_function_call(
       name="book_appointment",
       arguments={"date": "tomorrow"}
     )
1. Verify the function call output. ◦ After confirming the call, verify the tool’s response using
is_function_call_output()
to ensure the tool returned the expected result. ◦ Example:
Copy code
await result.expect.next_event().is_function_call_output(
       output="Appointment confirmed for tomorrow"
     )
1. Inspect the event sequence if you need more detail. ◦ The
RunResult
contains the ordered events (messages, function calls, outputs). Walk through these events if you need to confirm where and when the tool was invoked or to debug mismatches. 1. (Optional) Use qualitative judgment if you want behavior assessment. ◦ You can run
.judge()
on results to get a qualitative assessment of whether the agent’s actions matched intent after tool usage. Notes and tips • Make sure the LLM model/plugin you’re testing with supports the testing flow (e.g., compatible LLM plugin or RealtimeModel in text mode) for reliable results. • If the assertion fails, inspect the event list to see what happened instead (e.g., a plain message from the agent rather than a function call or different arguments). • If you have multiple possible implementations (e.g., sync vs async tool invocation), tell me which one you’re using and I’ll show the precise test snippet for that case. If you'd like, share: • The test harness you use (Python pytest, Vitest/Node, or something else) • The function/tool name and expected arguments I can then provide an exact test snippet tailored to your setup. Sources: Using the Testing Framework with Realtime Models | LiveKit | Testing and evaluation | LiveKit Documentation