If my agent is navigating the IVR or using some ot...
# ask-ai
b
If my agent is navigating the IVR or using some other tools, I want to add that in the conversation history. So that when the call ends, the transcript have everything like, which tools the LLM used, what was the button pressed in case of IVR etc. How can I do this?
t
Thanks for reaching out, Harsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to include agent actions like IVR navigation or tool usage in the conversation history and transcripts, here’s a simple way to do it: 1. Log DTMF Codes and IVR Navigation: You can use the
publish_dtmf
method to send DTMF codes and
publish_data
to log these actions right in the chat context. This way, all those DTMF codes get nicely recorded in the conversation history.
Copy code
await room.local_participant.publish_dtmf(code=code, digit=str(code))
await room.local_participant.publish_data(f"{code}", topic="dtmf_code")
2. Log Tool Execution: Whenever tools run, their outputs get added to the chat context. For example, DTMF codes sent by the agent show up as function calls along with their outputs.
Copy code
tool_output = perform_tool_executions(...)
chat_ctx.items.extend(tool_messages)
3. Use Chat Context Events: The
chatCtx
captures everything — messages, function calls, and more — so IVR navigation and tool usage are all recorded seamlessly. 4. Implement Cooldown for DTMF Codes: Just a heads-up: it’s a good idea to have a 3-second cooldown between DTMF presses to avoid any rapid-fire issues. By following these steps, you’ll have a full and clear record of agent actions included automatically in the conversation history and transcripts. Pretty handy, right? Sources: complex-agents/ivr-agent/README.md | livekit-agents/livekit/agents/voice/agent.py | Events and error handling | LiveKit Docs
b
so when I will do session.history, the items list will have everything in that?
t
The
session.history.items
list includes messages and tool usage, like function calls and their outputs. That said, it’s not totally clear from the docs whether IVR navigation actions (like DTMF signals) are included. If capturing those IVR navigation actions is important to you, you might want to set up some custom tracking or do a bit of extra testing to see how it’s handled. Checking any IVR-specific docs could also help clarify this.
b
how to add an item in chat context?
t
Hey there! If you want to add an item to the chat context in LiveKit, you can easily do that using the
add_message()
method from the
ChatContext
class. This lets you specify who’s sending the message and what the message is all about. Here’s a quick example to get you started: Sources: examples/drive-thru/test_agent.py