Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(agentic_rag): return calculate tool result (#19012)

Loonga39b6ec2e9a8
diff --git a/rag/advanced_rag/harness/action_session.py b/rag/advanced_rag/harness/action_session.py
index 3ccf72f6ff..293d4b3977 100644
--- a/rag/advanced_rag/harness/action_session.py
+++ b/rag/advanced_rag/harness/action_session.py
@@ -824,7 +824,7 @@ async def _exec_calculate(tools, args: dict) -> tuple:
if not res:
# nothing derivable -> tell the model so it doesn't loop on it
return [{"kind": "calculate", "expression": None, "note": "no numeric answer derivable from given facts; answer directly or retrieve more numbers."}], []
- return [{"kind": "calculate", "expression": res.get("expression"), "result": res.get("result"), "computed": res.get("computed_value")}], []
+ return [{"kind": "calculate", "expression": res.get("expression"), "result": res.get("value")}], []
async def _exec_graph_explore(tools, args: dict) -> tuple:
diff --git a/test/unit_test/rag/advanced_rag/test_action_session.py b/test/unit_test/rag/advanced_rag/test_action_session.py
new file mode 100644
index 0000000000..3f10fa041d
--- /dev/null
+++ b/test/unit_test/rag/advanced_rag/test_action_session.py
@@ -0,0 +1,34 @@
+from types import SimpleNamespace
+
+import pytest
+
+from rag.advanced_rag.harness.action_session import _exec_calculate
+
+
+async def test_exec_calculate_returns_computed_value(monkeypatch):
+ async def fake_compute_from_facts(model, question, facts):
+ assert model is tools.chat_mdl
+ assert question == "What is the total?"
+ assert facts == ["First value: 2", "Second value: 3"]
+ return {
+ "needed": True,
+ "label": "Total",
+ "value": "5",
+ "expression": "2 + 3",
+ "uses": [0, 1],
+ }
+
+ monkeypatch.setattr("rag.advanced_rag.harness.arithmetic.compute_from_facts", fake_compute_from_facts)
+ tools = SimpleNamespace(chat_mdl=object())
+
+ results, evidence_ids = await _exec_calculate(
+ tools,
+ {
+ "question": "What is the total?",
+ "facts": ["First value: 2", "Second value: 3"],
+ },
+ )
+
+ assert results == [{"kind": "calculate", "expression": "2 + 3", "result": "5"}]
+ assert evidence_ids == []