Nathan Brake commited on
Commit
80972ac
·
unverified ·
1 Parent(s): 4ea7cdc

use new ver of any agent (#53)

Browse files
pyproject.toml CHANGED
@@ -9,7 +9,7 @@ license = {text = "Apache-2.0"}
9
  requires-python = ">=3.11"
10
  dynamic = ["version"]
11
  dependencies = [
12
- "any-agent[smolagents,mcp,openai,langchain,llama_index] @ git+ssh://[email protected]/mozilla-ai/any-agent",
13
  "fire",
14
  "loguru",
15
  "pydantic",
 
9
  requires-python = ">=3.11"
10
  dynamic = ["version"]
11
  dependencies = [
12
+ "any-agent[all]",
13
  "fire",
14
  "loguru",
15
  "pydantic",
src/surf_spot_finder/cli.py CHANGED
@@ -1,19 +1,17 @@
1
- from any_agent import AgentFramework, AnyAgent
2
-
3
  from fire import Fire
4
  from loguru import logger
5
 
6
  from surf_spot_finder.config import (
7
  Config,
8
  )
9
- from any_agent.tracing import setup_tracing
10
 
11
  from surf_spot_finder.instructions.openai import SINGLE_AGENT_SYSTEM_PROMPT
12
  from surf_spot_finder.instructions.smolagents import SYSTEM_PROMPT
13
 
14
 
15
  @logger.catch(reraise=True)
16
- def find_surf_spot(
17
  config_file: str,
18
  ) -> str:
19
  """Find the best surf spot based on the given criteria.
@@ -32,15 +30,13 @@ def find_surf_spot(
32
  elif config.framework == AgentFramework.OPENAI:
33
  config.main_agent.instructions = SINGLE_AGENT_SYSTEM_PROMPT
34
 
35
- logger.info("Setting up tracing")
36
- tracing_path = setup_tracing(config.framework, "output")
37
-
38
  logger.info(f"Loading {config.framework} agent")
39
  logger.info(f"{config.managed_agents}")
40
- agent = AnyAgent.create(
41
  agent_framework=config.framework,
42
  agent_config=config.main_agent,
43
  managed_agents=config.managed_agents,
 
44
  )
45
 
46
  query = config.input_prompt_template.format(
@@ -49,11 +45,9 @@ def find_surf_spot(
49
  DATE=config.date,
50
  )
51
  logger.info(f"Running agent with query:\n{query}")
52
- agent.run(query)
53
-
54
- logger.success("Done!")
55
 
56
- return tracing_path
57
 
58
 
59
  def main():
 
1
+ from any_agent import AgentFramework, AnyAgent, TracingConfig
 
2
  from fire import Fire
3
  from loguru import logger
4
 
5
  from surf_spot_finder.config import (
6
  Config,
7
  )
 
8
 
9
  from surf_spot_finder.instructions.openai import SINGLE_AGENT_SYSTEM_PROMPT
10
  from surf_spot_finder.instructions.smolagents import SYSTEM_PROMPT
11
 
12
 
13
  @logger.catch(reraise=True)
14
+ async def find_surf_spot(
15
  config_file: str,
16
  ) -> str:
17
  """Find the best surf spot based on the given criteria.
 
30
  elif config.framework == AgentFramework.OPENAI:
31
  config.main_agent.instructions = SINGLE_AGENT_SYSTEM_PROMPT
32
 
 
 
 
33
  logger.info(f"Loading {config.framework} agent")
34
  logger.info(f"{config.managed_agents}")
35
+ agent = await AnyAgent.create_async(
36
  agent_framework=config.framework,
37
  agent_config=config.main_agent,
38
  managed_agents=config.managed_agents,
39
+ tracing=TracingConfig(console=True, cost_info=True),
40
  )
41
 
42
  query = config.input_prompt_template.format(
 
45
  DATE=config.date,
46
  )
47
  logger.info(f"Running agent with query:\n{query}")
48
+ agent_trace = await agent.run_async(query)
 
 
49
 
50
+ logger.info(f"Final result:\n{agent_trace.final_output}")
51
 
52
 
53
  def main():
src/surf_spot_finder/config.py CHANGED
@@ -56,6 +56,21 @@ class Config(BaseModel):
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)
 
56
  print(f"Importing {tool}")
57
  callables.append(getattr(module, func_name))
58
  else:
59
+ # this means it must be an MCPStdioParams
60
  callables.append(tool)
61
+ data["main_agent"]["tools"] = callables
62
+ for agent in data.get("managed_agents", []):
63
+ callables = []
64
+ for tool in agent.get("tools", []):
65
+ if isinstance(tool, str):
66
+ module_name, func_name = tool.rsplit(".", 1)
67
+ module = __import__(module_name, fromlist=[func_name])
68
+ print(f"Importing {tool}")
69
+ callables.append(getattr(module, func_name))
70
+ else:
71
+ # this means it must be an MCPStdioParams
72
+ callables.append(tool)
73
+ agent["tools"] = callables
74
+
75
+ data["framework"] = AgentFramework[data["framework"]]
76
  return cls(**data)