[Bug]: autogen.runtime_logging.start do not write the log into sqllite when using it in python with multiy thread
Describe the bug
this is the error info: [SqliteLogger] log_chat_completion error: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 13416 and this is thread id 21888.
Steps to reproduce
No response
Expected Behavior
we expect it can use in multy thread
Screenshots and logs
Additional Information
No response
@flyxia are you using async chats? Can you share your code that reproduces this?
cc @cheng-tan
Hi @flyxia can you provide a small code sample to reproduce this issue? Thank you.
Same here, I'm using Flask and Socket.IO to communicate with Autogen.
# Override the _print_received_message method for sending to socket
def new_print_received_message(self, message, sender):
socketio.emit('message', {"sender": sender.name,
"content": message})
GroupChatManager._print_received_message = new_print_received_message
On the Flask side, I do this:
@socketio.on('send-message')
def handle_message(message):
global chat_started
if ( chat_started == False ):
chat_started = True
session['current_session_id'] = autogen.runtime_logging.start(logger_type="sqlite", config={"dbname": "logging.db"})
user_proxy.initiate_chat(
manager,
message=message,
summary_method="last_msg"
)
autogen.runtime_logging.stop()
else:
user_proxy.send(message, manager)
@app.route('/')
def index():
return render_template('index.html')
While it works, suddenly I encounter an issue where the logger stops working while chatting with agents:
SqliteLogger] log_chat_completion error: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 281471502578080 and this is thread id 281471017284000.
User Proxy
def is_termination_msg(content) -> bool:
print(content)
have_content = content.get("content", None) is not None
if have_content and "TERMINATE" in content["content"]:
return True
return False
user_proxy = UserProxyAgent(
'user_proxy',
system_message="...",
human_input_mode="TERMINATE",
is_termination_msg= is_termination_msg,
)
Info about the project
I'm creating a chat group using a graph with the goal of generating emails based on information that the user sends to the chats. The flow is as follows:
-
User asks to send an email.
-
Mail assistant checks if it has all information (clients and email type). If not, it requests the user's input using "TERMINATE"
-
Once the Mail Assistant has the required information, it forwards it to the Contact Meeting Mail Assistant. This assistant collects additional information specific to the "contact" mail type (such as motivation, date, and time of the meeting), continuing the conversation with the user using "TERMINATE" as needed.
-
Once the contact meeting mail assistant has the information, it passes it to the mail generation assistant, which is in charge of writing the actual mail based on the information and structure passed by the previous agent.
I also use function to collect client information, mail structure, today date, etc.
I'm not sure if Autogen is a good choice for such a tool, especially considering the heavy need for real user input.
thank you @monteduro, I'm looking into this issue, will send a fix shortly
@monteduro Have you seen sequential chats? It may be better suited for your use case then group chat.
See "Sequential Multi-Agent Chats" in the examples: https://microsoft.github.io/autogen/docs/Examples