autogen
autogen copied to clipboard
[Bug]: Runtime error with autogen.runtime_logging.start, using nested chats
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 https://github.com/microsoft/autogen/commit/ebde196d6b893003ef7986dd721d1686e42b9ea8
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
- Ensure you're using autogen version
v0.2.27
- 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()
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:
https://github.com/microsoft/autogen/blob/10bb25ba7d933f83e6f2f28a024e7a163cd77f5d/autogen/agentchat/conversable_agent.py#L1950-L1959
Would you like to propose a fix? cc @lalo
No. Only with logging enabled.
Happy to PR something but wasn’t sure the right approach to match code base expectations.
E.g. using getattr vs. @wrap instead of partial, etc.
On Thu, May 2, 2024 at 8:30 PM Eric Zhu @.***> wrote:
Does this happen when you turn off logging?
— Reply to this email directly, view it on GitHub https://github.com/microsoft/autogen/issues/2573#issuecomment-2091953827, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABDQA3CMTV7COBNTYHT5DTZALLCHAVCNFSM6AAAAABHD6VOOGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJRHE2TGOBSG4 . You are receiving this because you authored the thread.Message ID: @.***>
I think in this case using a simple wrapper function for nested chat makes the code more readable than partial.