average-stone-56235
08/06/2025, 12:03 PMtall-airline-16756
08/06/2025, 12:03 PMtall-airline-16756
08/06/2025, 12:04 PM@function_tool()
async def get_user_data(context: RunContext, user_id: str) -> str:
"""
Retrieve user data from the database and provide it as context.
"""
try:
# Example: Querying a JSON database
with open('user_database.json', 'r') as db_file:
database = json.load(db_file)
user_data = database.get(user_id, {})
if user_data:
return json.dumps(user_data)
else:
return "User data not found."
except Exception as e:
logging.error(f"Error retrieving user data: {e}")
return "An error occurred while retrieving user data."
This function can be used to fetch user data and pass it to the LLM for generating responses. Let me know if you need further assistance or specific implementation details.
Sources: External data and RAG | LiveKit Docs | complex-agents/nutrition-assistant/README.mdaverage-stone-56235
08/06/2025, 12:07 PMtall-airline-16756
08/06/2025, 12:08 PMchat_ctx
parameter.
That said, if you ever need to bring in new or updated info during the chat, the agent can easily fetch it from the database whenever necessary. Just let me know if you'd like me to walk you through some examples or give you more details on how to set this up—I’m here to help!
Sources: Workflows | LiveKit Docs | Workflows | LiveKit Docs | External data and RAG | LiveKit Docs