Skip to content
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e6a4289
Add autogen.py
zhhhhhhhy Jul 9, 2025
2f87542
Modify the code of autogen #12
zhhhhhhhy Jul 15, 2025
d649092
modify autogen.py #12
zhhhhhhhy Jul 15, 2025
43872e8
add autogen.py #12
zhhhhhhhy Jul 15, 2025
74895fc
Revert "add autogen.py #12"
zhhhhhhhy Jul 15, 2025
7ad4b62
modify autogen.py #12
zhhhhhhhy Jul 15, 2025
d1495ff
modify autogen.py(#12)
zhhhhhhhy Jul 15, 2025
2ea48ac
Merge remote-tracking branch 'origin/main' into autogen-support
RuishanFang Jul 16, 2025
61851ee
Merge branch 'LINs-lab:main' into main
zhhhhhhhy Jul 16, 2025
b4f489e
Merge branch 'autogen-support' of https://github.com/zhhhhhhhy/MASAre…
zhhhhhhhy Jul 16, 2025
31d268e
Merge branch 'LINs-lab:main' into main
zhhhhhhhy Jul 18, 2025
fb50cc4
Merge branch 'LINs-lab:main' into main
zhhhhhhhy Jul 23, 2025
f6d5646
Merge branch 'main' of https://github.com/zhhhhhhhy/MASArena into aut…
zhhhhhhhy Jul 23, 2025
2a25acd
modify autogen.py
zhhhhhhhy Jul 23, 2025
7d244dd
test
zhhhhhhhy Jul 23, 2025
16c21bf
t
zhhhhhhhy Jul 25, 2025
ba24c37
modify autogen version
zhhhhhhhy Jul 25, 2025
5c1c0bd
Delete redundant files
zhhhhhhhy Jul 25, 2025
7bfb9fd
Merge remote-tracking branch 'masarena/main' into autogen-support
RuishanFang Aug 1, 2025
986da03
delete redundant documents
zhhhhhhhy Aug 1, 2025
c64e277
Merge branch 'autogen-support' of https://github.com/zhhhhhhhy/MASAre…
zhhhhhhhy Aug 1, 2025
8458616
refactor: clean up whitespace and formatting in autogen.py(#12)
RuishanFang Aug 1, 2025
c92e4cb
Merge remote-tracking branch 'origin/autogen-support' into autogen-su…
RuishanFang Aug 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions mas_arena/agents/autogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import os
from typing import Dict, Any
from openai import AsyncOpenAI
from dotenv import load_dotenv
from mas_arena.agents.base import AgentSystem, AgentSystemRegistry

load_dotenv()


class AutoGen(AgentSystem):

def __init__(self, name: str = "autogen", config: Dict[str, Any] = None):
"""Initialize the AutoGen System"""
super().__init__(name, config)
self.config = config or {}

self.model_name = self.config.get("model_name") or os.getenv("MODEL_NAME", "qwen-plus")

self.num_rounds = self.config.get("num_rounds", 5)

self.client = AsyncOpenAI(api_key=os.getenv("OPENAI_API_KEY"), base_url=os.getenv("OPENAI_API_BASE"))

self.agents = [
{
"name": "primary",
"system_prompt": """You are a helpful AI assistant, skilled at generating creative and accurate content."""
},
{
"name": "critic",
"system_prompt": "Provide constructive feedback on the content provided. Respond with 'APPROVE' when the content meets high standards or your feedback has been addressed."
}
]

async def run_agent(self, problem: Dict[str, Any], **kwargs) -> Dict[str, Any]:

problem_text = problem["problem"]
messages = [
{"role": "user", "content": f"Problem: {problem_text}"}
]
conversation_history = messages.copy()

all_messages = []
final_answer = ""

for _ in range(self.num_rounds):
for n, agent in enumerate(self.agents):
agent_name = agent["name"]
agent_prompt = agent["system_prompt"]

agent_messages = [
{"role": "system", "content": agent_prompt},
*conversation_history
]

response = await self.client.chat.completions.create(
model=self.model_name,
messages=agent_messages
)

response_content = response.choices[0].message.content

ai_message = {
'content': response_content,
'name': agent_name,
'role': 'assistant',
'message_type': 'ai_response',
'usage_metadata': response.usage
}

conversation_history.append({"role": "assistant", "content": response_content, "name": agent_name})

if (agent_name == "primary"):
final_answer = ai_message["content"]

if agent_name == "critic" and "approve" in response_content.lower():
return {
"messages": all_messages,
"final_answer": final_answer
}
all_messages.append(ai_message)

return {
"messages": all_messages,
"final_answer": final_answer
}


AgentSystemRegistry.register("autogen", AutoGen)