Case Study: End the Call Intelligently
The following steps build on the LLM client class from the Integrate LLM guide.1
Define the function
Note: for OpenAI, the model will either give a tool call or a text response — not both. The
message parameter lets the LLM say something before ending the call.Node.js
2
Add function calling to the chat request
Node.js
3
Extract function call arguments from the streaming response
Node.js
4
End the call when the LLM triggers the function
Node.js
Case Study: Make an Appointment
End call is the simplest function calling use case. In most cases, you’ll want your agent to say something while calling the function and say something after it returns.This is not production-ready as-is. In production, you need to handle duplicate function calls, user interruptions, and more complex state management. A good practice is to maintain internal states to track what function to run and how it influences LLM responses.