"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
feat(agent): let the agent edit a research goal's objective in place
Lanre Shittuec06a0f37261
diff --git a/agent/SKILL.md b/agent/SKILL.mdindex a8cc29215..44372b9e6 100644--- a/agent/SKILL.md+++ b/agent/SKILL.md@@ -142,6 +142,7 @@ Use `load_skill(name)` to access full methodology docs with code templates.| `start_research_goal` | Create an auditable research goal | None || `get_research_goal` | Read the current research goal | None || `add_goal_evidence` | Attach evidence to a research goal | None |+| `update_research_goal` | Edit a research goal's objective or summary in place | None || `update_research_goal_status` | Update goal lifecycle status | None || `backtest` | Run vectorized backtest engine | None* || `paper_trade_step` | Deterministic paper-trading matching engine; never places real orders | None* |diff --git a/agent/src/skills/research-goal/SKILL.md b/agent/src/skills/research-goal/SKILL.mdindex 73b9a047c..09ec8094a 100644--- a/agent/src/skills/research-goal/SKILL.md+++ b/agent/src/skills/research-goal/SKILL.md@@ -26,7 +26,8 @@ Do not start a goal for a tiny one-shot answer unless the user explicitly asks.3. Before continuing an existing task, call `get_research_goal`.4. After a market-data lookup, backtest, document read, web source, or manual reasoning step, call `add_goal_evidence`.5. Link evidence to a criterion using `criterion_id` or `criterion_index`.-6. When all required criteria have been audited, call `update_research_goal_status`.+6. If the objective wording needs tightening or correcting mid-research, call `update_research_goal` instead of starting a new goal; it edits the objective in place and keeps existing criteria and evidence.+7. When all required criteria have been audited, call `update_research_goal_status`.## Criteria Templatediff --git a/agent/src/tools/__init__.py b/agent/src/tools/__init__.pyindex e6e281cfc..eedf1648a 100644--- a/agent/src/tools/__init__.py+++ b/agent/src/tools/__init__.py@@ -129,6 +129,7 @@ def build_registry(GetResearchGoalTool,StartResearchGoalTool,UpdateResearchGoalStatusTool,+ UpdateResearchGoalTool,)from src.tools.autopilot_tool import RunResearchAutopilotToolfrom src.tools.remember_tool import RememberTool@@ -140,6 +141,7 @@ def build_registry(GetResearchGoalTool,AddGoalEvidenceTool,UpdateResearchGoalStatusTool,+ UpdateResearchGoalTool,}# Tools that need the host session id injected: they create or mutate the# session's research goal, and the LLM never knows the session id.diff --git a/agent/src/tools/goal_tool.py b/agent/src/tools/goal_tool.pyindex c9b37bca3..34647af60 100644--- a/agent/src/tools/goal_tool.py+++ b/agent/src/tools/goal_tool.py@@ -314,6 +314,75 @@ class UpdateResearchGoalStatusTool(_GoalToolBase):return _json_error(str(exc))+class UpdateResearchGoalTool(_GoalToolBase):+ """Edit the current research goal's objective or summary in place."""++ name = "update_research_goal"+ description = (+ "Refine the current finance research goal's objective or display summary "+ "without superseding it. Use this to tighten or correct the objective wording "+ "as research progresses; it keeps the same goal id, criteria, and evidence. "+ "To replace the goal entirely, use start_research_goal instead."+ )+ is_readonly = False+ parameters = {+ "type": "object",+ "properties": {+ "session_id": {+ "type": "string",+ "description": "Optional session id. Omit when the host runtime injected the current session.",+ },+ "goal_id": {"type": "string", "description": "Optional goal id. Defaults to the current goal."},+ "expected_goal_id": {+ "type": "string",+ "description": "Optional stale-write guard. Defaults to goal_id.",+ },+ "objective": {"type": "string", "description": "Replacement research objective."},+ "ui_summary": {"type": "string", "description": "Replacement compact display summary."},+ },+ }++ def execute(self, **kwargs: Any) -> str:+ """Edit the current research goal's objective or summary.++ Args:+ **kwargs: Tool arguments from the model.++ Returns:+ JSON envelope with the updated goal snapshot or an error.+ """+ session_id = self._session_id(kwargs)+ if not session_id:+ return _json_error("session_id is required")+ objective = kwargs.get("objective")+ ui_summary = kwargs.get("ui_summary")+ if objective is None and ui_summary is None:+ return _json_error("objective or ui_summary is required")+ try:+ snapshot = self._store.get_current_snapshot(session_id)+ goal_id = str(kwargs.get("goal_id") or "").strip()+ if not goal_id:+ if snapshot is None:+ return _json_error("no current goal for this session", error_type="not_found")+ goal_id = str(snapshot["goal"]["goal_id"])+ expected_goal_id = str(kwargs.get("expected_goal_id") or goal_id).strip()+ self._store.update_goal(+ session_id=session_id,+ goal_id=goal_id,+ expected_goal_id=expected_goal_id,+ objective=objective,+ ui_summary=ui_summary,+ )+ updated = self._store.get_goal_snapshot(goal_id)+ if updated is not None:+ self._emit("goal.updated", {"goal": updated["goal"], "snapshot": updated})+ return json.dumps({"status": "ok", "snapshot": updated}, ensure_ascii=False)+ except StaleGoalError as exc:+ return _json_error(str(exc), error_type="stale_goal")+ except (TypeError, ValueError) as exc:+ return _json_error(str(exc))++class GetResearchGoalTool(_GoalToolBase):"""Read the current research goal snapshot."""diff --git a/agent/tests/test_goal_tools.py b/agent/tests/test_goal_tools.pyindex 2120cae43..1f40cb9d5 100644--- a/agent/tests/test_goal_tools.py+++ b/agent/tests/test_goal_tools.py@@ -13,6 +13,7 @@ from src.tools.goal_tool import (GetResearchGoalTool,StartResearchGoalTool,UpdateResearchGoalStatusTool,+ UpdateResearchGoalTool,)@@ -309,6 +310,61 @@ def test_goal_status_tool_can_cancel_current_goal(tmp_path: Path) -> None:assert store.get_current_snapshot("session-1") is None+def test_update_goal_tool_edits_objective_without_resetting_progress(tmp_path: Path) -> None:+ """The agent can refine an objective in place, unlike start_research_goal+ which would mint a new goal and reset all criteria to pending.+ """+ store = GoalStore(tmp_path / "goals.db")+ start = StartResearchGoalTool(default_session_id="session-1", store=store)+ add_evidence = AddGoalEvidenceTool(default_session_id="session-1", store=store)+ update = UpdateResearchGoalTool(default_session_id="session-1", store=store)++ created = json.loads(+ start.execute(+ objective="Evaluate NVDA momentum as a research-only thesis.",+ criteria=["Define thesis", "Check price action"],+ )+ )+ goal_id = created["snapshot"]["goal"]["goal_id"]+ add_evidence.execute(criterion_index=1, text="NVDA shows strong momentum.")++ result = json.loads(+ update.execute(objective="Evaluate NVDA and AMD momentum as a research-only thesis.")+ )++ assert result["status"] == "ok"+ snapshot = result["snapshot"]+ assert snapshot["goal"]["goal_id"] == goal_id+ assert snapshot["goal"]["objective"] == "Evaluate NVDA and AMD momentum as a research-only thesis."+ assert snapshot["evidence_count"] == 1+ assert [c["status"] for c in snapshot["criteria"]] == ["covered", "pending"]+++def test_update_goal_tool_requires_a_field_to_change(tmp_path: Path) -> None:+ store = GoalStore(tmp_path / "goals.db")+ start = StartResearchGoalTool(default_session_id="session-1", store=store)+ update = UpdateResearchGoalTool(default_session_id="session-1", store=store)+ start.execute(objective="Evaluate NVDA momentum.", criteria=["Define thesis"])++ result = json.loads(update.execute())++ assert result == {"status": "error", "error_type": "validation", "error": "objective or ui_summary is required"}+++def test_update_goal_tool_rejects_a_stale_expected_goal_id(tmp_path: Path) -> None:+ store = GoalStore(tmp_path / "goals.db")+ start = StartResearchGoalTool(default_session_id="session-1", store=store)+ update = UpdateResearchGoalTool(default_session_id="session-1", store=store)+ start.execute(objective="Evaluate NVDA momentum.", criteria=["Define thesis"])++ result = json.loads(+ update.execute(objective="A different objective.", expected_goal_id="not-the-real-id")+ )++ assert result["status"] == "error"+ assert result["error_type"] == "stale_goal"++def test_registry_injects_goal_event_callback() -> None:"""SessionService can build goal tools that emit through the event bus."""from src.tools import build_registry