Aurele000 commited on
Commit
a99d899
·
1 Parent(s): a404d0c

reflexion agent also

Browse files
Files changed (2) hide show
  1. agent.py +22 -5
  2. app.py +8 -0
agent.py CHANGED
@@ -207,26 +207,42 @@ agent_excel = create_react_agent(
207
 
208
  tools=[open_xlsx_doc, create_agent_and_answer, ],
209
  prompt=(
210
- "You are an agent psecialized with Excel files.\n\n"
211
  "INSTRUCTIONS:\n"
212
  "- Assist ONLY when an Excel file is mentionned \n"
213
  "- First, when you receive an Excel file path, you have to use the 'open_xlsx_doc' tool. Then you use the 'create_agent_and_answer'\n"
214
- "- The output of the first tool (the pd.Dataframe) is a part of the input of the first solution\n"
215
 
216
  "- Once you have got a response from the 'create_agent_and_answer_tool', transmit it to your supervisor \n"
217
  ),
218
  name="agent_excel",
219
  )
220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  supervisor = create_supervisor(
222
- model=init_chat_model("openai:gpt-4o", api_key = api_open_ai_agent_key),
223
- agents=[research_agent, math_agent, web_search_openai_agent, agent_excel],
224
  prompt=(
225
- "You are a supervisor managing four agents:\n"
226
  "- research_agent: Specialised in ArXiv and Wikipedia. Assign research-related tasks to this agent.\n"
227
  "- math_agent: Handles math-related tasks such as solving equations or performing calculations.\n"
228
  "- web_search_openai_agent: Can browse the web to find up-to-date and relevant information. Assign web-related tasks to this agent.\n"
229
  "- agent_excel: Can exploit Excel file. You have to give him an Excel path file with a question, and wait for his response.\n"
 
230
  "Assign work to one agent at a time. Do not call agents in parallel.\n"
231
  "When a new question arises, always first consult the research_agent — it may provide useful information.\n"
232
  "If research_agent yields no results, then delegate the task to web_search_openai_agent.\n"
@@ -248,6 +264,7 @@ def response_from_agent(question):
248
  for chunk in supervisor.stream(
249
  {"messages": [{"role": "user", "content": question}]}
250
  ):
 
251
  response = chunk
252
 
253
 
 
207
 
208
  tools=[open_xlsx_doc, create_agent_and_answer, ],
209
  prompt=(
210
+ "You are an agent specialized with Excel files.\n\n"
211
  "INSTRUCTIONS:\n"
212
  "- Assist ONLY when an Excel file is mentionned \n"
213
  "- First, when you receive an Excel file path, you have to use the 'open_xlsx_doc' tool. Then you use the 'create_agent_and_answer'\n"
214
+ "- The output of the first tool is a part of the input of the second tool\n"
215
 
216
  "- Once you have got a response from the 'create_agent_and_answer_tool', transmit it to your supervisor \n"
217
  ),
218
  name="agent_excel",
219
  )
220
 
221
+ reflexion_agent = create_react_agent(
222
+ model=llm_reasoning,
223
+
224
+ tools=[],
225
+ prompt=(
226
+ "You are an intelligent agent\n\n"
227
+ "INSTRUCTIONS:\n"
228
+ "- Assist ONLY when you are called \n"
229
+ "- You are the most intelligent agent"
230
+ "- Your job is to solve hard problems when your supervisor ask you to do so"
231
+ "- Give him a precise answer. "
232
+ ),
233
+ name="reflexion_agent",
234
+ )
235
+
236
  supervisor = create_supervisor(
237
+ model=init_chat_model("openai:gpt-4.1", api_key = api_open_ai_agent_key),
238
+ agents=[research_agent, math_agent, web_search_openai_agent, agent_excel, reflexion_agent],
239
  prompt=(
240
+ "You are a supervisor managing five agents:\n"
241
  "- research_agent: Specialised in ArXiv and Wikipedia. Assign research-related tasks to this agent.\n"
242
  "- math_agent: Handles math-related tasks such as solving equations or performing calculations.\n"
243
  "- web_search_openai_agent: Can browse the web to find up-to-date and relevant information. Assign web-related tasks to this agent.\n"
244
  "- agent_excel: Can exploit Excel file. You have to give him an Excel path file with a question, and wait for his response.\n"
245
+ "- reflexion_agent: This agent uses a powerful model. It is your most intelligent agent. Useful for reflexion tasks\n"
246
  "Assign work to one agent at a time. Do not call agents in parallel.\n"
247
  "When a new question arises, always first consult the research_agent — it may provide useful information.\n"
248
  "If research_agent yields no results, then delegate the task to web_search_openai_agent.\n"
 
264
  for chunk in supervisor.stream(
265
  {"messages": [{"role": "user", "content": question}]}
266
  ):
267
+
268
  response = chunk
269
 
270
 
app.py CHANGED
@@ -63,7 +63,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
63
  results_log = []
64
  answers_payload = []
65
  print(f"Running agent on {len(questions_data)} questions...")
 
66
  for item in questions_data:
 
 
 
67
  task_id = item.get("task_id")
68
  question_text = item.get("question")
69
  filename = item.get('file_name')
@@ -71,7 +75,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
71
  print(f"Skipping item with missing task_id or question: {item}")
72
  continue
73
  try:
 
 
 
74
  submitted_answer = response_from_agent(question_text + 'The file_name (path) is : ' + filename)
 
75
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
76
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
77
  except Exception as e:
 
63
  results_log = []
64
  answers_payload = []
65
  print(f"Running agent on {len(questions_data)} questions...")
66
+ i = 0
67
  for item in questions_data:
68
+ i+=1
69
+ print(f'on est la {i} ieme question')
70
+
71
  task_id = item.get("task_id")
72
  question_text = item.get("question")
73
  filename = item.get('file_name')
 
75
  print(f"Skipping item with missing task_id or question: {item}")
76
  continue
77
  try:
78
+ print(f'la question est {question_text}')
79
+ if filename :
80
+ print('fichier attaché : ', filename)
81
  submitted_answer = response_from_agent(question_text + 'The file_name (path) is : ' + filename)
82
+ print('submitted_answer:', submitted_answer)
83
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
84
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
85
  except Exception as e: