will this work? does cat context have append funct...
# ask-ai
p
will this work? does cat context have append function?
Copy code
chat_ctx = ChatContext()
    chat_ctx = chat_ctx.append(role="system", text=AGENT_INSTRUCTIONS)
    chat_ctx = chat_ctx.append(role="user", text="Hello")
t
Thanks for reaching out, Vaneeza. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I’m happy to help clarify this for you! The
ChatContext
class in LiveKit doesn’t have a direct
append
method built into its core. Instead, you’ll want to use the
add_message()
method to add messages to the context. Here’s a quick example:
Copy code
chat_ctx.add_message(role="system", text=AGENT_INSTRUCTIONS)
That said, some examples or utilities might offer an
append
method just to make things a bit easier, but it’s not officially part of the core class. If you run into any trouble, I recommend sticking with
add_message()
. Please feel free to reach out if you have any more questions—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent.py | delay-handling/README.mdoc
p
ChatContext.add_message() got an unexpected keyword argument 'text'
t
Hi there! Just a quick note: the
ChatContext.add_message()
method doesn’t take a
text
argument. Instead, you’ll want to use the
content
argument to add your message. Here’s a little example to help you out:
Copy code
chat_ctx.add_message(role="system", content=AGENT_INSTRUCTIONS)
The
content
argument is pretty flexible — it can be a string or even a list with text, images, or audio. If anything’s unclear or you want to dive deeper, just let me know. I’m here to help! Sources: examples/drive-thru/test_agent.py