can i make agent say a response and call a tool in...
# ask-ai
c
can i make agent say a response and call a tool in same response in livekit
✅ 1
t
Thanks for reaching out, Kushagra. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking whether an agent in LiveKit can both say a response and call a tool in the same response. Short answer: not as one atomic, simultaneous output — but yes, you can achieve the same user experience via sequential actions within a single turn. What you can do: • Have the agent generate speech and then immediately call a tool (ReAct pattern). Example: agent says “I’m checking that for you,” then invokes
lookup_order_status()
and follows up with another spoken result. • Trigger speech from inside the tool or while the tool runs using
context.session.say()
or
session.generate_reply()
, so the user hears immediate feedback while the tool executes. • Use pre-synthesized/cached TTS to play quick audio while longer tool calls run in the background to avoid latency. • Barge-in/interruption handling is supported so the flow stays natural if the user speaks during speech or tool execution. If you want, tell me which implementation you’re using (server-side tools via
@function_tool
, or in-tool TTS calls) and I’ll give a concise code pattern you can follow. Sources: The ReAct Pattern for Voice Agents and How AI Agents Think, Act, and Respon... | Function tool definition | LiveKit Documentation | The ReAct Pattern for Voice Agents and How AI Agents Think, Act, and Respon... | External data and RAG | LiveKit Documentation | Audio customization | LiveKit Documentation, with interactive elements
c
i only want to instruct it in prompt and do not want to use a generate_reply or say method. is it possible then
t
Thanks — you're asking if, by only instructing the model in the prompt (no `generate_reply`/`say`), the agent can both speak and invoke a tool in the exact same LLM output. Short answer: No — you cannot produce simultaneous speech and a tool call purely via a single prompt output. LiveKit requires the agent to perform those actions sequentially: the LLM can emit a spoken response and then trigger a tool, or trigger a tool and then emit follow-up speech. If you avoid `generate_reply`/`say`, you can still have the model request a tool call in its reasoning, but the system will execute the tool and any playback of TTS must be handled by session APIs (or by the tool itself emitting speech). Alternatives you can use without explicit per-line TTS calls: • Let the LLM in the prompt follow the ReAct pattern (produce a natural-language remark like “Checking that now” then request the tool). The platform will run the tool next and you can send the tool result back for a follow-up generation. • Have the tool itself produce speech output (the tool can trigger playback) so the user hears something while the turn continues. • Pre-synthesize TTS for likely utterances and play cached audio while the tool runs. If you tell me which flow you prefer (prompt-only ReAct style, tool-emitted speech, or pre-synthesized TTS), I’ll provide a concise example pattern you can use. , with interactive elements
c
so can the agent first say a message and then call the tool. if i only instruct it in prompt
t
You're asking if, using only prompt instructions (no `generate_reply`/`say`), the agent can first speak and then call a tool. Yes — but only as a sequential flow, not as a single atomic LLM output. What you can do: • Prompt the model using the ReAct pattern so it emits a short spoken message (e.g., "I'm checking that now") and then requests a tool call. • LiveKit will play the model's spoken text, then execute the requested tool; the tool result can be fed back for the model's follow-up reply. • You cannot have one single LLM generation both play speech and perform the tool call simultaneously. Speech playback and tool execution happen as separate steps. • If you need audible feedback while the tool runs without explicit session TTS calls, consider having the tool itself produce speech or using pre-synthesized/cached TTS. If you want, I can give a concise prompt example in ReAct style for this flow. Which option do you prefer? , with interactive elements
c
yes give an example. create a example agent with prompt to explain
t
Thanks — I updated the draft to clarify that speech playback and tool execution are handled sequentially by LiveKit (the model should follow ReAct-style prompt, but the platform orchestrates playing the sentence then running the tool). Below is the revised example and explanation. Tool definition (example)
Copy code
{
  "name": "lookup_order_status",
  "description": "Returns the order status for a given order_id",
  "parameters": {
    "type": "object",
    "properties": {
      "order_id": {
        "type": "string",
        "description": "Order identifier"
      }
    },
    "required": [
      "order_id"
    ]
  }
}
Prompt (ReAct-style) to give the model
Copy code
System: You are a helpful agent. Follow the ReAct pattern: when you need external data, first produce a short user-facing message (one sentence) indicating what you're doing, then emit a tool call in JSON exactly matching the tool schema. Do not call any SDK methods yourself.

User: My order 12345 seems delayed. Can you check it?

Assistant (expected format):
1) A single short sentence for the user (what you will say aloud), e.g. "I'm checking your order status now."
2) A JSON tool invocation on the next line matching the tool schema.

Example response:
"I'm checking your order status now."
{"tool": "lookup_order_status", "arguments": {"order_id": "12345"}}
How LiveKit will handle this (sequential orchestration) • The model should emit the short sentence followed by the JSON tool invocation (ReAct style). • LiveKit will play the sentence as speech first, then parse the JSON and execute the tool. • After the tool returns, LiveKit appends the tool result to the conversation and the model generates the follow-up reply (which will be played as speech). • This achieves the user experience of “agent speaks, then tool runs, then agent reports back,” but speech playback and tool execution are performed sequentially by the platform rather than as one atomic simultaneous LLM action. If you want, I can adapt this prompt for multiple tools or produce a Node/Python runtime snippet showing how to parse the model output and orchestrate playback → tool call → follow-up. Which would you prefer? , with interactive elements