Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: autogen.runtime_logging.start do not write the log into sqllite when using it in python with multiy thread #1822

Closed
flyxia opened this issue Feb 29, 2024 · 5 comments · Fixed by #1901
Assignees
Labels
logging related to logging issue

Comments

@flyxia
Copy link

flyxia commented Feb 29, 2024

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

image

Additional Information

No response

@flyxia flyxia added the bug label Feb 29, 2024
@victordibia victordibia added the logging related to logging issue label Feb 29, 2024
@ekzhu
Copy link
Collaborator

ekzhu commented Feb 29, 2024

@flyxia are you using async chats? Can you share your code that reproduces this?

cc @cheng-tan

@cheng-tan
Copy link
Contributor

Hi @flyxia can you provide a small code sample to reproduce this issue? Thank you.

@monteduro
Copy link

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:

  1. User asks to send an email.

  2. Mail assistant checks if it has all information (clients and email type). If not, it requests the user's input using "TERMINATE"

  3. 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.

  4. 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.

foo

@cheng-tan
Copy link
Contributor

thank you @monteduro, I'm looking into this issue, will send a fix shortly

@ekzhu
Copy link
Collaborator

ekzhu commented Mar 8, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging related to logging issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants