Hi, I have a question. How can i get the user tran...
# agents
a
Hi, I have a question. How can i get the user transcript when a function call executes so i can perform RAG?
@bland-addition-5518 @refined-appointment-81829
r
did you try session.history?
a
No. Let me see
no, it gives this <livekit.agents.llm.chat_context.ChatContext object at 0x10e61d9f0>
r
right you would need to extract the messages you want. you could try this:
Copy code
@function_tool  
async def your_rag_function(context: RunContext, query: str):  
    # Access the agent's chat context  
    chat_ctx = context.session.current_agent.chat_ctx  
      
    # Get the most recent user message  
    user_messages = [item for item in chat_ctx.items if item.role == "user"]  
    latest_transcript = user_messages[-1].text_content if user_messages else ""  
      
    # Perform RAG with the transcript  
    return await perform_rag(latest_transcript, query)