Skip to content

Commit a831db1

Browse files
committed
Refactor agent config loading and update examples
1 parent 59b0e8c commit a831db1

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

agents.yaml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
agents:
1313
# Example 1: Simple custom research agent with overrides
1414
custom_research_agent:
15-
base_class: "SGRAgent"
15+
base_class: "sgr_deep_research.core.SGRAgent"
1616
# Optional: Override LLM settings for this agent
1717
llm:
1818
model: "gpt-4o"

config.yaml.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ mcp:
5353
# url: "https://your-mcp-server.com/mcp"
5454
# headers:
5555
# Authorization: "Bearer your-token"
56+
57+
58+
# Note: The 'agents' field is optional and can be loaded from either:
59+
# - This config.yaml file
60+
# - Any separate file by GlobalConfig.definitions_from_yaml method
61+
# See examples in agents.yaml.example for agent configuration options
62+
agents:

sgr_deep_research/core/agent_config.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,31 @@ def from_yaml(cls, yaml_path: str) -> Self:
3838
if not yaml_path.exists():
3939
raise FileNotFoundError(f"Configuration file not found: {yaml_path}")
4040
config_data = yaml.safe_load(yaml_path.read_text(encoding="utf-8"))
41+
main_config_agents = config_data.pop("agents", {})
4142
if cls._instance is None:
42-
cls._instance = cls(**config_data)
43+
cls._instance = cls(
44+
**config_data,
45+
)
4346
else:
4447
cls._initialized = False
4548
cls._instance = cls(**config_data, agents=cls._instance.agents)
49+
# agents should be initialized last to allow merging
50+
cls._definitions_from_dict({"agents": main_config_agents})
51+
return cls._instance
52+
53+
@classmethod
54+
def _definitions_from_dict(cls, agents_data: dict) -> Self:
55+
for agent_name, agent_config in agents_data.get("agents").items():
56+
agent_config["name"] = agent_name
57+
58+
custom_agents = Definitions(**agents_data).agents
59+
60+
# Check for agents that will be overridden
61+
overridden = set(cls._instance.agents.keys()) & set(custom_agents.keys())
62+
if overridden:
63+
logger.warning(f"Loaded agents will override existing agents: " f"{', '.join(sorted(overridden))}")
64+
65+
cls._instance.agents.update(custom_agents)
4666
return cls._instance
4767

4868
@classmethod
@@ -68,18 +88,4 @@ def definitions_from_yaml(cls, agents_yaml_path: str) -> Self:
6888
if not yaml_data.get("agents"):
6989
raise ValueError(f"Agents definitions file must contain 'agents' key: {agents_yaml_path}")
7090

71-
for agent_name, agent_config in yaml_data.get("agents").items():
72-
agent_config["name"] = agent_name
73-
74-
custom_agents = Definitions(**yaml_data).agents
75-
76-
# Check for agents that will be overridden
77-
overridden = set(cls._instance.agents.keys()) & set(custom_agents.keys())
78-
if overridden:
79-
logger.warning(
80-
f"Custom agents from {agents_yaml_path.name} will override existing agents: "
81-
f"{', '.join(sorted(overridden))}"
82-
)
83-
84-
cls._instance.agents.update(custom_agents)
85-
return cls._instance
91+
return cls._definitions_from_dict(yaml_data)

0 commit comments

Comments
 (0)