"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(grounding): keep code-tool envelope bookkeeping out of observed evidence
zeus229c54cfa3d444d
diff --git a/agent/src/agent/grounding/evidence.py b/agent/src/agent/grounding/evidence.pyindex 49799cb75..9ce60e2f1 100644--- a/agent/src/agent/grounding/evidence.py+++ b/agent/src/agent/grounding/evidence.py@@ -29,6 +29,12 @@ _TIMESTAMP_FIELDS = ("trade_date", "date", "datetime", "timestamp", "time", "ind_MAX_GENERIC_EVIDENCE = 2_000+#: Top-level fields of a code-running tool's envelope (backtest, bash, ...). They+#: describe the process, not the market, so they never become observed evidence.+_ENVELOPE_FIELDS = frozenset(+ {"exit_code", "returncode", "elapsed_seconds", "duration_seconds"}+)+# Only these CSV columns count; Volume, Adj Close etc. are ignored so the# contradiction check gains no values it would be willing to accept._CSV_PRICE_COLUMNS = {@@ -1157,6 +1163,8 @@ class _EvidenceMixin:for key, item in value.items():if str(key).casefold() in timestamp_fields:continue+ if not path and str(key).casefold() in _ENVELOPE_FIELDS:+ continuevisit(item,f"{path}.{key}" if path else str(key),diff --git a/agent/tests/test_grounding_code_tool_envelope.py b/agent/tests/test_grounding_code_tool_envelope.pynew file mode 100644index 000000000..dd208b5ff--- /dev/null+++ b/agent/tests/test_grounding_code_tool_envelope.py@@ -0,0 +1,64 @@+"""Operational envelope fields of code-running tools are not financial evidence."""++from __future__ import annotations++import json+from pathlib import Path++import pytest++from src.agent.grounding import GroundingLedger++pytestmark = pytest.mark.unit+++def _ledger(tmp_path: Path, tool: str, payload: dict) -> GroundingLedger:+ ledger = GroundingLedger(run_dir=tmp_path, user_message="Analyze AAPL.US")+ ledger.ingest_tool_result(+ tool_name=tool,+ arguments={"run_dir": str(tmp_path)},+ result=json.dumps(payload),+ call_id="call-1",+ success=True,+ )+ return ledger++[email protected]("tool", ["backtest", "bash"])[email protected]("field", ["exit_code", "elapsed_seconds"])+def test_envelope_bookkeeping_is_not_observed_evidence(+ tmp_path: Path, tool: str, field: str+) -> None:+ ledger = _ledger(+ tmp_path,+ tool,+ {+ "status": "ok",+ "exit_code": 0,+ "elapsed_seconds": 12.5,+ "stdout": "done",+ "stderr": "",+ },+ )++ assert [+ r for r in ledger._evidence if r.field in {"exit_code", "elapsed_seconds"}+ ] == []++ claim = "12.5" if field == "elapsed_seconds" else "0.0"+ result = ledger.validate_final_answer(+ f"The run reported {claim}.\n\n```figures\n{claim} | observed | {field} | {tool}\n```"+ )+ assert result.valid is False+++def test_explicit_numeric_result_of_a_tool_still_grounds(tmp_path: Path) -> None:+ ledger = _ledger(+ tmp_path,+ "bash",+ {"status": "ok", "exit_code": 0, "result": {"sma_20": 187.42}},+ )++ assert any(+ r.field == "result.sma_20" and r.value == 187.42 for r in ledger._evidence+ )