purple-rainbow-1246
05/15/2025, 7:53 PMtall-airline-16756
05/15/2025, 7:53 PMtall-airline-16756
05/15/2025, 7:53 PMpublish_data
method with a custom topic. This ensures the message is not tracked in the chat history. Here's an example:
// JavaScript example
await room.localParticipant.publishData(
payload: JSON.stringify({ message: "Your message here" }),
topic: "custom-topic-not-for-chat"
);
On the agent's side (Python), you can listen for these messages by setting up a data receiver for the specific topic:
# Python example
@room.on("data_received")
def on_data_received(dp: DataPacket):
if dp.topic == "custom-topic-not-for-chat":
try:
parsed = json.loads(dp.data)
message = parsed["message"]
# Handle the message
except Exception as e:
logging.warning("Failed to parse message: %s", e, exc_info=e)
To send a message back to the participant, the agent can use the send_message
method of the `ChatManager`:
# Python example
await chat_manager.send_message("Hello from the agent!")
Let me know if you need further assistance!
Sources: Job lifecycle | LiveKit Docs | livekit.rtc.chat API documentation | livekit.rtc.chat API documentation