Sivaraj commited on
Commit
91d8810
·
1 Parent(s): a7e0d98

Add additional tools; tune agent system prompts

Browse files
Files changed (2) hide show
  1. agent.py +16 -6
  2. requirements.txt +1 -0
agent.py CHANGED
@@ -2,18 +2,22 @@ from smolagents import (
2
  ToolCallingAgent,
3
  CodeAgent,
4
  DuckDuckGoSearchTool,
 
5
  FinalAnswerTool,
6
  VisitWebpageTool,
7
  PromptTemplates,
8
  PlanningPromptTemplate,
9
  ManagedAgentPromptTemplate,
10
  FinalAnswerPromptTemplate,
 
11
  )
12
 
13
  from tool import addition_tool
14
  from src.config.model import openai_model
 
15
 
16
 
 
17
  # --- Basic Agent Definition ---
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
19
  class BaseAgent:
@@ -22,14 +26,18 @@ class BaseAgent:
22
  self.agent = ToolCallingAgent(
23
  model=openai_model,
24
  tools=[
25
- # addition_tool,
 
 
26
  DuckDuckGoSearchTool(),
27
- # VisitWebpageTool(),
28
- # FinalAnswerTool(),
29
  ],
 
 
30
  verbosity_level=2,
31
  prompt_templates=PromptTemplates(
32
- system_prompt="You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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.",
33
  planning=PlanningPromptTemplate(
34
  initial_plan="",
35
  update_plan_pre_messages="",
@@ -40,7 +48,7 @@ class BaseAgent:
40
  report="",
41
  ),
42
  final_answer=FinalAnswerPromptTemplate(
43
- pre_messages="", post_messages=""
44
  ),
45
  ),
46
  )
@@ -48,5 +56,7 @@ class BaseAgent:
48
  def run(self, question: str, additional_args: dict = None) -> str:
49
  print(f"Agent received question (first 50 chars): {question[:50]}...")
50
  response = self.agent.run(question, additional_args=additional_args)
 
 
51
  print(f"Agent returning response: {response}")
52
- return response.replace("FINAL ANSWER:", "").strip()
 
2
  ToolCallingAgent,
3
  CodeAgent,
4
  DuckDuckGoSearchTool,
5
+ PythonInterpreterTool,
6
  FinalAnswerTool,
7
  VisitWebpageTool,
8
  PromptTemplates,
9
  PlanningPromptTemplate,
10
  ManagedAgentPromptTemplate,
11
  FinalAnswerPromptTemplate,
12
+ WikipediaSearchTool,
13
  )
14
 
15
  from tool import addition_tool
16
  from src.config.model import openai_model
17
+ import re
18
 
19
 
20
+ gaia_prompt = "You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number then reply with digit and not in words, e.g: if Five, then reply with 5, if Three, then reply with 3, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. 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. 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."
21
  # --- Basic Agent Definition ---
22
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
23
  class BaseAgent:
 
26
  self.agent = ToolCallingAgent(
27
  model=openai_model,
28
  tools=[
29
+ addition_tool,
30
+ WikipediaSearchTool(),
31
+ PythonInterpreterTool(),
32
  DuckDuckGoSearchTool(),
33
+ VisitWebpageTool(),
34
+ FinalAnswerTool(),
35
  ],
36
+ add_base_tools=True,
37
+ max_steps=4,
38
  verbosity_level=2,
39
  prompt_templates=PromptTemplates(
40
+ system_prompt=gaia_prompt,
41
  planning=PlanningPromptTemplate(
42
  initial_plan="",
43
  update_plan_pre_messages="",
 
48
  report="",
49
  ),
50
  final_answer=FinalAnswerPromptTemplate(
51
+ pre_messages=gaia_prompt, post_messages=gaia_prompt+"The final answer should be as few words or numbers only. Exclude all the previuos context and only return the final answer. In case words separated by commas, use the following format: 'word1, word2, word3' without any additional text or explanation.",
52
  ),
53
  ),
54
  )
 
56
  def run(self, question: str, additional_args: dict = None) -> str:
57
  print(f"Agent received question (first 50 chars): {question[:50]}...")
58
  response = self.agent.run(question, additional_args=additional_args)
59
+ response = re.sub(r"(?s)^.*?FINAL ANSWER:", "FINAL ANSWER:", response)
60
+ response = response.replace("FINAL ANSWER:", "").strip()
61
  print(f"Agent returning response: {response}")
62
+ return response
requirements.txt CHANGED
@@ -2,3 +2,4 @@ gradio
2
  requests
3
  smolagents[toolkit,openai,vision,transformers,litellm]
4
  gradio[oauth]
 
 
2
  requests
3
  smolagents[toolkit,openai,vision,transformers,litellm]
4
  gradio[oauth]
5
+ wikipedia-api