Within the stt->llm->tts pipeline agent-sess...
# ask-ai
m
Within the stt->llm->tts pipeline agent-session. can I ask the llm and get string output? programatically
t
Thanks for reaching out, Rajadurai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether, inside an AgentSession running the stt → llm → tts pipeline, you can programmatically call the LLM and get back a string. Yes — you can. Use the session's generate_reply / generateReply method to invoke the LLM directly and collect the streamed text output as a string. This works independently of STT/TTS (so you don't need audio in/out) and runs in the same session context (chat history, agent state). Short examples: • Python
Copy code
response_text = ""
handle = session.generate_reply(user_input="What is the capital of France?")
async for chunk in handle.text_stream:
    response_text += chunk
print(response_text)
• Node.js
Copy code
const handle = session.generateReply({ userInput: "What is the capital of France?" });
let response = "";
for await (const chunk of handle.textStream()) {
  response += chunk;
}
console.log(response);
If you want finer control over LLM inputs/outputs (tool use, custom prompts, or different streaming behavior), you can override
llm_node()
in your Agent subclass. Would you like an example that fits your language (Python/Node) or a sample Agent override? Sources: Tool definition and use | LiveKit docs | External data and RAG | LiveKit Docs | Agent session | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs | Pipeline nodes and hooks | LiveKit docs
m
AttributeError: 'SpeechHandle' object has no attribute 'text_stream
t
You're seeing that AttributeError because
SpeechHandle
controls audio playout and does not expose a text stream. To get the LLM's string output programmatically, use one of these options. Which language are you using (Python or Node)? Pick one and I’ll give the exact snippet for your environment. Options: • Capture the final LLM text from the session events (recommended if you're inside AgentSession). ◦ Listen for
conversation_item_added
and read
event.item.text_content
when role == "agent" — that contains the LLM/TTS input text. • Intercept the LLM stream by overriding
llm_node
in your Agent subclass (recommended if you want raw streaming chunks before TTS). ◦ In your override, iterate the default
llm_node
output, collect
chunk.delta.content
(or the string chunks), then yield them. • Skip the agent pipeline and call the LLM directly (if you only need strings, not TTS/STT). ◦ Use the LLM chat API to stream and concatenate
chunk.delta.content
into a final string. Tell me your language and whether you want streaming or just the final string and I’ll post the specific code. Sources: Agent speech and audio | LiveKit docs | Sending text | LiveKit docs | Text and transcriptions | LiveKit docs | Pipeline nodes and hooks | LiveKit docs