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

in AgentBuilder~_build_agents, if there are more than one function can add to one agent, the agent`s system message will be update incorrectly #5037

Open
davidxwwang opened this issue Jan 14, 2025 · 2 comments
Labels
0.2 Issues which are related to the pre 0.4 codebase

Comments

@davidxwwang
Copy link

davidxwwang commented Jan 14, 2025

What happened?

eg: if Function send_email and get_user_emailaddress is registered to agent Email_Expert. the send_email or get_user_emailaddress will miss in the Email_Expert system message! --->

for func in list_of_functions:
....
self.agent_procs_assign[resp][0].update_system_message(
self.UPDATED_AGENT_SYSTEM_MESSAGE.format(
agent_system_message=agents_current_system_message,
function_name=func["name"],
function_description=func["description"],
)
)
print(f"Function {func['name']} is registered to agent {resp}.")

Image

Image

What did you expect to happen?

Function send_email and get_user_emailaddress in the Email_Expert system message

How can we reproduce it (as minimally and precisely as possible)?

def do_task2(using_model: str):

list_of_functions = [
    {
        "name": "ossinsight_data_api",
        "description": "This is an API endpoint allowing users (analysts) to input question about GitHub in text format to retrieve the related and structured data.",
        "function": ask_ossinsight,
    },
    {
        "name": "send_email",
        "description": "send email to user",
        "function": send_email,
    },
    {
        "name": "get_user_emailaddress",
        "description": "获取用户的email地址",
        "function": get_user_emailaddress,
    },
    {
        "name": "open_chrome",
        "description": "打开chrome浏览器",
        "function": open_chrome,
    }       
]

task = "给我算下1累加到50的结果,并发送到david的邮箱中,最后给我打开浏览器,我要看看邮箱内容 "

# 使用 SHA256 算法计算哈希值
hash_object = hashlib.sha256(task.encode("utf-8"))
hash_value = hash_object.hexdigest()

agent_builder = AgentBuilder(
    config_file_location='F:\\GitHub\\david-autogen\\test2',
    builder_model=using_model,
    agent_model=using_model,
)

saved_agents_config_path = f"{script_dir}/{hash_value}.json"
if os.path.exists(saved_agents_config_path):
    agent_list, agent_configs = agent_builder.load(filepath=saved_agents_config_path, list_of_functions=list_of_functions)
else:
    workspace = f"{parent_dir}/workspace" 
    agent_list, agent_configs = agent_builder.build(
        building_task=task,
        default_llm_config={"temperature": 0},
        code_execution_config={
            "last_n_messages": 2,
            "work_dir": workspace,
            "timeout": 60,
            "use_docker": "python:3",
        },
        list_of_functions=list_of_functions
    ) 
    agent_builder.save(saved_agents_config_path)

AutoGen version

0.2

Which package was this bug in

AgentChat

Model used

gpt-3.5

Python version

3.10

Operating system

windows

Any additional info you think would be helpful for fixing this bug

No response

@davidxwwang davidxwwang changed the title in AgentBuilder~_build_agents, if there are more than two functions can add to one agent, the agent`s system message will be update incorrectly in AgentBuilder~_build_agents, if there are more than one function can add to one agent, the agent`s system message will be update incorrectly Jan 14, 2025
@rysweet rysweet added 0.2 Issues which are related to the pre 0.4 codebase and removed needs-triage labels Jan 15, 2025
@rysweet
Copy link
Collaborator

rysweet commented Jan 15, 2025

hi @davidxwwang - are you sure you are on 0.2? if so would you consider migrating to 0.4?
since it seems you have also identified the root of the problem and a fix, you could also submit a PR for 0.2:

  • fork the repo
  • implement your fix in the fork
  • write tests if needed or appropriate
  • create the PR
  • validate that CI is green
  • submit for review

@davidxwwang
Copy link
Author

hi @davidxwwang - are you sure you are on 0.2? if so would you consider migrating to 0.4? since it seems you have also identified the root of the problem and a fix, you could also submit a PR for 0.2:

  • fork the repo
  • implement your fix in the fork
  • write tests if needed or appropriate
  • create the PR
  • validate that CI is green
  • submit for review

yes, I have been developing on version 0.2 and haven't used version 0.4 yet. ok, l will try.

another problem is that : when using AGENT_SYS_MSG_PROMPT in AgentBuilder~build() to generate agent`s system message, the generated system message may loss TERMINATE info, this could make some tool calls to enter an infinite loop when using other model (Not GPT, but other large models( l use deepseek), maybe other large models might not have the same level of understanding and analysis ability as GPT) eg: the generated system message using AGENT_SYS_MSG_PROMPT will be like this

` ## Your role

Email_Expert is a specialized expert designed to handle tasks related to email communication, data calculation, and browser automation. This expert is proficient in performing mathematical calculations, sending emails, and managing browser operations to ensure seamless task execution.

## Task and skill instructions
  • Task description: Calculate the sum of numbers from 1 to 50, send the result to David's email, and open the browser to allow the user to check the email content.

  • Skill description:

    • Mathematical Calculation: Accurately compute the sum of a sequence of numbers.
    • Email Communication: Send the calculated result to a specified email address.
    • Browser Automation: Open a web browser to facilitate the user in checking the email content.
  • Other information: Ensure that the email is sent successfully and that the browser opens to the correct email interface for the user to verify the content.

This expert is equipped to handle the entire workflow efficiently, ensuring that each step is executed correctly and that the user can easily verify the results. `

I suggest adding the following statement to AGENT_SYS_MSG_PROMPT to make the agent clearly understand when the task ends and return “TERMINATE”:

Group chat instruction\nYou are now working in a group chat with different expert and a group chat manager.\nYou should refer to the previous message from other participant members or yourself, follow their topic and reply to them.When the task is complete and the result has been carefully verified, after obtaining agreement from the other members, you can end the conversation by replying only with "TERMINATE"

Here is the corresponding code: ` AgentBuilder~build()

print(colored("==> Generating system message...", "green"), flush=True) agent_sys_msg_list = [] for name in agent_name_list: print(f"Preparing system message for {name}", flush=True) resp_agent_sys_msg = ( self.builder_model.create( messages=[ { "role": "user", "content": self.AGENT_SYS_MSG_PROMPT.format( task=building_task, position=name, default_sys_msg=self.DEFAULT_DESCRIPTION, ), } ] ) .choices[0] .message.content ) `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.2 Issues which are related to the pre 0.4 codebase
Projects
None yet
Development

No branches or pull requests

2 participants