calm-eye-57311
10/27/2025, 3:28 PMtall-airline-16756
10/27/2025, 3:29 PMtall-airline-16756
10/27/2025, 3:30 PMChatContext object with the messages you want and then pass it to the Agent constructor using the chat_ctx parameter. This way, your agent will have the context ready right from the start.
Here’s a friendly example in Python to guide you:
from livekit.agents import Agent, llm
# Create chat history
chat_history = [
{"role": "assistant", "content": "Hello, I am a travel planner. How can I help you?"},
{"role": "user", "content": "I want to go to Paris this summer."},
{"role": "assistant", "content": "Paris is a beautiful city. How many days will you be staying?"},
]
# Initialize chat context
chat_ctx = llm.ChatContext.empty()
for item in chat_history:
chat_ctx.add_message(role=item["role"], content=item["content"])
# Create agent with pre-loaded chat context
agent = Agent(
instructions="You are a helpful travel planner.",
llm=openai.LLM(model="gpt-4o-mini"),
chat_ctx=chat_ctx,
)
If you’re working with Node.js or TypeScript, the process is quite similar—you’d use the ChatContext and ChatMessage classes to set up your chat history.
Please feel free to reach out if you’d like me to walk you through more examples or if there’s anything else you need help with. I’m here to support you!
Sources: Pipeline nodes and hooks | LiveKit Docs | examples/warm-transfer/warm_transfer.py | External data and RAG | LiveKit Docs | Workflows | LiveKit Docs | agent/main.py