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]: max_consecutive_auto_reply not working on recipient agent #600

Open
marklysze opened this issue Jan 22, 2025 · 1 comment
Open

[Bug]: max_consecutive_auto_reply not working on recipient agent #600

marklysze opened this issue Jan 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@marklysze
Copy link
Collaborator

Describe the bug

The max_consecutive_auto_reply parameter on an agent is not terminating the chat when it's on the agent that is the recipient in initiate_chat.

In this example it should terminate when my_agent goes to reply for a second time, but doesn't:

from autogen import ConversableAgent
llm_config = {"model": "gpt-4o-mini"}

# Doesn't terminate on auto reply
my_agent = ConversableAgent(
    name="helpful_agent",
    llm_config=llm_config,
    system_message="You are a poetic AI assistant, respond in rhyme.",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=1
)

other_agent = ConversableAgent(
    name="other_agent",
    llm_config=llm_config,
    system_message="You are a scientific AI, respond with science facts.",
    human_input_mode="NEVER",
)

other_agent.initiate_chat(my_agent, message="What's the big deal about AI?", max_turns=10)

Whereas, if we change the agents around in initiate_chat, it does:

from autogen import ConversableAgent
llm_config = {"model": "gpt-4o-mini"}

# Does terminate on auto reply
my_agent = ConversableAgent(
    name="helpful_agent",
    llm_config=llm_config,
    system_message="You are a poetic AI assistant, respond in rhyme.",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=1
)

other_agent = ConversableAgent(
    name="other_agent",
    llm_config=llm_config,
    system_message="You are a scientific AI, respond with science facts.",
    human_input_mode="NEVER",
)

my_agent.initiate_chat(other_agent, message="What's the big deal about AI?", max_turns=10)

Steps to reproduce

See code above.

Model Used

Not model specific, used gpt-4o-mini

Expected Behavior

Terminated before replying a second time.

Screenshots and logs

No response

Additional Information

No response

@marklysze marklysze added the bug Something isn't working label Jan 22, 2025
@marklysze
Copy link
Collaborator Author

This is likely a broader issue, I encountered the same bug if I register a reply function with an agent that should terminate upon reply, but it doesn't if the agent with the reply function is the recipient in initiate_chat.

This should terminate when it's agent_b's turn to reply, but it doesn't.

from typing import Any, Dict, List, Optional, Tuple, Union
from autogen import ConversableAgent, Agent
llm_config = {"model": "gpt-4o-mini"}

a_agent = ConversableAgent(
    name="agent_a",
    llm_config=llm_config,
    system_message="You are a poetic AI assistant, respond in rhyme.",
    human_input_mode="TERMINATE",
)

b_agent = ConversableAgent(
    name="agent_b",
    llm_config=llm_config,
    system_message="You are a scientific AI, respond with science facts.",
    human_input_mode="NEVER",
)

def my_reply_func(
    recipient: ConversableAgent,
    messages: Optional[List[Dict]] = None,
    sender: Optional[Agent] = None,
    config: Optional[Any] = None,
) -> Tuple[bool, Union[str, Dict, None]]:
    return True, None

b_agent.register_reply(
    trigger="agent_a",
    reply_func=my_reply_func,
    position=0

)

# b_agent being recipient doesn't work here, switch a_agent and b_agent around here and it works.
a_agent.initiate_chat(recipient=b_agent, message="What's the big deal about AI?", max_turns=10)

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

No branches or pull requests

1 participant