Nancy1906 commited on
Commit
bffa65a
·
verified ·
1 Parent(s): 5896e5f
Files changed (1) hide show
  1. my_tools.py +9 -11
my_tools.py CHANGED
@@ -235,16 +235,16 @@ scrape_tool = FunctionTool.from_defaults(fn=scrape_wikipedia_table, name="scrap
235
  fallback_tool= FunctionTool.from_defaults(fn=lambda q: "Procedo con conocimiento interno.", name="no_tool_solution", description="Fallback.")
236
  all_tools = [search_tool, scrape_tool, table_tool, code_tool, excel_tool, botanical_tool, reverse_tool, fallback_tool]
237
 
 
 
238
  # Construir descripciones de herramientas
239
- # Cada FunctionTool tiene .name y .tool_config.description
240
- # CORRECCIÓN AQUÍ:
241
  tool_descriptions = "\n".join([
242
- f"{t.name}: {t.tool_config.description}"
243
  for t in all_tools
244
  ])
245
 
246
  # Prompt de sistema final
247
- # (El resto del system_prompt y la inicialización del agente deben estar bien si esta es la única causa del SyntaxError)
248
  system_prompt = f"""Eres Alfred, un agente ReAct eficiente y preciso. Tu objetivo es responder preguntas de forma correcta.
249
  Sigue estos pasos rigurosamente:
250
  1. ANALIZA la pregunta cuidadosamente. Identifica la información clave y el tipo de respuesta esperada.
@@ -262,10 +262,10 @@ Herramientas disponibles (usa SOLO estos y con los nombres exactos):
262
  # Inicializar agente
263
  llm = GeminiLLM() # LlamaDebugHandler se añade dentro de GeminiLLM si no hay handlers
264
  alfred_agent = ReActAgent.from_tools(
265
- tools=all_tools,
266
- llm=llm,
267
- system_prompt=system_prompt,
268
- verbose=True,
269
  max_iterations=15,
270
  callback_manager=llm.callback_manager # Asegura que el agente usa el callback manager del LLM
271
  )
@@ -273,10 +273,8 @@ alfred_agent = ReActAgent.from_tools(
273
  def basic_agent_response(question: str) -> str:
274
  try:
275
  resp = alfred_agent.query(question)
276
- # El objeto de respuesta de ReActAgent suele tener un atributo .response
277
- # y si no, convertir a string podría dar el resultado principal.
278
  if hasattr(resp, 'response') and resp.response is not None:
279
- return str(resp.response)
280
  elif resp is not None:
281
  return str(resp)
282
  return "No se generó una respuesta válida."
 
235
  fallback_tool= FunctionTool.from_defaults(fn=lambda q: "Procedo con conocimiento interno.", name="no_tool_solution", description="Fallback.")
236
  all_tools = [search_tool, scrape_tool, table_tool, code_tool, excel_tool, botanical_tool, reverse_tool, fallback_tool]
237
 
238
+ all_tools = [search_tool, scrape_tool, table_tool, code_tool, excel_tool, botanical_tool, reverse_tool, fallback_tool]
239
+
240
  # Construir descripciones de herramientas
241
+ # CORRECCIÓN AQUÍ: Acceder a name y description a través de metadata
 
242
  tool_descriptions = "\n".join([
243
+ f"{t.metadata.name}: {t.metadata.description}" # Cambiado t.name a t.metadata.name y t.tool_config.description a t.metadata.description
244
  for t in all_tools
245
  ])
246
 
247
  # Prompt de sistema final
 
248
  system_prompt = f"""Eres Alfred, un agente ReAct eficiente y preciso. Tu objetivo es responder preguntas de forma correcta.
249
  Sigue estos pasos rigurosamente:
250
  1. ANALIZA la pregunta cuidadosamente. Identifica la información clave y el tipo de respuesta esperada.
 
262
  # Inicializar agente
263
  llm = GeminiLLM() # LlamaDebugHandler se añade dentro de GeminiLLM si no hay handlers
264
  alfred_agent = ReActAgent.from_tools(
265
+ tools=all_tools,
266
+ llm=llm,
267
+ system_prompt=system_prompt,
268
+ verbose=True,
269
  max_iterations=15,
270
  callback_manager=llm.callback_manager # Asegura que el agente usa el callback manager del LLM
271
  )
 
273
  def basic_agent_response(question: str) -> str:
274
  try:
275
  resp = alfred_agent.query(question)
 
 
276
  if hasattr(resp, 'response') and resp.response is not None:
277
+ return str(resp.response)
278
  elif resp is not None:
279
  return str(resp)
280
  return "No se generó una respuesta válida."