stivenDR14 commited on
Commit
f5395f8
·
1 Parent(s): 97e737a

improving the prompt

Browse files
Files changed (2) hide show
  1. agent.py +51 -8
  2. app.py +1 -1
agent.py CHANGED
@@ -173,14 +173,14 @@ class BasicAgent:
173
  except Exception as e:
174
  print(f"Warning: Could not initialize DuckDuckGo tool: {e}")
175
 
176
- """ try:
177
  # Wikipedia search
178
  wiki_spec = WikipediaToolSpec()
179
  wiki_tools = FunctionTool.from_defaults(wiki_spec.wikipedia_search, name="wikipedia_search", description="Search Wikipedia for information")
180
  self.tools.extend(wiki_tools)
181
  print("✅ Wikipedia tool initialized")
182
  except Exception as e:
183
- print(f"Warning: Could not initialize Wikipedia tool: {e}") """
184
 
185
  """ try:
186
  # Web requests tool
@@ -226,13 +226,56 @@ class BasicAgent:
226
 
227
  # Create the CodeAct Agent without assuming event loop state
228
  #self.agent = CodeActAgent(**self._agent_params)
229
- # Enhanced prompt with specific formatting requirements
230
  enhanced_prompt = f"""
231
- You are a helpful assistant tasked with answering questions using a set of tools.
232
- Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
233
- FINAL ANSWER: [YOUR FINAL ANSWER].
234
- 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.
235
- Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  """
237
 
238
  self.agent = FunctionAgent(
 
173
  except Exception as e:
174
  print(f"Warning: Could not initialize DuckDuckGo tool: {e}")
175
 
176
+ try:
177
  # Wikipedia search
178
  wiki_spec = WikipediaToolSpec()
179
  wiki_tools = FunctionTool.from_defaults(wiki_spec.wikipedia_search, name="wikipedia_search", description="Search Wikipedia for information")
180
  self.tools.extend(wiki_tools)
181
  print("✅ Wikipedia tool initialized")
182
  except Exception as e:
183
+ print(f"Warning: Could not initialize Wikipedia tool: {e}")
184
 
185
  """ try:
186
  # Web requests tool
 
226
 
227
  # Create the CodeAct Agent without assuming event loop state
228
  #self.agent = CodeActAgent(**self._agent_params)
229
+ # Enhanced prompt with specific formatting requirements for medium models
230
  enhanced_prompt = f"""
231
+ You are an intelligent AI assistant equipped with powerful tools to help solve problems. You must think step-by-step and use the available tools when needed.
232
+
233
+ ## AVAILABLE TOOLS:
234
+ You have access to the following tools - use them strategically:
235
+
236
+ ### Mathematical Tools:
237
+ - add_numbers(a, b): Add two numbers together
238
+ - subtract_numbers(a, b): Subtract second number from first number
239
+ - multiply_numbers(a, b): Multiply two numbers
240
+ - divide_numbers(a, b): Divide first number by second number
241
+ - power_numbers(a, b): Raise first number to the power of second number
242
+ - calculate_percentage(value, percentage): Calculate percentage of a value
243
+ - get_modulus(a, b): Get the modulus of two numbers
244
+
245
+ ### Research Tools:
246
+ - tavily_search(query): Search the web for current information
247
+ - wikipedia_search(query): Search Wikipedia for factual information
248
+
249
+ ## INSTRUCTIONS:
250
+ 1. **Read the question carefully** and identify what type of answer is needed
251
+ 2. **Think step-by-step** - break down complex problems into smaller parts
252
+ 3. **Use tools when necessary** - don't try to guess calculations or current information
253
+ 4. **For mathematical problems**: Use the math tools for accuracy
254
+ 5. **For factual questions**: Use search tools to get current/accurate information
255
+ 6. **Show your reasoning** - explain your thought process before the final answer
256
+
257
+ ## ANSWER FORMAT:
258
+ Always end your response with exactly this format:
259
+ FINAL ANSWER: [YOUR ANSWER]
260
+
261
+ ## FORMATTING RULES FOR FINAL ANSWER:
262
+ - **Numbers**: Write plain numbers without commas, units, or symbols (unless specifically asked)
263
+ - **Text**: Use simple words, no articles (a, an, the), no abbreviations
264
+ - **Lists**: Comma-separated, following the above rules for each element
265
+ - **Calculations**: Show the result as a plain number
266
+
267
+ ## EXAMPLES:
268
+ Question: "What is 25% of 200?"
269
+ Reasoning: I need to calculate 25% of 200 using the percentage tool.
270
+ [Use calculate_percentage(200, 25)]
271
+ FINAL ANSWER: 50
272
+
273
+ Question: "What is the capital of France?"
274
+ Reasoning: This is a factual question about geography.
275
+ [Use wikipedia_search("France capital")]
276
+ FINAL ANSWER: Paris
277
+
278
+ Remember: Think carefully, use tools when helpful, and always provide your final answer in the specified format.
279
  """
280
 
281
  self.agent = FunctionAgent(
app.py CHANGED
@@ -164,7 +164,7 @@ with gr.Blocks() as demo:
164
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
165
 
166
  ---
167
- My certificate of completion: [![Certificate](https://huggingface.co/datasets/agents-course/final-certificates/resolve/main/certificates/stiv14/2025-06-27.png)](https://huggingface.co/datasets/agents-course/final-certificates/resolve/main/certificates/stiv14/2025-06-27.png)
168
 
169
  """
170
  )
 
164
  This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
165
 
166
  ---
167
+ My certificate of completion: https://huggingface.co/datasets/agents-course/final-certificates/resolve/main/certificates/stiv14/2025-06-27.png
168
 
169
  """
170
  )