Spaces:
Sleeping
Sleeping
sem história de mensagens
Browse files
agent.py
CHANGED
@@ -37,46 +37,12 @@ class Agent:
|
|
37 |
text_inverter_tool, check_table_commutativity_tool],
|
38 |
prompt= SUPERVISOR_PROMPT,
|
39 |
add_handoff_back_messages=True,
|
40 |
-
output_mode="
|
41 |
).compile()
|
42 |
|
43 |
print("Agent initialized.")
|
44 |
|
45 |
|
46 |
-
|
47 |
-
def _call_antiga(self, question: str, task_id: str, task_file_name: str) -> str:
|
48 |
-
print(f"Agent received question({task_id}) (first 50 chars): {question[:50]}...")
|
49 |
-
|
50 |
-
file_prefix = ""
|
51 |
-
if task_file_name:
|
52 |
-
print(f"Task com arquivo {task_file_name}")
|
53 |
-
File_Util.baixa_arquivo_task(task_file_name)
|
54 |
-
file_prefix = f"File: {task_file_name} . "
|
55 |
-
|
56 |
-
for chunk in self.supervisor.stream(
|
57 |
-
{
|
58 |
-
"messages": [
|
59 |
-
{
|
60 |
-
"role": "user",
|
61 |
-
"content": f"{file_prefix}{question}",
|
62 |
-
}
|
63 |
-
]
|
64 |
-
},
|
65 |
-
):
|
66 |
-
Agent_Util.pretty_print_messages(chunk, last_message=True)
|
67 |
-
final_chunk = chunk
|
68 |
-
|
69 |
-
print("Extraindo a resposta do agente")
|
70 |
-
agent_answer = final_chunk["supervisor"]["messages"]
|
71 |
-
print(f"resposta: {agent_answer}")
|
72 |
-
|
73 |
-
|
74 |
-
final_answer = re.sub(r"^FINAL ANSWER:\s*", "", agent_answer, flags=re.IGNORECASE)
|
75 |
-
print(f"Agent returning answer for task {task_id}: {final_answer}")
|
76 |
-
|
77 |
-
return final_answer
|
78 |
-
|
79 |
-
|
80 |
def __call__(self, question: str, task_id: str, task_file_name: str) -> str:
|
81 |
print(f"Agent (nova forma de invocar) received question({task_id}) (first 50 chars): {question[:50]}...")
|
82 |
|
@@ -98,16 +64,10 @@ class Agent:
|
|
98 |
}
|
99 |
)
|
100 |
|
101 |
-
print(f"
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
return "Desculpe, não houve resposta."
|
106 |
-
|
107 |
-
print("Extraindo last_message")
|
108 |
-
last_msg = messages[-1]["content"]
|
109 |
-
print(f"Last Message: {last_msg}")
|
110 |
-
final_answer = re.sub(r"^FINAL ANSWER:\s*", "", last_msg.strip(), flags=re.IGNORECASE)
|
111 |
print(f"Agent returning answer for task {task_id}: {final_answer}")
|
112 |
|
113 |
return final_answer
|
|
|
37 |
text_inverter_tool, check_table_commutativity_tool],
|
38 |
prompt= SUPERVISOR_PROMPT,
|
39 |
add_handoff_back_messages=True,
|
40 |
+
output_mode="final_response",
|
41 |
).compile()
|
42 |
|
43 |
print("Agent initialized.")
|
44 |
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
def __call__(self, question: str, task_id: str, task_file_name: str) -> str:
|
47 |
print(f"Agent (nova forma de invocar) received question({task_id}) (first 50 chars): {question[:50]}...")
|
48 |
|
|
|
64 |
}
|
65 |
)
|
66 |
|
67 |
+
print(f"Resposta LLM: {response}")
|
68 |
+
answer_llm = response.get("output", "").strip()
|
69 |
+
print(f"Resposta pré-processada: {answer_llm}")
|
70 |
+
final_answer = re.sub(r"^FINAL ANSWER:\s*", "", answer_llm, flags=re.IGNORECASE)
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
print(f"Agent returning answer for task {task_id}: {final_answer}")
|
72 |
|
73 |
return final_answer
|