mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-30 19:02:16 +00:00
* chore: create learning subdirectory structure (routing, agents, intelligence) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: extract classify_query to routing/_utils.py Move the classify_query() function and its regex patterns into a shared utility module so multiple routing policies can import it without depending on the full trace_policy module. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: move routing files to learning/routing/ subdirectory Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: create LearnedRouterPolicy merging trace-driven + SFT routing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add conditional Algolia DocSearch integration Add Algolia DocSearch as an optional search upgrade — native lunr.js search remains the default until credentials are configured. Includes CDN assets, Jinja2 conditional config injection, init script with graceful fallback, light/dark theme CSS, improved search tokenization for snake_case/dotted identifiers, and search boosts for key pages. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: move agent_evolver and skill_discovery to learning/agents/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: move learning/orchestrator to learning/intelligence/orchestrator Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: delete removed learning policies, rewrite __init__.py, clean up api_routes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add SFT/GRPO/DSPy/GEPA config dataclasses, update LearningConfig Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add general-purpose SFT trainer (intelligence/sft_trainer.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: update stale imports in multi_model_router example Update imports to use new learning/routing/ paths after the subdirectory reorganization. Replace BanditRouterPolicy with LearnedRouterPolicy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add general-purpose GRPO trainer (intelligence/grpo_trainer.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add DSPy agent optimizer (agents/dspy_optimizer.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add GEPA agent optimizer (agents/gepa_optimizer.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add learning-dspy and learning-gepa optional dependency extras Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: update integration test to check for learned policy instead of grpo Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: clean up stale APIs and unused params in examples - deep_research: remove system_prompt and max_turns params not accepted by Jarvis.ask(), inline system prompt into the query instead - doc_qa: remove unused --top-k CLI arg that was never passed to the API - multi_model_router: fix select_model() call to match single-arg signature Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: import SFT/GRPO trainers in intelligence/__init__.py for registry Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: remove .md file changes from PR Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: restore search boost frontmatter for key docs pages Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
128 lines
4.1 KiB
Python
128 lines
4.1 KiB
Python
"""Tests for orchestrator policy model."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from openjarvis.learning.intelligence.orchestrator.policy_model import (
|
|
OrchestratorPolicyModel,
|
|
)
|
|
from openjarvis.learning.intelligence.orchestrator.types import (
|
|
EpisodeState,
|
|
OrchestratorAction,
|
|
OrchestratorObservation,
|
|
)
|
|
|
|
|
|
class TestParseOutput:
|
|
"""Test _parse_output without loading a real model."""
|
|
|
|
def _model(self) -> OrchestratorPolicyModel:
|
|
return OrchestratorPolicyModel()
|
|
|
|
def test_valid_thought_tool_input(self):
|
|
m = self._model()
|
|
text = (
|
|
"THOUGHT: I need to calculate 2+2\n"
|
|
"TOOL: calculator\n"
|
|
"INPUT: 2+2"
|
|
)
|
|
po = m._parse_output(text, ["calculator", "think"])
|
|
assert po.thought == "I need to calculate 2+2"
|
|
assert po.tool_name == "calculator"
|
|
assert po.tool_input == "2+2"
|
|
assert po.is_final_answer is False
|
|
|
|
def test_final_answer(self):
|
|
m = self._model()
|
|
text = (
|
|
"THOUGHT: I have the result\n"
|
|
"FINAL_ANSWER: 42"
|
|
)
|
|
po = m._parse_output(text, ["calculator"])
|
|
assert po.is_final_answer is True
|
|
assert po.tool_input == "42"
|
|
|
|
def test_final_answer_with_space(self):
|
|
m = self._model()
|
|
text = "FINAL ANSWER: the result is 7"
|
|
po = m._parse_output(text, ["calculator"])
|
|
assert po.is_final_answer is True
|
|
|
|
def test_missing_fields_fallback(self):
|
|
m = self._model()
|
|
text = "just some random output"
|
|
po = m._parse_output(text, ["calculator", "think"])
|
|
# Should fallback to first available tool
|
|
assert po.tool_name == "calculator"
|
|
assert po.thought == "No thought provided"
|
|
|
|
def test_invalid_tool_name_fallback(self):
|
|
m = self._model()
|
|
text = "THOUGHT: reason\nTOOL: nonexistent_tool\nINPUT: hello"
|
|
po = m._parse_output(text, ["calculator", "think"])
|
|
assert po.tool_name == "calculator" # fallback
|
|
|
|
def test_case_insensitive_tool_match(self):
|
|
m = self._model()
|
|
text = "THOUGHT: reason\nTOOL: Calculator\nINPUT: 5+5"
|
|
po = m._parse_output(text, ["calculator", "think"])
|
|
assert po.tool_name == "calculator"
|
|
|
|
def test_empty_tools_list(self):
|
|
m = self._model()
|
|
text = "THOUGHT: reason\nTOOL: calc\nINPUT: 1"
|
|
po = m._parse_output(text, [])
|
|
assert po.tool_name == "unknown"
|
|
|
|
|
|
class TestBuildPrompt:
|
|
def test_includes_task(self):
|
|
m = OrchestratorPolicyModel()
|
|
state = EpisodeState(initial_prompt="What is 2+2?")
|
|
prompt = m._build_prompt(state, ["calculator"])
|
|
assert "What is 2+2?" in prompt
|
|
|
|
def test_includes_tools(self):
|
|
m = OrchestratorPolicyModel()
|
|
state = EpisodeState(initial_prompt="q")
|
|
prompt = m._build_prompt(state, ["calculator", "think"])
|
|
assert "calculator" in prompt
|
|
assert "think" in prompt
|
|
|
|
def test_includes_history(self):
|
|
m = OrchestratorPolicyModel()
|
|
state = EpisodeState(initial_prompt="q")
|
|
action = OrchestratorAction(
|
|
thought="use calc", tool_name="calculator", tool_input="2+2"
|
|
)
|
|
obs = OrchestratorObservation(content="4")
|
|
state.add_turn(action, obs)
|
|
prompt = m._build_prompt(state, ["calculator"])
|
|
assert "Turn 1:" in prompt
|
|
assert "use calc" in prompt
|
|
|
|
def test_format_instructions(self):
|
|
m = OrchestratorPolicyModel()
|
|
state = EpisodeState(initial_prompt="q")
|
|
prompt = m._build_prompt(state, ["calculator"])
|
|
assert "THOUGHT:" in prompt
|
|
assert "TOOL:" in prompt
|
|
assert "INPUT:" in prompt
|
|
|
|
|
|
class TestPredictActionRequiresModel:
|
|
def test_raises_without_model(self):
|
|
m = OrchestratorPolicyModel()
|
|
state = EpisodeState(initial_prompt="q")
|
|
with pytest.raises(RuntimeError, match="Cannot generate"):
|
|
m.predict_action(state, ["calculator"])
|
|
|
|
|
|
class TestRepr:
|
|
def test_repr(self):
|
|
m = OrchestratorPolicyModel()
|
|
r = repr(m)
|
|
assert "OrchestratorPolicyModel" in r
|
|
assert "None" in r
|