Pass variable to chat agent #26807
Unanswered
juliouyehara
asked this question in
Q&A
Replies: 1 comment 2 replies
-
To pass the import chainlit as cl
from tools.output_tools import *
import asyncio
@cl.password_auth_callback
def auth_callback(username: str, password: str):
user_info = USERS.get(username)
if user_info and user_info["password"] == password:
cdfazenda = user_info.get("cdfazenda", "Livre")
role = user_info.get("role", "user")
return cl.User(
identifier=username,
metadata={"cdfazenda": cdfazenda, "role": role}
)
else:
return None
@cl.on_message
async def main(message: cl.Message):
user_metadata = cl.user_session.get("metadata", {})
cdfazenda = user_metadata.get("cdfazenda", "Livre")
agent_executor = chain(model="gemini_1.5_pro", session_id=cl.user_session.get("session_id"))
input_data = {
"input": message.content,
"chat_history": [],
"cdfazenda": cdfazenda # Pass the cdfazenda variable here
}
loop = asyncio.get_event_loop()
response = await loop.run_in_executor(None, agent_executor.invoke, input_data)
await message.reply(response) In this code, the Make sure that your agent and tools are designed to handle and utilize the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I'm using chainlit to build a chatbot, at the beginning of the chat there is a user login, where the cdfazenda variable is included in the metadata, what I want is to pass this variable to the agent to use it in a fixed way, so he doesn't need to interpret in the context what the cdfazenda variable is, so it remains in a fixed form to be used in the tools.
System Info
platform (windows)
python version 3.11
Beta Was this translation helpful? Give feedback.
All reactions