Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/openjarvis/learning/spec_search/diagnose/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
from typing import Any

from openjarvis.core.types import Message, Role
from openjarvis.learning.spec_search.diagnose.types import DiagnosticTool


Expand Down Expand Up @@ -278,7 +279,7 @@ def _run_self_on_task(task_id: str, max_tokens: int = 2048) -> str:
if sample is None:
return json.dumps({"error": f"Task {task_id} not found in benchmark"})
response = teacher_engine.generate(
messages=[{"role": "user", "content": sample.query}],
messages=[Message(role=Role.USER, content=sample.query)],
model=teacher_model,
max_tokens=max_tokens,
)
Expand Down
3 changes: 2 additions & 1 deletion src/openjarvis/learning/spec_search/plan/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@

AGENT pillar:
- replace_system_prompt: {{"new_content": "You are a helpful assistant.\\n..."}}
- patch_system_prompt: {{"diff": "--- a/prompt.md\\n+++ b/prompt.md\\n@@ ...\\n"}}
- patch_system_prompt: {{"diff": "--- a/prompt.md\\n+++ b/prompt.md\\n\
@@ -3,1 +3,1 @@\\n-Old line\\n+New line\\n"}}
- set_agent_class: {{"agent": "simple", "new_class": "react"}}
- set_agent_param: {{"agent": "native_react", "param": "max_turns", "value": 10}}
- edit_few_shot_exemplars: {{"agent": "native_react", \
Expand Down
48 changes: 48 additions & 0 deletions tests/learning/spec_search/test_diagnose_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,51 @@ def test_returns_benchmark_tasks(self, tmp_path: Path) -> None:
parsed = json.loads(result)
assert len(parsed) == 1
assert parsed[0]["task_id"] == "task-001"


class TestRunSelfOnTask:
"""Tests for the run_self_on_task diagnostic tool."""

def test_passes_message_objects_to_generate(self, tmp_path: Path) -> None:
from openjarvis.core.types import Message, Role
from openjarvis.learning.spec_search.diagnose.tools import (
build_diagnostic_tools,
)

captured_messages: list[Message] = []

def _mock_generate(*, messages: list[Message], **_: Any) -> dict[str, Any]:
captured_messages.extend(messages)
return {
"content": "ok",
"cost_usd": 0.0,
"usage": {"total_tokens": 1},
}

teacher_engine = MagicMock()
teacher_engine.generate.side_effect = _mock_generate

tools = build_diagnostic_tools(
trace_store=_make_stub_trace_store(),
config=_make_stub_config(tmp_path),
benchmark_samples=_make_stub_benchmark_samples(),
student_runner=MagicMock(),
teacher_engine=teacher_engine,
teacher_model="claude-opus-4-6",
judge=MagicMock(),
session_id="session-001",
)
run_self_on_task = next(t for t in tools if t.name == "run_self_on_task")
result = run_self_on_task.fn(task_id="task-001")

teacher_engine.generate.assert_called_once()
assert captured_messages
assert isinstance(captured_messages[0], Message)
assert captured_messages[0].role == Role.USER

parsed = json.loads(result)
assert parsed["task_id"] == "task-001"
assert parsed["output"] == "ok"
assert parsed["cost_usd"] == 0.0
assert parsed["tokens_used"] == 1
assert "error" not in parsed