Skip to content

Commit 4c549f4

Browse files
authored
feat(agent): support single agent mode. (#67)
* upd: add support for main-agent only mode. * add handle edge cases for sub_agents being null or {}
1 parent 0178a5e commit 4c549f4

File tree

3 files changed

+80
-18
lines changed

3 files changed

+80
-18
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
defaults:
2+
- benchmark: gaia-validation
3+
- override hydra/job_logging: none
4+
- _self_ # Allow defining variables at the top of this file
5+
6+
7+
main_agent:
8+
prompt_class: MainAgentPromptBoxedAnswer
9+
llm:
10+
provider_class: "ClaudeOpenRouterClient"
11+
model_name: "anthropic/claude-3.7-sonnet"
12+
async_client: true
13+
temperature: 0.3
14+
top_p: 0.95
15+
min_p: 0.0
16+
top_k: -1
17+
max_tokens: 32000
18+
openrouter_api_key: "${oc.env:OPENROUTER_API_KEY,???}"
19+
openrouter_base_url: "${oc.env:OPENROUTER_BASE_URL,https://openrouter.ai/api/v1}"
20+
openrouter_provider: "anthropic"
21+
disable_cache_control: false
22+
keep_tool_result: -1
23+
oai_tool_thinking: false
24+
25+
tool_config:
26+
- tool-reasoning-os
27+
- tool-searching
28+
- tool-image-video-os
29+
- tool-reading
30+
- tool-code
31+
- tool-audio-os
32+
33+
max_turns: -1 # Maximum number of turns for main agent execution
34+
max_tool_calls_per_turn: 10 # Maximum number of tool calls per turn
35+
36+
input_process:
37+
hint_generation: false
38+
hint_llm_base_url: "${oc.env:HINT_LLM_BASE_URL,https://api.openai.com/v1}"
39+
output_process:
40+
final_answer_extraction: false
41+
final_answer_llm_base_url: "${oc.env:FINAL_ANSWER_LLM_BASE_URL,https://api.openai.com/v1}"
42+
43+
openai_api_key: "${oc.env:OPENAI_API_KEY,???}" # used for hint generation and final answer extraction
44+
add_message_id: true
45+
keep_tool_result: -1
46+
chinese_context: "${oc.env:CHINESE_CONTEXT,false}"
47+
48+
49+
sub_agents: null
50+
51+
52+
# Can define some top-level or default parameters here
53+
output_dir: logs/
54+
data_dir: "${oc.env:DATA_DIR,data}" # Points to where data is stored
55+

src/core/orchestrator.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ async def wrapped():
4040
nonlocal cache
4141
if cache is None:
4242
# Only fetch tool definitions if not already cached
43-
result = {
44-
name: await tool_manager.get_all_tool_definitions()
45-
for name, tool_manager in sub_agent_tool_managers.items()
46-
}
43+
# Handle empty sub_agent_tool_managers (single agent mode)
44+
if not sub_agent_tool_managers:
45+
result = {}
46+
else:
47+
result = {
48+
name: await tool_manager.get_all_tool_definitions()
49+
for name, tool_manager in sub_agent_tool_managers.items()
50+
}
4751
cache = result
4852
return cache
4953

@@ -409,6 +413,8 @@ async def run_sub_agent(
409413
)
410414

411415
# Generate sub-agent system prompt
416+
if not self.cfg.sub_agents or sub_agent_name not in self.cfg.sub_agents:
417+
raise ValueError(f"Sub-agent {sub_agent_name} not found in configuration")
412418
sub_agent_prompt_instance = _load_agent_prompt_class(
413419
self.cfg.sub_agents[sub_agent_name].prompt_class
414420
)
@@ -761,7 +767,8 @@ async def run_main_agent(
761767

762768
# 2. Get tool definitions
763769
tool_definitions = await self.main_agent_tool_manager.get_all_tool_definitions()
764-
tool_definitions += expose_sub_agents_as_tools(self.cfg.sub_agents)
770+
if self.cfg.sub_agents is not None and self.cfg.sub_agents:
771+
tool_definitions += expose_sub_agents_as_tools(self.cfg.sub_agents)
765772
if not tool_definitions:
766773
logger.debug(
767774
"Warning: No tool definitions found. LLM cannot use any tools."

src/core/pipeline.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def execute_task_pipeline(
8686

8787
# Initialize sub agent LLM client
8888
# Require agent-specific LLM configuration for sub-agents
89-
if cfg.sub_agents:
89+
if cfg.sub_agents is not None and cfg.sub_agents:
9090
first_sub_agent = next(iter(cfg.sub_agents.values()))
9191
if hasattr(first_sub_agent, "llm") and first_sub_agent.llm is not None:
9292
sub_agent_llm_client = LLMClient(
@@ -97,9 +97,8 @@ async def execute_task_pipeline(
9797
"No LLM configuration found in sub-agent. Please ensure the agent configuration includes an LLM section."
9898
)
9999
else:
100-
raise ValueError(
101-
"No sub agents defined. Please ensure the agent configuration includes sub-agent sections."
102-
)
100+
sub_agent_llm_client = None
101+
logger.info("No sub agents defined, using main agent only for the task")
103102

104103
# Initialize orchestrator
105104
orchestrator = Orchestrator(
@@ -181,15 +180,16 @@ def create_pipeline_components(cfg: DictConfig, logs_dir: str | None = None):
181180
)
182181

183182
sub_agent_tool_managers = {}
184-
for sub_agent in cfg.sub_agents:
185-
sub_agent_mcp_server_configs, sub_agent_blacklist = (
186-
create_mcp_server_parameters(cfg, cfg.sub_agents[sub_agent], logs_dir)
187-
)
188-
sub_agent_tool_manager = ToolManager(
189-
sub_agent_mcp_server_configs,
190-
tool_blacklist=sub_agent_blacklist,
191-
)
192-
sub_agent_tool_managers[sub_agent] = sub_agent_tool_manager
183+
if cfg.sub_agents is not None and cfg.sub_agents:
184+
for sub_agent in cfg.sub_agents:
185+
sub_agent_mcp_server_configs, sub_agent_blacklist = (
186+
create_mcp_server_parameters(cfg, cfg.sub_agents[sub_agent], logs_dir)
187+
)
188+
sub_agent_tool_manager = ToolManager(
189+
sub_agent_mcp_server_configs,
190+
tool_blacklist=sub_agent_blacklist,
191+
)
192+
sub_agent_tool_managers[sub_agent] = sub_agent_tool_manager
193193

194194
# Create OutputFormatter
195195
output_formatter = OutputFormatter()

0 commit comments

Comments
 (0)