Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(goal): preserve tool-call provenance contract

zeus2298a2bc5b26577
diff --git a/agent/src/skills/research-goal/SKILL.md b/agent/src/skills/research-goal/SKILL.md
index 642c4bad6..73b9a047c 100644
--- a/agent/src/skills/research-goal/SKILL.md
+++ b/agent/src/skills/research-goal/SKILL.md
@@ -42,7 +42,9 @@ Use this shape when the user did not provide criteria:
- Keep evidence short and concrete.
- Prefer artifact-backed evidence when a tool produced a run or file.
- Include `run_id`, `artifact_path`, `source_provider`, `source_type`, `symbol_universe`, `benchmark`, and `data_as_of` when known.
-- `tool_call_id` is traceability only. Completion needs verified evidence from an existing `run_id` or an allowed `artifact_path` with a matching sha256 hash.
+- For evidence backed by one specific tool result, copy that result's exact `tool_call_id` into `add_goal_evidence`; do not shorten, alias, or invent it.
+- `evidence_id` values such as `ev_...` identify rows in the research-goal ledger. They are used by goal audits and are never grounding source refs; do not write `ev_...::field` in a figures declaration.
+- `tool_call_id` preserves provenance but does not verify goal completion by itself. Completion still needs verified evidence from an existing `run_id` or an allowed `artifact_path` with a matching sha256 hash.
- Do not mark live trading instructions as evidence. Refuse or reframe them as research-only analysis.
## Completion Rules
diff --git a/agent/src/tools/goal_tool.py b/agent/src/tools/goal_tool.py
index 90b56afd1..f607a6ac8 100644
--- a/agent/src/tools/goal_tool.py
+++ b/agent/src/tools/goal_tool.py
@@ -351,7 +351,10 @@ class AddGoalEvidenceTool(_GoalToolBase):
name = "add_goal_evidence"
description = (
"Attach a concise evidence note, artifact reference, or tool result to the current "
- "research goal. Prefer linking evidence to a criterion by criterion_id or criterion_index."
+ "research goal. Prefer linking evidence to a criterion by criterion_id or criterion_index. "
+ "When the evidence comes from one specific tool result, preserve that result's exact "
+ "tool_call_id; the returned evidence_id (ev_...) identifies the goal-ledger row and is "
+ "not a grounding source reference."
)
is_readonly = False
parameters = {
@@ -378,7 +381,14 @@ class AddGoalEvidenceTool(_GoalToolBase):
"type": "string",
"description": "Optional host-injected current run directory. Omit unless provided by the runtime.",
},
- "tool_call_id": {"type": "string", "description": "Optional tool call id for traceability."},
+ "tool_call_id": {
+ "type": "string",
+ "description": (
+ "Optional provenance id of the specific tool result behind this evidence. "
+ "When known, copy its tool_call_id verbatim. Never substitute an evidence_id "
+ "(ev_...), tool name, shortened alias, or invented id."
+ ),
+ },
"source_provider": {"type": "string", "description": "Data or tool provider."},
"source_type": {"type": "string", "description": "Source type, e.g. backtest, market_data, manual_note."},
"source_uri": {"type": "string", "description": "Optional source URI."},
diff --git a/agent/tests/test_goal_tools.py b/agent/tests/test_goal_tools.py
index 37fac4fcb..b2d982c2e 100644
--- a/agent/tests/test_goal_tools.py
+++ b/agent/tests/test_goal_tools.py
@@ -163,6 +163,75 @@ def test_goal_evidence_tool_binds_runtime_artifact(
assert evidence["verification_status"] == "verified"
+def test_goal_evidence_preserves_exact_tool_call_provenance(tmp_path: Path) -> None:
+ """Tool-backed goal evidence keeps the exact source call id beside its own evidence id."""
+ store = GoalStore(tmp_path / "goals.db")
+ start = StartResearchGoalTool(default_session_id="session-1", store=store)
+ add = AddGoalEvidenceTool(default_session_id="session-1", store=store)
+ created = json.loads(
+ start.execute(
+ objective="Audit one tool-backed metric.",
+ criteria=["Record the metric provenance"],
+ )
+ )
+ call_id = "call_iDflHZFxCGQG1VfvfLoNBXCk|fc_0fa4bc82"
+
+ result = json.loads(
+ add.execute(
+ goal_id=created["snapshot"]["goal"]["goal_id"],
+ criterion_index=1,
+ text="The source tool returned the audited metric.",
+ tool_call_id=call_id,
+ source_provider="pytest",
+ source_type="market_data",
+ )
+ )
+
+ evidence = result["evidence"]
+ assert result["status"] == "ok"
+ assert evidence["evidence_id"].startswith("ev_")
+ assert evidence["tool_call_id"] == call_id
+ assert evidence["evidence_id"] != evidence["tool_call_id"]
+ assert result["snapshot"]["evidence"][0]["tool_call_id"] == call_id
+
+
+def test_goal_evidence_can_remain_manual_without_tool_call_id(tmp_path: Path) -> None:
+ """Manual evidence does not acquire an invented tool provenance id."""
+ store = GoalStore(tmp_path / "goals.db")
+ start = StartResearchGoalTool(default_session_id="session-1", store=store)
+ add = AddGoalEvidenceTool(default_session_id="session-1", store=store)
+ created = json.loads(
+ start.execute(
+ objective="Record a manual research note.",
+ criteria=["Record the note"],
+ )
+ )
+
+ result = json.loads(
+ add.execute(
+ goal_id=created["snapshot"]["goal"]["goal_id"],
+ criterion_index=1,
+ text="Manual reasoning note.",
+ source_provider="pytest",
+ source_type="manual_note",
+ )
+ )
+
+ assert result["status"] == "ok"
+ assert result["evidence"]["tool_call_id"] is None
+
+
+def test_goal_evidence_tool_schema_distinguishes_call_and_evidence_ids() -> None:
+ """The always-visible tool schema tells the model which id belongs in grounding provenance."""
+ description = AddGoalEvidenceTool.description
+ call_description = AddGoalEvidenceTool.parameters["properties"]["tool_call_id"]["description"]
+
+ assert "exact tool_call_id" in description
+ assert "evidence_id (ev_...)" in description
+ assert "copy its tool_call_id verbatim" in call_description
+ assert "Never substitute an evidence_id" in call_description
+
+
def test_goal_status_tool_can_cancel_current_goal(tmp_path: Path) -> None:
"""Agent tools can move a current goal to a terminal status."""
store = GoalStore(tmp_path / "goals.db")
@@ -211,3 +280,5 @@ def test_research_goal_skill_is_bundled() -> None:
assert "start_research_goal" in content
assert "add_goal_evidence" in content
+ assert "exact `tool_call_id`" in content
+ assert "`ev_...::field`" in content