asthara commited on
Commit
140bc8d
·
1 Parent(s): 977691e

add two agents

Browse files
Files changed (5) hide show
  1. agent.py +36 -0
  2. app.py +3 -18
  3. prompts.yaml +0 -14
  4. retriever.py +0 -0
  5. tools.py +0 -0
agent.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import (
2
+ CodeAgent,
3
+ ToolCallingAgent,
4
+ HfApiModel,
5
+ WebSearchTool,
6
+ )
7
+ import yaml
8
+
9
+ #model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
10
+ model = HfApiModel(
11
+ max_tokens=2096,
12
+ temperature=0.5,
13
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
14
+ custom_role_conversions=None,
15
+ )
16
+
17
+ web_agent = ToolCallingAgent(
18
+ tools=[WebSearchTool()],
19
+ model=model,
20
+ max_steps=10,
21
+ name="web_search_agent",
22
+ description="Runs web searches.",
23
+ )
24
+
25
+ with open("prompts.yaml", 'r') as stream:
26
+ prompt_templates = yaml.safe_load(stream)
27
+
28
+ manager_agent = CodeAgent(
29
+ tools=[],
30
+ model=model,
31
+ managed_agents=[web_agent],
32
+ max_steps=6,
33
+ verbosity_level=1,
34
+ additional_authorized_imports=["time", "numpy", "pandas"],
35
+ prompt_templates=prompt_templates
36
+ )
app.py CHANGED
@@ -5,16 +5,16 @@ import inspect
5
  import pandas as pd
6
  from smolagents import CodeAgent, ToolCallingAgent, InferenceClientModel, WebSearchTool, LiteLLMModel, HfApiModel
7
  import yaml
 
8
 
9
- # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --- Basic Agent Definition ---
14
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
  def __init__(self):
17
  print("BasicAgent initialized.")
 
18
  def __call__(self, question: str) -> str:
19
  print(f"Agent received question (first 50 chars): {question[:50]}...")
20
  fixed_answer = "This is a default answer."
@@ -42,22 +42,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
42
 
43
  # 1. Instantiate Agent ( modify this part to create your agent)
44
  try:
45
- #agent = BasicAgent()
46
- model = HfApiModel(
47
- max_tokens=2096,
48
- temperature=0.5,
49
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
50
- custom_role_conversions=None,
51
- )
52
- with open("prompts.yaml", 'r') as stream:
53
- prompt_templates = yaml.safe_load(stream)
54
- agent = CodeAgent(
55
- model=model,
56
- tools=[WebSearchTool()],
57
- max_steps=10,
58
- verbosity_level=1,
59
- prompt_templates=prompt_templates
60
- )
61
  except Exception as e:
62
  print(f"Error instantiating agent: {e}")
63
  return f"Error initializing agent: {e}", None
 
5
  import pandas as pd
6
  from smolagents import CodeAgent, ToolCallingAgent, InferenceClientModel, WebSearchTool, LiteLLMModel, HfApiModel
7
  import yaml
8
+ from agent import manager_agent
9
 
 
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --- Basic Agent Definition ---
 
14
  class BasicAgent:
15
  def __init__(self):
16
  print("BasicAgent initialized.")
17
+ self.agent = manager_agent
18
  def __call__(self, question: str) -> str:
19
  print(f"Agent received question (first 50 chars): {question[:50]}...")
20
  fixed_answer = "This is a default answer."
 
42
 
43
  # 1. Instantiate Agent ( modify this part to create your agent)
44
  try:
45
+ agent = BasicAgent()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  except Exception as e:
47
  print(f"Error instantiating agent: {e}")
48
  return f"Error initializing agent: {e}", None
prompts.yaml CHANGED
@@ -15,17 +15,3 @@
15
  - You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
16
  - The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
17
  - Don't give up! You're in charge of solving the task, not providing directions to solve it.
18
-
19
- managed_agent: |-
20
- You are a general AI assistant. You will be asked a question.
21
- Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
22
- YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
23
- If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
24
- If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
25
- If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
26
-
27
- planning: |-
28
- Think step by step. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
29
-
30
- final_answer: |-
31
- FINAL ANSWER: {{final_answer}}
 
15
  - You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
16
  - The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
17
  - Don't give up! You're in charge of solving the task, not providing directions to solve it.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
retriever.py ADDED
File without changes
tools.py ADDED
File without changes