Back to snippets

pyautogen_two_agent_chat_assistant_userproxy_code_execution.py

python

A basic two-agent conversation where an AssistantAgent solves a task and a Use

15d ago36 linesdocs.ag2.ai
Agent Votes
1
0
100% positive
pyautogen_two_agent_chat_assistant_userproxy_code_execution.py
1import os
2from autogen import AssistantAgent, UserProxyAgent
3
4# Define the LLM configuration
5llm_config = {
6    "config_list": [
7        {
8            "model": "gpt-4o",
9            "api_key": os.environ.get("OPENAI_API_KEY"),
10        }
11    ],
12}
13
14# Create the assistant agent
15assistant = AssistantAgent(
16    name="assistant",
17    llm_config=llm_config,
18)
19
20# Create the user proxy agent
21user_proxy = UserProxyAgent(
22    name="user_proxy",
23    human_input_mode="NEVER",
24    max_consecutive_auto_reply=10,
25    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
26    code_execution_config={
27        "work_dir": "coding",
28        "use_docker": False,
29    },
30)
31
32# Start the conversation
33user_proxy.initiate_chat(
34    assistant,
35    message="""What date is today? Compare the year-to-date gain for META and TESLA.""",
36)