Spaces:
Runtime error
Runtime error
bbbb
Browse files- my_tools.py +20 -8
my_tools.py
CHANGED
|
@@ -237,13 +237,14 @@ all_tools = [search_tool, scrape_tool, table_tool, code_tool, excel_tool, botani
|
|
| 237 |
|
| 238 |
# Construir descripciones de herramientas
|
| 239 |
# Cada FunctionTool tiene .name y .tool_config.description
|
| 240 |
-
|
| 241 |
-
.join([
|
| 242 |
f"{t.name}: {t.tool_config.description}"
|
| 243 |
for t in all_tools
|
| 244 |
])
|
| 245 |
|
| 246 |
# Prompt de sistema final
|
|
|
|
| 247 |
system_prompt = f"""Eres Alfred, un agente ReAct eficiente y preciso. Tu objetivo es responder preguntas de forma correcta.
|
| 248 |
Sigue estos pasos rigurosamente:
|
| 249 |
1. ANALIZA la pregunta cuidadosamente. Identifica la información clave y el tipo de respuesta esperada.
|
|
@@ -259,15 +260,26 @@ Herramientas disponibles (usa SOLO estos y con los nombres exactos):
|
|
| 259 |
{tool_descriptions}"""
|
| 260 |
|
| 261 |
# Inicializar agente
|
| 262 |
-
llm = GeminiLLM()
|
| 263 |
-
alfred_agent = ReActAgent.from_tools(
|
| 264 |
-
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
def basic_agent_response(question: str) -> str:
|
| 268 |
try:
|
| 269 |
resp = alfred_agent.query(question)
|
| 270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
except Exception as e:
|
| 272 |
-
return f"Error crítico: {e}"
|
| 273 |
|
|
|
|
| 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.
|
|
|
|
| 260 |
{tool_descriptions}"""
|
| 261 |
|
| 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 |
+
)
|
| 272 |
|
| 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."
|
| 283 |
except Exception as e:
|
| 284 |
+
return f"Error crítico del agente: {e}"
|
| 285 |
|