How to clear a conversation without disconnecting ...
# ask-ai
a
How to clear a conversation without disconnecting all the agent and restart the connection
t
Thanks for reaching out, pui. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Regarding clearing a conversation without disconnecting agents: you can reset the agent's chat context while keeping its connection active. Options: • Python
Copy code
from livekit.agents import ChatContext

new_context = ChatContext()
await agent.update_chat_ctx(new_context)
• TypeScript
Copy code
import { llm } from '@livekit/agents';

const newContext = llm.ChatContext.empty();
await agent.updateChatCtx(newContext);
This clears prior messages, tool calls, and context while the agent remains connected and ready for new input. Would you like an example that preserves certain system messages or user metadata when clearing the rest of the conversation? Sources: Pipeline nodes and hooks | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docs
a
how do i get the agent ? if i am using session = AgentSession( llm=openai.realtime.RealtimeModel(voice="sage"), )
t
You're on the right track —
AgentSession
doesn't create the Agent for you. To get an agent when using your session, instantiate an Agent and pass it into
session.start()
. After start, the agent is available as
session.agent
. Example (Python):
Copy code
from livekit.agents import Agent, AgentSession
from livekit.plugins import openai

class MyAgent(Agent):
    def __init__(self):
        super().__init__(instructions="You are a helpful assistant.")

agent = MyAgent()

session = AgentSession(
    llm=openai.realtime.RealtimeModel(voice="sage"),
)

# start the session with your agent
await session.start(room=ctx.room, agent=agent)

# access the agent
current_agent = session.agent
print(current_agent.instructions)
Would you like an example that adds custom state or shows how to call
agent.update_chat_ctx()
to clear conversation context while keeping the connection? Sources: Agent session | LiveKit docs | Agents and handoffs | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs
a
AttributeError: 'AgentSession' object has no attribute 'agent' await session.start(agent=LocalAgent(), room=ctx.room)
t
You're seeing that AttributeError because
session.agent
becomes available only after
await session.start(...)
completes and the session is fully started. Quick checklist and example to fix this: 1. Ensure you await start before accessing
session.agent
. 2. Keep a reference to the agent you pass in (simpler and reliable). 3. Optionally listen for the session's agent-state event to know when it's ready. Example (Python):
Copy code
agent = LocalAgent()                      # create agent instance
session = AgentSession(llm=...)           # your session
await session.start(agent=agent, room=ctx.room)   # wait for start to finish

