This project demonstrates how to call an API using a tool_call
in Tavus. It uses the Daily.co SDK and a third-party API (Pokemon API) to fetch dynamic Pokémon data in real time.
If you're looking for a more in-depth explaination of how this project works and how to set everything up, click here to read my blog!
Start by forking the ready-to-use Pokemon Demo and explore Tavus CVI's real-time video interactions. Whether you need the classic Persona or a customized version, the demo provides all the building blocks to get started.
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
When a user asks a question like:
“Tell me something about Charmander!”
The app triggers a tool_call
event via the Tavus LLM pipeline. That event is handled in real time by the app using the Daily API. Based on the tool name (get_pokemon_fact
) and arguments (e.g., "pokemon_name": "charmander"
), the app makes a request to the PokéAPI to fetch:
- The Pokémon's types
- Their abilities
- Their height and weight (converted into feet/inches and pounds)
A random fact is selected and then echoed back to the user through the conversation.echo
event — displayed inside the video chat session, as if it were a natural response.
-
User Prompt → Tool Call
- The user says something that triggers a tool call:
conversation.tool_call
. - Tavus sends an
app-message
to the app with the tool name and arguments.
- The user says something that triggers a tool call:
-
Handle Tool Call
- The app listens for
app-message
events. - If the tool call is
get_pokemon_fact
, it extracts thepokemon_name
, calls the PokéAPI, and randomly selects a fact.
- The app listens for
-
Send Back Response
- The selected fact is sent back using
conversation.echo
.
- The selected fact is sent back using
- React
- TypeScript
- Vite
- Tailwind CSS
- Framer Motion
{
"message_type": "conversation",
"event_type": "conversation.tool_call",
"properties": {
"name": "get_pokemon_fact",
"arguments": "{\"pokemon_name\":\"eevee\"}"
}
}
{
"message_type": "conversation",
"event_type": "conversation.echo",
"properties": {
"modality": "text",
"text": "This Pokémon has the following abilities: run-away, adaptability, anticipation"
}
}
You can easily update the persona that powers your Tavus conversation.
Open the createConversation.ts
file and update the persona_id
and replica_id
fields to match your custom setup.
body: JSON.stringify({
// 🧠 Replace with your custom Persona and Replica IDs
persona_id: "p1234567", // e.g., Pokémon Trainer Persona ID from Tavus
replica_id: "r89abcd123", // Linked voice replica for the persona
conversation_name: "A Chat with Your Pokémon Guide", // Optional: Name your session
conversational_context: "You're speaking to a seasoned Pokémon Trainer who loves sharing fun facts and lore.", // Helps set tone and context
custom_greeting: "Welcome, Trainer! Ready to explore the world of Pokémon?", // First thing users will hear
properties: {
language: "english",
},
});
- Create a
PATCH
request in Postman - In the
PATCH
URL, usehttps://tavusapi.com/v2/personas/PERSONA_ID_HERE
- In the Headers tab, use:
- x-api-key: YOUR_TAVUS_API_KEY
- Content-Type: application/json
- In the Raw -> Body tab, paste this:
[
{
"op": "replace",
"path": "/layers/llm/tools",
"value": [
{
"type": "function",
"function": {
"name": "get_pokemon_fact",
"description": "Get abilities of a given Pokémon",
"parameters": {
"type": "object",
"properties": {
"pokemon_name": {
"type": "string",
"description": "Name of the Pokémon, e.g., Pikachu"
}
},
"required": ["pokemon_name"]
}
}
}
]
}
]
- Click the
SEND
to send the request.
You can confirm in Postman if your Persona is updated by making a GET
request to https://tavusapi.com/v2/personas/PERSONA_ID_HERE
and checking the body.