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