File size: 2,048 Bytes
a31cea6 7c51be5 a31cea6 7c51be5 a31cea6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
"""Tests for Magentic Judge termination logic."""
from unittest.mock import patch
import pytest
from src.agents.magentic_agents import create_judge_agent
pytestmark = pytest.mark.unit
def test_judge_agent_has_termination_instructions() -> None:
"""Judge agent must be created with explicit instructions for early termination."""
with patch("src.agents.magentic_agents.get_domain_config") as mock_config:
# Mock config to return empty strings so we test the hardcoded critical section
mock_config.return_value.judge_system_prompt = ""
with patch("src.agents.magentic_agents.ChatAgent") as mock_chat_agent_cls:
with patch("src.agents.magentic_agents.settings") as mock_settings:
mock_settings.openai_api_key = "sk-dummy"
mock_settings.openai_model = "gpt-4"
create_judge_agent()
# Verify ChatAgent was initialized with correct instructions
assert mock_chat_agent_cls.called
call_kwargs = mock_chat_agent_cls.call_args.kwargs
instructions = call_kwargs.get("instructions", "")
# Verify critical sections from Solution B
assert "CRITICAL OUTPUT FORMAT" in instructions
assert "SUFFICIENT EVIDENCE" in instructions
assert "confidence >= 70%" in instructions
assert "STOP SEARCHING" in instructions
assert "Delegate to ReportAgent NOW" in instructions
def test_judge_agent_uses_reasoning_temperature() -> None:
"""Judge agent should be initialized with temperature=1.0."""
with patch("src.agents.magentic_agents.ChatAgent") as mock_chat_agent_cls:
with patch("src.agents.magentic_agents.settings") as mock_settings:
mock_settings.openai_api_key = "sk-dummy"
mock_settings.openai_model = "gpt-4"
create_judge_agent()
call_kwargs = mock_chat_agent_cls.call_args.kwargs
assert call_kwargs.get("temperature") == 1.0
|