Spaces:
Running
Running
Turn str into callable before loading any-agent config
Browse files
src/surf_spot_finder/cli.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
from any_agent import AgentFramework, AnyAgent
|
2 |
-
import yaml
|
3 |
-
from pathlib import Path
|
4 |
|
5 |
from fire import Fire
|
6 |
from loguru import logger
|
@@ -26,7 +24,7 @@ def find_surf_spot(
|
|
26 |
|
27 |
"""
|
28 |
logger.info(f"Loading {config_file}")
|
29 |
-
config = Config.
|
30 |
|
31 |
if not config.main_agent.instructions:
|
32 |
if config.framework == AgentFramework.SMOLAGENTS:
|
|
|
1 |
from any_agent import AgentFramework, AnyAgent
|
|
|
|
|
2 |
|
3 |
from fire import Fire
|
4 |
from loguru import logger
|
|
|
24 |
|
25 |
"""
|
26 |
logger.info(f"Loading {config_file}")
|
27 |
+
config = Config.from_yaml(config_file)
|
28 |
|
29 |
if not config.main_agent.instructions:
|
30 |
if config.framework == AgentFramework.SMOLAGENTS:
|
src/surf_spot_finder/config.py
CHANGED
@@ -47,4 +47,15 @@ class Config(BaseModel):
|
|
47 |
"""
|
48 |
with open(yaml_path, "r") as f:
|
49 |
data = yaml.safe_load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
return cls(**data)
|
|
|
47 |
"""
|
48 |
with open(yaml_path, "r") as f:
|
49 |
data = yaml.safe_load(f)
|
50 |
+
# for each tool listed in main_agent.tools, use import lib to import it and replace the str with the callable
|
51 |
+
callables = []
|
52 |
+
for tool in data["main_agent"]["tools"]:
|
53 |
+
if isinstance(tool, str):
|
54 |
+
module_name, func_name = tool.rsplit(".", 1)
|
55 |
+
module = __import__(module_name, fromlist=[func_name])
|
56 |
+
print(f"Importing {tool}")
|
57 |
+
callables.append(getattr(module, func_name))
|
58 |
+
else:
|
59 |
+
# this means it must be an MCPTool
|
60 |
+
callables.append(tool)
|
61 |
return cls(**data)
|