Merge PR #1767 into reviewed maintenance batch
This commit is contained in:
commit
f2d59a67df
2 files changed
+72
No files matched your search
@@ -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:
|
||||
continue
|
||||
visit(
|
||||
item,
|
||||
f"{path}.{key}" if path else str(key),
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tool", ["backtest", "bash"])
|
||||
@pytest.mark.parametrize("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
|
||||
)
|
||||
Reference in new issue
Block a user