average-architect-28889
07/25/2025, 11:29 AMtall-airline-16756
07/25/2025, 11:29 AMtall-airline-16756
07/25/2025, 11:29 AMaverage-architect-28889
07/25/2025, 11:34 AMtall-airline-16756
07/25/2025, 11:35 AMChatContext like your chat's personal assistant. You can grab all your messages and even add new ones super easily. Check this out:
const chatContext = new ChatContext();
const allMessages = chatContext.messages;
chatContext.append({ text: "Hello", role: ChatRole.USER });
• Python: Same idea here - just a simple way to manage your chat data. It's like having a neat little chat organizer:
chat_ctx = ChatContext()
all_items = chat_ctx.items
chat_ctx.add_message(role="user", content="Hello")
Default Fields Maintained:
• Core Protocol: Fields include id, timestamp, message, editTimestamp, deleted, and generated.
• JavaScript SDK: Additional fields include role, name, content, toolCalls, toolCallId, and toolException.
• Python SDK: Fields include id, type, role, content, interrupted, transcript_confidence, hash, and created_at.
• Flutter SDK: Fields include message, timestamp, id, sender, and participant.
Don't worry about the details - LiveKit's got your back and automatically handles all these fields for you behind the scenes!
Sources: agents/src/llm/chat_context.ts | livekit-agents/livekit/agents/llm/chat_context.py | External data and RAG | LiveKit Docs | packages/livekit-rtc/src/proto/room_pb.ts | lib/src/context/chat_context.dartaverage-architect-28889
07/25/2025, 11:38 AMtall-airline-16756
07/25/2025, 11:39 AMAgent class's chat_ctx property. It's super easy – just type agent.chat_ctx and you'll get a read-only view of your current chat context.
• JavaScript/TypeScript: For JavaScript or TypeScript fans, the VoicePipelineAgent and LLMStream classes have a handy chatCtx accessor. Just grab it with agent.chatCtx.
I noticed you might have been trying to use run_context.agent.chat.chat_ctx, but that doesn't quite match up with the documented ways of accessing the chat context. No worries though – stick with the methods I mentioned, and you'll be good to go!
Sources: livekit-agents/livekit/agents/voice/audio_recognition.py | VoicePipelineAgent | LiveKit Agents | LLMStream | LiveKit Agentsaverage-architect-28889
07/25/2025, 11:41 AMtall-airline-16756
07/25/2025, 11:42 AMagent.chat_ctx in LiveKit – it's actually pretty simple. 😊
• Basic Import for Agent:
from livekit.agents import Agent
• If you also need ChatContext directly:
from livekit.agents import Agent, ChatContext
• Alternative Import Using the llm Module:
from livekit.agents import Agent, llm
# Then use llm.ChatContext
• Or Import ChatContext from the llm Submodule:
from livekit.agents import Agent
from livekit.agents.llm import ChatContext
Quick tip: agent.chat_ctx gives you a read-only peek into the agent's current chat context as an llm.ChatContext object. Cool, right?
Here's a quick example to help you get started:
from livekit.agents import Agent
# Create an agent instance
agent = Agent(instructions="You are a helpful assistant.")
# Access the chat context
chat_context = agent.chat_ctx
Pro tip: The most straightforward way is just using from livekit.agents import Agent, which lets you easily access the chat_ctx property on your agent. Happy coding! 🚀
Sources: livekit-agents/livekit/agents/voice/agent_activity.pyaverage-architect-28889
07/25/2025, 11:43 AMtall-airline-16756
07/25/2025, 11:44 AM