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]: Runtime error with autogen.runtime_logging.start, using nested chats #2573

Closed
robraux opened this issue May 2, 2024 · 3 comments · Fixed by #2600
Closed

[Bug]: Runtime error with autogen.runtime_logging.start, using nested chats #2573

robraux opened this issue May 2, 2024 · 3 comments · Fixed by #2600
Labels
bug Something isn't working logging related to logging issue

Comments

@robraux
Copy link
Collaborator

robraux commented May 2, 2024

Describe the bug

Enabling runtime logging autogen.runtime_logging.start, while using nested chats with the default reply function causes a crash.

Introduced in v0.2.27 via ebde196

register_nested_chats -- default reply func uses a partial, which does supply the special __name__ attribute.

reply_func = partial(reply_func_from_nested_chats, chat_queue)

Steps to reproduce

  1. Ensure you're using autogen version v0.2.27
  2. Run "Additional Information" example, or, enable autogen.runtime_logging.start(config={"dbname": "logs.db"}) on existing nested chats application which uses the default reply function.

Model Used

gpt-3.5-turbo

Expected Behavior

No runtime error, logging executed successfully.

Screenshots and logs

Traceback (most recent call last):
  File "/Users/rraux/x/logging_failure.py", line 60, in <module>
    res = user_proxy.initiate_chat(
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rraux/Library/Caches/pypoetry/virtualenvs/ari-demo-autogen-FkVIsuHz-py3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 997, in initiate_chat
    msg2send = self.generate_reply(messages=self.chat_messages[recipient], sender=recipient)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rraux/Library/Caches/pypoetry/virtualenvs/ari-demo-autogen-FkVIsuHz-py3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 1955, in generate_reply
    reply_func_name=reply_func.__name__,
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'functools.partial' object has no attribute '__name__'. Did you mean: '__ne__'?

Additional Information

AutoGen Version: 0.2.27 minimum
Python Version: 3.11.3

Example Code for failure, based on autogen example.

import autogen

config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST")
llm_config = {"config_list": config_list}

writer = autogen.AssistantAgent(
    name="Writer",
    llm_config={"config_list": config_list},
    system_message="""
    You are a professional writer, known for your insightful and engaging articles.
    You transform complex concepts into compelling narratives.
    You should imporve the quality of the content based on the feedback from the user.
    """,
)

task = """Write a concise but engaging blogpost about Nvidia."""

user_proxy = autogen.UserProxyAgent(
    name="User",
    human_input_mode="NEVER",
    is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
    code_execution_config={
        "last_n_messages": 1,
        "work_dir": "tasks",
        "use_docker": False,
    },
)

critic = autogen.AssistantAgent(
    name="Critic",
    llm_config={"config_list": config_list},
    system_message="""
    You are a critic, known for your thoroughness and commitment to standards.
    Your task is to scrutinize content for any harmful elements or regulatory violations, ensuring
    all materials align with required guidelines.
    For code
    """,
)


def reflection_message(recipient, messages, sender, config):
    print("Reflecting...", "yellow")
    return f"Reflect and provide critique on the following writing. \n\n {recipient.chat_messages_for_summary(sender)[-1]['content']}"


user_proxy.register_nested_chats(
    [
        {
            "recipient": critic,
            "message": reflection_message,
            "summary_method": "last_msg",
            "max_turns": 1,
        }
    ],
    trigger=writer,  # condition=my_condition,
)

logging_session_id = autogen.runtime_logging.start(config={"dbname": "logs.db"})
res = user_proxy.initiate_chat(
    recipient=writer, message=task, max_turns=2, summary_method="last_msg"
)
autogen.runtime_logging.stop()
@robraux robraux added the bug Something isn't working label May 2, 2024
@ekzhu
Copy link
Collaborator

ekzhu commented May 3, 2024

Thanks for raising the issue. Like you said, the bug is due to the reply_func is a partial but the logging code does not know this:

if logging_enabled():
log_event(
self,
"reply_func_executed",
reply_func_module=reply_func.__module__,
reply_func_name=reply_func.__name__,
final=final,
reply=reply,
)
if final:

Would you like to propose a fix? cc @lalo

@ekzhu ekzhu added the logging related to logging issue label May 3, 2024
@robraux
Copy link
Collaborator Author

robraux commented May 3, 2024 via email

@ekzhu
Copy link
Collaborator

ekzhu commented May 3, 2024

I think in this case using a simple wrapper function for nested chat makes the code more readable than partial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logging related to logging issue
Projects
None yet
2 participants