CoralLeiCN commited on
Commit
0173236
·
1 Parent(s): cd5c77a

Refactor imports and enhance system prompts in agents and tools modules

Browse files
Files changed (5) hide show
  1. agent/agents.py +7 -6
  2. agent/prompts.py +3 -1
  3. agent/score.py +0 -2
  4. agent/tools.py +2 -3
  5. agent/utils.py +0 -1
agent/agents.py CHANGED
@@ -1,13 +1,12 @@
1
  import time
2
 
3
  import litellm
4
- from google import genai
5
  from google.genai import types
6
- from google.genai.types import GenerateContentConfig, ThinkingConfig
7
  from pydantic import BaseModel
8
- from smolagents import CodeAgent, Tool, VisitWebpageTool, WebSearchTool
9
 
10
- from agent.prompts import system_prompt
11
  from agent.tools import (
12
  CodeExecutionTool,
13
  DownloadFile,
@@ -101,13 +100,15 @@ class BasicAgent:
101
  print(f"Agent received question (first 50 chars): {question[:50]}...")
102
  # Run the agent to find the best catering service
103
 
104
- answer = self.code_agent.run(f"Task id: {task_id}, Question: {question}")
 
 
105
  print(f"Agent found answer: {answer}")
106
  response = client.models.generate_content(
107
  model=model,
108
  contents=f"Here is the provided question: {question}, infomation or answer: {str(answer)} \n Now, resposne with the answer that followed the rules.",
109
  config=types.GenerateContentConfig(
110
- system_instruction=system_prompt,
111
  response_mime_type="application/json",
112
  temperature=0.0,
113
  response_schema=final_answer,
 
1
  import time
2
 
3
  import litellm
 
4
  from google.genai import types
5
+ from google.genai.types import ThinkingConfig
6
  from pydantic import BaseModel
7
+ from smolagents import CodeAgent, VisitWebpageTool, WebSearchTool
8
 
9
+ from agent.prompts import formatter_system_prompt, system_prompt
10
  from agent.tools import (
11
  CodeExecutionTool,
12
  DownloadFile,
 
100
  print(f"Agent received question (first 50 chars): {question[:50]}...")
101
  # Run the agent to find the best catering service
102
 
103
+ answer = self.code_agent.run(
104
+ f"{system_prompt}\nTask id: {task_id}, Question: {question}"
105
+ )
106
  print(f"Agent found answer: {answer}")
107
  response = client.models.generate_content(
108
  model=model,
109
  contents=f"Here is the provided question: {question}, infomation or answer: {str(answer)} \n Now, resposne with the answer that followed the rules.",
110
  config=types.GenerateContentConfig(
111
+ system_instruction=formatter_system_prompt,
112
  response_mime_type="application/json",
113
  temperature=0.0,
114
  response_schema=final_answer,
agent/prompts.py CHANGED
@@ -1,4 +1,6 @@
1
- system_prompt = """
 
 
2
  I will provide you with the question and the information and answer, often derived from agent outputs. Your task is to distill this information into a single, precisely formatted final answer. The final answer should adhere strictly to the following formatting rules. Provide ONLY the requested value(s) and nothing else:
3
  Output Type: The final answer must be one of the following:
4
  A single number (in Western/Arabic digits).
 
1
+ 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."""
2
+
3
+ formatter_system_prompt = """
4
  I will provide you with the question and the information and answer, often derived from agent outputs. Your task is to distill this information into a single, precisely formatted final answer. The final answer should adhere strictly to the following formatting rules. Provide ONLY the requested value(s) and nothing else:
5
  Output Type: The final answer must be one of the following:
6
  A single number (in Western/Arabic digits).
agent/score.py CHANGED
@@ -1,10 +1,8 @@
1
  # modified from https://huggingface.co/spaces/gaia-benchmark/leaderboard/blob/main/scorer.py
2
- import json
3
  import re
4
  import string
5
  import warnings
6
 
7
- import numpy as np
8
 
9
 
10
  def normalize_number_str(number_str: str) -> float:
 
1
  # modified from https://huggingface.co/spaces/gaia-benchmark/leaderboard/blob/main/scorer.py
 
2
  import re
3
  import string
4
  import warnings
5
 
 
6
 
7
 
8
  def normalize_number_str(number_str: str) -> float:
agent/tools.py CHANGED
@@ -1,13 +1,12 @@
1
  import io
2
 
3
  import requests
 
4
  from google import genai
5
  from google.genai import types
6
- from langchain_community.retrievers import WikipediaRetriever
7
  from PIL import Image
8
  from smolagents import Tool
9
- import wikipedia
10
- from markdownify import markdownify as md
11
 
12
 
13
  class WikipediaSearchTool(Tool):
 
1
  import io
2
 
3
  import requests
4
+ import wikipedia
5
  from google import genai
6
  from google.genai import types
7
+ from markdownify import markdownify as md
8
  from PIL import Image
9
  from smolagents import Tool
 
 
10
 
11
 
12
  class WikipediaSearchTool(Tool):
agent/utils.py CHANGED
@@ -1,4 +1,3 @@
1
- import os
2
 
3
  from google import genai
4
  from smolagents import LiteLLMModel
 
 
1
 
2
  from google import genai
3
  from smolagents import LiteLLMModel