witty-kangaroo-6889
07/22/2025, 6:04 AMtall-airline-16756
07/22/2025, 6:04 AMtall-airline-16756
07/22/2025, 6:05 AMjson.dumps() to serialize the response. If the response is a simple type (str, int, float, bool), it is converted to a string directly.
• *Example Tool:*`@llm.ai_callable()
async def get_weather(self, location: str):
# ... fetch weather data ...
return {"weather": "sunny", "temperature_f": 70}`
• LLM Consumption: The LLM receives the JSON string and can use it in its reply to the user.
Common Errors and Solutions:
• JSON Parsing Errors: Ensure the tool returns serializable data. If the tool returns a non-serializable object, use json.dumps() or convert it to a string.
• Tool Execution Errors: Handle exceptions within the tool and return error messages as strings if needed.
• Response Format Issues: Always return a dictionary, list, or string. Avoid returning custom objects unless they are serializable.
By following these practices, the LLM will be able to invoke your function tool, receive the JSON response, and use it in user interactions without errors.
Sources: Tool definition and use | LiveKit Docs | Function calling with Voice Agents | LiveKit Docs | mcp_client/util.py | common/chat.cppwitty-kangaroo-6889
07/22/2025, 6:08 AMtall-airline-16756
07/22/2025, 6:09 AMYou've got this awesome tool that gives you a JSON response. When it comes in, your job is to take those details and turn them into a friendly, easy-to-understand message for the user. Like if the tool tells you {"weather": "sunny", "temperature_f": 70}, you'd say: "Great news! It's a beautiful sunny day with a perfect 70°F temperature."
Just remember: be specific about the JSON structure, give a clear example, and show the LLM how to make those tool responses feel personal and helpful.
Sources: models/templates/NousResearch-Hermes-3-Llama-3.1-8B-tool_use.jinja | Tool definition and use | LiveKit Docs