How can I access the chat transcript from within a...
# ask-ai
f
How can I access the chat transcript from within a function tool call in a LiveKit Agents Workflow in Python?
t
Thanks for reaching out, Amitrajit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you access the chat transcript within a function tool call in a LiveKit Agents Workflow using Python. You can do this by using the
chat_ctx
attribute of the
Agent
class. This attribute gives you access to the full conversation history, including user messages, agent responses, function calls, and their outputs—making it easier to keep track of everything. Here’s a simple example to show you how you can retrieve the chat transcript:
Copy code
from livekit.agents import Agent, function_tool

class MyAgent(Agent):
    @function_tool()
    async def get_full_chat_transcript(self) -> str:
        transcript = []
        for item in self.chat_ctx.items:
            if item.type == "message" and hasattr(item, "text_content"):
                role = item.role
                content = item.text_content if item.text_content else ""
                transcript.append(f"{role}: {content}")
            elif item.type == "function_call":
                transcript.append(f"Function Call: {item.name}({item.arguments}) [ID: {item.call_id}]")
            elif item.type == "function_call_output":
                transcript.append(f"Function Output: {item.output} [For Call ID: {item.call_id}]")
        return "\n".join(transcript)
The
chat_ctx.items
list holds all the interaction items in the order they happened, including: • Messages: User and assistant text input/output • Function Calls: When function tools are invoked • Function Outputs: The results returned by those function tools This approach lets you easily access and work with the conversation transcript however you need. If you have any questions or want to explore this further, feel free to ask—I’m here to help! Sources: README.md | Text and transcriptions | LiveKit Docs