Skip to content

Commit bf5b919

Browse files
authored
Use kwargs to create agent_configs in AgentBuilder (#1209)
* Fix agent_configs in conf being ignored in AgentBuilder * Use TextAnalyzerAgent in tests * Minor refactor
1 parent f77bb74 commit bf5b919

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

autogen/agentchat/contrib/captainagent/agent_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def build(
397397
if max_agents is None:
398398
max_agents = self.max_agents
399399

400-
agent_configs = []
400+
agent_configs = kwargs.get("agent_configs", [])
401401
self.building_task = building_task
402402

403403
print(colored("==> Generating agents...", "green"), flush=True)

test/agentchat/contrib/test_agent_builder.py

+31
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import pytest
1414

1515
from autogen.agentchat.contrib.captainagent.agent_builder import AgentBuilder
16+
from autogen.agentchat.contrib.text_analyzer_agent import TextAnalyzerAgent
1617
from autogen.import_utils import optional_import_block, skip_on_missing_imports
1718

1819
from ...conftest import KEY_LOC, OAI_CONFIG_LIST
@@ -122,6 +123,36 @@ def test_build_from_library(builder: AgentBuilder):
122123
assert len(agent_config["agent_configs"]) <= builder.max_agents
123124

124125

126+
@pytest.mark.openai
127+
@skip_on_missing_imports(["openai"], "openai")
128+
def test_build_with_agent_configs(builder: AgentBuilder):
129+
conf = {
130+
"building_task": "Generate one TextAnalyzerAgent to analyze text",
131+
"agent_configs": [
132+
{
133+
"name": "TextAnalyzerAgent",
134+
"model": ["gpt-4o"],
135+
"description": "A helpful assistant to analyze text. Ask them to analyze any text, and they will provide you with the analysis.",
136+
"system_message": "",
137+
"agent_path": "autogen/agentchat/contrib/text_analyzer_agent/TextAnalyzerAgent",
138+
}
139+
],
140+
"coding": True,
141+
"default_llm_config": {"temperature": 0},
142+
"code_execution_config": {"work_dir": ".", "use_docker": False, "timeout": 60, "last_n_messages": 2},
143+
}
144+
145+
agents, _ = builder.build(**conf)
146+
147+
is_agent_found = False
148+
for agent in agents:
149+
if isinstance(agent, TextAnalyzerAgent):
150+
is_agent_found = True
151+
break
152+
153+
assert is_agent_found, "TextAnalyzerAgent not found in agents"
154+
155+
125156
@pytest.mark.openai
126157
@skip_on_missing_imports(["openai"], "openai")
127158
def test_save(builder: AgentBuilder):

0 commit comments

Comments
 (0)