microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
32.25k stars 4.7k forks source link

Code Executor Agent Try To Execute JSON Code Block #3943

Closed egemeyvecioglu closed 1 hour ago

egemeyvecioglu commented 2 hours ago

What happened?

I have a setting where one user proxy and one assistant agent try to solve a task that must return structured file content such as JSON, YAML, etc. The assistant writes Python code, and the user proxy executes it. But then, when the assistant generates a JSON from the code output, the user proxy tries to execute it again, which results in confusion between agents.

What did you expect to happen?

User Proxy shouldn't try to execute JSON code block. Is there a way to let the user proxy agent only execute Python and shell scripts?

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


import autogen

llm_config = {
    "cache_seed": 42,
    "temperature": 0,
    "config_list": [
        {
            "model": "gpt-4o",
        }
    ],
    "timeout": 120,
}
user_proxy = autogen.UserProxyAgent(
    "user_proxy",
    llm_config=llm_config,
    code_execution_config={
        "last_n_messages": 3,
        "work_dir": "coding",
        "use_docker": False,
    },
    human_input_mode="NEVER",
)

assistant = autogen.AssistantAgent(
    "assistant",
    llm_config=llm_config,
    human_input_mode="NEVER",
)

user_proxy.initiate_chat(assistant, message="Give me a a json example.")

AutoGen version

0.3.1

Which package was this bug in

AgentChat

Model used

gpt-4

Python version

3.10

Operating system

MacOS

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

No response

ekzhu commented 1 hour ago

For your user proxy setting:

from autogen.coding import LocalCommandLineCodeExecutor

user_proxy = autogen.UserProxyAgent(
    "user_proxy",
    llm_config=llm_config,
    code_execution_config={
      "executor": LocalCommandLineCodeExecutor(work_dir="coding", execution_policies={"json": False}),
    },
    human_input_mode="NEVER",
)

Can you also update the issue description with your exact package used and version number? This is certainly not 0.4