rdisipio commited on
Commit
32ca30b
·
1 Parent(s): 0c791ca

adding tools

Browse files
Files changed (3) hide show
  1. agent.py +25 -15
  2. app.py +2 -2
  3. tools.py +1 -0
agent.py CHANGED
@@ -1,24 +1,34 @@
 
1
  from smolagents import (
2
  CodeAgent, InferenceClientModel, HfApiModel,
3
- DuckDuckGoSearchTool
4
  )
5
 
6
- # Initialize the Hugging Face model
7
- # model = InferenceClientModel()
8
- model = HfApiModel()
9
 
10
- tools = [
11
- DuckDuckGoSearchTool(),
12
- ]
13
-
14
- def create_agent():
15
  """
16
- Create and return a CodeAgent instance with the specified tools and model.
17
  """
18
- # Initialize the CodeAgent with the tools and model
19
- agent = CodeAgent(
20
- tools = tools,
21
- model = model
 
22
  )
23
- return agent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
 
1
+ import os
2
  from smolagents import (
3
  CodeAgent, InferenceClientModel, HfApiModel,
4
+ DuckDuckGoSearchTool, LiteLLMModel
5
  )
6
 
 
 
 
7
 
8
+ class MyAgent(CodeAgent):
 
 
 
 
9
  """
10
+ Custom agent class that extends CodeAgent.
11
  """
12
+ tools = [
13
+ DuckDuckGoSearchTool(),
14
+ ]
15
+ model = LiteLLMModel(
16
+ model_id="gemini/gemini-2.0-flash", api_key=os.getenv("GEMINI_API_KEY", "")
17
  )
18
+
19
+ def __init__(self, *args, **kwargs) -> None:
20
+ super().__init__(
21
+ tools=self.tools,
22
+ model=self.model,
23
+ additional_authorized_imports=[
24
+ "markdownify",
25
+ "requests",
26
+ "pandas",
27
+ "io",
28
+ ],
29
+ name="MyAgent",
30
+ description = "A custom agent that can search the web and generate code.",
31
+ add_base_tools=True,
32
+ max_steps=30,
33
+ )
34
 
app.py CHANGED
@@ -4,7 +4,7 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
7
- from agent import create_agent
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
@@ -32,7 +32,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
32
 
33
  # 1. Instantiate Agent ( modify this part to create your agent)
34
  try:
35
- agent = create_agent() # Call the function to create your agent
36
  except Exception as e:
37
  print(f"Error instantiating agent: {e}")
38
  return f"Error initializing agent: {e}", None
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from agent import MyAgent
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
 
32
 
33
  # 1. Instantiate Agent ( modify this part to create your agent)
34
  try:
35
+ agent = MyAgent() # Call the function to create your agent
36
  except Exception as e:
37
  print(f"Error instantiating agent: {e}")
38
  return f"Error initializing agent: {e}", None
tools.py CHANGED
@@ -0,0 +1 @@
 
 
1
+ from smolagents import tools