# now safe to access
current_agent = session.agent
# or use the original reference
current_agent = agent
If you still get the error after awaiting
start
, tell me: • the exact SDK version you're using, and • whether you call
session.agent
before or after
await session.start(...)
. Sources: Agent session | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs
a
how to stop the ai output voice after we temporary hide the session from user, and when continueing back with reseting the chat context, it will first still output all the voice message that is not finished on the last conversation before
t
You're seeing unfinished voice resume because the TTS/playback was not interrupted before hiding. To stop AI voice output and prevent resumed playback when you return, do the following: 1. Interrupt ongoing speech immediately before hiding:
Copy code
await session.interrupt()
# or if you have a SpeechHandle:
handle.interrupt()
1. Disable automatic resumption of interrupted speech when creating the session:
Copy code
session = AgentSession(
  llm=...,
  resume_false_interruption=False,
)
1. Clear the conversation context after interrupting so no pending messages continue:
Copy code
from livekit.agents import ChatContext
await agent.update_chat_ctx(ChatContext())
1. (Optional) Stop listening/receiving audio while hidden:
Copy code
await session.input.set_audio_enabled(False)
Sequence to use when hiding: 1.
await session.interrupt()
2.
await agent.update_chat_ctx(ChatContext())
3.
await session.input.set_audio_enabled(False)
(if you want to pause input) When resuming, re-enable audio and continue; the cleared chat context prevents unfinished messages from replaying. Do you want a concrete example showing this full hide/resume flow in your current code? Sources: Agent speech and audio | LiveKit docs | Turn detection and interruptions | LiveKit Docs | Agents v0.x migration guide - Python | LiveKit docs | Text and transcriptions | LiveKit docs
a
what is the maximum limit for simli avatar ? can i just let it keep on running to avoid starting connection again which have the delay avatar = simli.AvatarSession( simli_config=simli.SimliConfig( api_key=os.environ.get("SIMLI_API_KEY"), face_id=os.environ.get("SIMLI_FACE_ID"), max_idle_time=900, max_session_length=3600, ), )
t
You're asking about max limits for a Simli avatar session and whether you can keep it running indefinitely to avoid reconnect delay. Short answer: • The exact maximum values for
max_idle_time
and
max_session_length
are not specified in the LiveKit/Simli integration docs. • Those two parameters are configurable on your side and control when the session will be considered idle or reach its total allowed duration. • Continuously keeping an avatar session running to avoid reconnection delays is not the intended pattern — the Simli plugin is designed to start on demand and stop when finished. Running sessions indefinitely may hit service-side timeouts or incur unnecessary resource/cost overhead. What you can do now: • Keep your current configuration and experiment with larger values (e.g., increase
max_idle_time
from 900 and
max_session_length
from 3600) to see if it meets your latency needs. • When hiding the session, make sure you properly interrupt and stop the avatar to avoid leftover audio or state (you already use
avatar.start(...)
/
avatar.stop()
patterns). • If you need guaranteed always-on behavior for production low-latency, check Simli’s official docs or ask Simli for service limits and recommended patterns. Would you like a suggested configuration to test (example values and hide/resume sequence) based on your current numbers? Sources: Simli virtual avatar integration guide | LiveKit docs
a
I am using the avatar with the playground, and i notice there are sometimes, the captions is already generated 1 to 2 second of message and then the avatar only starts speaking what is the problem ?
t
You're seeing captions before the avatar speaks because text is ready before the avatar's audio+video pipeline finishes preparing playable frames. Causes and what you can do: Causes • TTS buffering: text is sent to TTS first; audio must be generated/streamed before playback. • Avatar synthesis: Simli needs extra time to produce the first video frames (lip-synced animation). • Sync behavior: captions are emitted as soon as text exists; playback waits for audio+video to be ready to keep lip-sync. Mitigations to reduce the gap • Use a low-latency streaming TTS provider (e.g., providers that support streaming audio) so audio becomes available faster. • Enable aligned transcripts: set
use_tts_aligned_transcript=True
in your
AgentSession
to better sync captions with TTS timing. • Shorten initial responses so the avatar can start rendering sooner. • Pre-warm/start the avatar session slightly before user-visible output (start the session or request a short silent TTS) to reduce first-frame latency. • Test outside the Playground UI (the playground can add extra rendering delays). If you want, I can show how to enable
use_tts_aligned_transcript
in your session code or suggest TTS provider configs to try. Which would you prefer? Sources: Simli virtual avatar integration guide | LiveKit docs | Bringing AI avatars to voice agents | Text and transcriptions | LiveKit docs
a
i am currently using chatgpt realtime ai model so it should not have tts right ?
t
You're correct that the ChatGPT Realtime model can produce audio directly (it's not "just text" TTS), but the avatar pipeline still introduces TTS/audio+video processing steps that can cause captions to appear before you hear/see speech. Here's why and what to do. Why captions can still appear first • The model emits text (captions) as soon as the response is generated. • The avatar service needs the audio (or audio stream) to generate lip‑synced video frames; producing/streaming that audio and synthesizing the first frames adds 1–2s of latency. • The system waits for playable audio+video so lip sync is accurate, which is why captions (text) can show earlier than the avatar starts speaking. What you can do to reduce the gap • Use low‑latency streaming audio if available from your model/provider so audio is available sooner. • Enable aligned transcripts if supported (
use_tts_aligned_transcript=True
) to better sync captions with audio timing. • Keep responses short or split long responses into smaller chunks. • Pre‑warm the avatar (start the session or request a tiny silent audio chunk) before showing UI output. • Test outside the Playground UI to rule out UI rendering delays. Would you like a short code example to enable aligned transcripts or to pre‑warm the avatar in your current setup?