Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -221,13 +221,21 @@ compiled_graph = graph.compile()
|
|
221 |
|
222 |
# βββββββββββββββββββββββββββ Public API ββββββββββββββββββββββββββββββββ
|
223 |
|
224 |
-
def answer(question: str, task_id: Optional[str] = None) -> str:
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
|
233 |
|
|
|
221 |
|
222 |
# βββββββββββββββββββββββββββ Public API ββββββββββββββββββββββββββββββββ
|
223 |
|
224 |
+
def answer(question: str, *, task_id: Optional[str] = None) -> str:
|
225 |
+
"""Run the agent and return whatever FINAL_ANSWER the graph produces."""
|
226 |
+
init_state = AgentState(question, task_id)
|
227 |
+
init_state.add(SystemMessage(content="You are a helpful assistant."))
|
228 |
+
init_state.add(HumanMessage(content=question))
|
229 |
+
|
230 |
+
# IMPORTANT: invoke() returns a **new** state instance (or an AddableValuesDict),
|
231 |
+
# not the object we pass in. Use the returned value to fetch final_answer.
|
232 |
+
out_state = compiled_graph.invoke(init_state)
|
233 |
+
|
234 |
+
if isinstance(out_state, dict): # AddableValuesDict behaves like a dict
|
235 |
+
return out_state.get("final_answer", "No answer.")
|
236 |
+
else: # If future versions return the dataclass
|
237 |
+
return getattr(out_state, "final_answer", "No answer.")
|
238 |
+
|
239 |
|
240 |
|
241 |
|