|
| 1 | +"""Regression tests: LLM-judge evaluators must send the model name to the LLM |
| 2 | +Gateway exactly as configured, including a "-community-agents" suffix. |
| 3 | +
|
| 4 | +Community/EU tenants' LLM Gateway routing rules are keyed on the suffixed |
| 5 | +model id -- the same id AgentHub sends when it runs the agent itself. |
| 6 | +Stripping the suffix before calling the Gateway causes a 417 "No llm routing |
| 7 | +rule found for product agentsplaygroundfallback in EU using model ..." for |
| 8 | +every Community/EU evaluation run, even though the identical model id works |
| 9 | +fine for the agent. |
| 10 | +""" |
| 11 | + |
| 12 | +import uuid |
| 13 | +from types import SimpleNamespace |
| 14 | +from unittest.mock import AsyncMock, patch |
| 15 | + |
| 16 | +import pytest |
| 17 | + |
| 18 | +from uipath.eval.evaluators.base_legacy_evaluator import LegacyEvaluationCriteria |
| 19 | +from uipath.eval.evaluators.legacy_context_precision_evaluator import ( |
| 20 | + LegacyContextPrecisionEvaluator, |
| 21 | + LegacyContextPrecisionEvaluatorConfig, |
| 22 | +) |
| 23 | +from uipath.eval.evaluators.legacy_faithfulness_evaluator import ( |
| 24 | + LegacyFaithfulnessEvaluator, |
| 25 | + LegacyFaithfulnessEvaluatorConfig, |
| 26 | +) |
| 27 | +from uipath.eval.evaluators.legacy_llm_as_judge_evaluator import ( |
| 28 | + LegacyLlmAsAJudgeEvaluator, |
| 29 | + LegacyLlmAsAJudgeEvaluatorConfig, |
| 30 | +) |
| 31 | +from uipath.eval.evaluators.legacy_trajectory_evaluator import ( |
| 32 | + LegacyTrajectoryEvaluator, |
| 33 | + LegacyTrajectoryEvaluatorConfig, |
| 34 | +) |
| 35 | +from uipath.eval.evaluators.llm_judge_output_evaluator import LLMJudgeOutputEvaluator |
| 36 | +from uipath.eval.evaluators.llm_judge_trajectory_evaluator import ( |
| 37 | + LLMJudgeTrajectoryEvaluator, |
| 38 | +) |
| 39 | +from uipath.eval.models.models import LegacyEvaluatorCategory, LegacyEvaluatorType |
| 40 | + |
| 41 | +COMMUNITY_MODEL = "gpt-5.4-2026-03-05-community-agents" |
| 42 | + |
| 43 | + |
| 44 | +def _fake_tool_call_response(score: float = 90, justification: str = "ok"): |
| 45 | + tool_call = SimpleNamespace( |
| 46 | + arguments={"score": score, "justification": justification} |
| 47 | + ) |
| 48 | + message = SimpleNamespace(tool_calls=[tool_call]) |
| 49 | + choice = SimpleNamespace(message=message) |
| 50 | + return SimpleNamespace(choices=[choice]) |
| 51 | + |
| 52 | + |
| 53 | +def _legacy_context_precision_evaluator() -> LegacyContextPrecisionEvaluator: |
| 54 | + return LegacyContextPrecisionEvaluator( |
| 55 | + id="context-precision", |
| 56 | + config_type=LegacyContextPrecisionEvaluatorConfig, |
| 57 | + evaluation_criteria_type=LegacyEvaluationCriteria, |
| 58 | + justification_type=str, |
| 59 | + category=LegacyEvaluatorCategory.LlmAsAJudge, |
| 60 | + type=LegacyEvaluatorType.ContextPrecision, |
| 61 | + name="Context Precision", |
| 62 | + description="Evaluates context chunk relevance", |
| 63 | + createdAt="2025-01-01T00:00:00Z", |
| 64 | + updatedAt="2025-01-01T00:00:00Z", |
| 65 | + targetOutputKey="*", |
| 66 | + model=COMMUNITY_MODEL, |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +class TestLegacyContextPrecisionEvaluatorSendsConfiguredModel: |
| 71 | + @pytest.mark.asyncio |
| 72 | + async def test_get_structured_llm_response_sends_full_model_name(self): |
| 73 | + evaluator = _legacy_context_precision_evaluator() |
| 74 | + mock_chat_completions = AsyncMock(return_value=_fake_tool_call_response()) |
| 75 | + evaluator.llm = AsyncMock(chat_completions=mock_chat_completions) |
| 76 | + |
| 77 | + await evaluator._get_structured_llm_response("some evaluation prompt") |
| 78 | + |
| 79 | + sent_model = mock_chat_completions.call_args.kwargs["model"] |
| 80 | + assert sent_model == COMMUNITY_MODEL |
| 81 | + |
| 82 | + |
| 83 | +def _legacy_faithfulness_evaluator() -> LegacyFaithfulnessEvaluator: |
| 84 | + return LegacyFaithfulnessEvaluator( |
| 85 | + id="faithfulness", |
| 86 | + config_type=LegacyFaithfulnessEvaluatorConfig, |
| 87 | + evaluation_criteria_type=LegacyEvaluationCriteria, |
| 88 | + justification_type=str, |
| 89 | + category=LegacyEvaluatorCategory.LlmAsAJudge, |
| 90 | + type=LegacyEvaluatorType.Faithfulness, |
| 91 | + name="Faithfulness", |
| 92 | + description="Evaluates faithfulness of claims against context", |
| 93 | + createdAt="2025-01-01T00:00:00Z", |
| 94 | + updatedAt="2025-01-01T00:00:00Z", |
| 95 | + targetOutputKey="*", |
| 96 | + model=COMMUNITY_MODEL, |
| 97 | + ) |
| 98 | + |
| 99 | + |
| 100 | +class TestLegacyFaithfulnessEvaluatorSendsConfiguredModel: |
| 101 | + @pytest.mark.asyncio |
| 102 | + async def test_get_structured_llm_response_sends_full_model_name(self): |
| 103 | + evaluator = _legacy_faithfulness_evaluator() |
| 104 | + mock_chat_completions = AsyncMock(return_value=_fake_tool_call_response()) |
| 105 | + evaluator.llm = AsyncMock(chat_completions=mock_chat_completions) |
| 106 | + |
| 107 | + await evaluator._get_structured_llm_response( |
| 108 | + "some evaluation prompt", "submit_result", {"type": "object"} |
| 109 | + ) |
| 110 | + |
| 111 | + sent_model = mock_chat_completions.call_args.kwargs["model"] |
| 112 | + assert sent_model == COMMUNITY_MODEL |
| 113 | + |
| 114 | + |
| 115 | +class TestLLMJudgeOutputEvaluatorSendsConfiguredModel: |
| 116 | + """Covers LLMJudgeMixin._get_llm_response -- the code path hit by |
| 117 | + 'uipath-llm-judge-output-semantic-similarity' in production.""" |
| 118 | + |
| 119 | + @pytest.mark.asyncio |
| 120 | + async def test_get_llm_response_sends_full_model_name_to_gateway(self): |
| 121 | + config = { |
| 122 | + "name": "TestEvaluator", |
| 123 | + "prompt": "Evaluate {{ActualOutput}} against {{ExpectedOutput}}", |
| 124 | + "model": COMMUNITY_MODEL, |
| 125 | + } |
| 126 | + with patch("uipath.platform.UiPath"): |
| 127 | + evaluator = LLMJudgeOutputEvaluator.model_validate( |
| 128 | + {"evaluatorConfig": config, "id": str(uuid.uuid4())} |
| 129 | + ) |
| 130 | + mock_llm_service = AsyncMock(return_value=_fake_tool_call_response()) |
| 131 | + evaluator.llm_service = mock_llm_service |
| 132 | + |
| 133 | + await evaluator._get_llm_response("some evaluation prompt") |
| 134 | + |
| 135 | + sent_model = mock_llm_service.call_args.kwargs["model"] |
| 136 | + assert sent_model == COMMUNITY_MODEL |
| 137 | + |
| 138 | + |
| 139 | +class TestLLMJudgeTrajectoryEvaluatorSendsConfiguredModel: |
| 140 | + """Covers the same LLMJudgeMixin._get_llm_response via the trajectory |
| 141 | + evaluator -- this is the exact evaluator type from the reported |
| 142 | + production trace ('uipath-llm-judge-trajectory-similarity').""" |
| 143 | + |
| 144 | + @pytest.mark.asyncio |
| 145 | + async def test_get_llm_response_sends_full_model_name_to_gateway(self): |
| 146 | + config = { |
| 147 | + "name": "TestEvaluator", |
| 148 | + "prompt": "Judge {{AgentRunHistory}} against {{ExpectedAgentBehavior}}", |
| 149 | + "model": COMMUNITY_MODEL, |
| 150 | + } |
| 151 | + with patch("uipath.platform.UiPath"): |
| 152 | + evaluator = LLMJudgeTrajectoryEvaluator.model_validate( |
| 153 | + {"evaluatorConfig": config, "id": str(uuid.uuid4())} |
| 154 | + ) |
| 155 | + mock_llm_service = AsyncMock(return_value=_fake_tool_call_response()) |
| 156 | + evaluator.llm_service = mock_llm_service |
| 157 | + |
| 158 | + await evaluator._get_llm_response("some evaluation prompt") |
| 159 | + |
| 160 | + sent_model = mock_llm_service.call_args.kwargs["model"] |
| 161 | + assert sent_model == COMMUNITY_MODEL |
| 162 | + |
| 163 | + |
| 164 | +def _legacy_trajectory_evaluator() -> LegacyTrajectoryEvaluator: |
| 165 | + return LegacyTrajectoryEvaluator( |
| 166 | + id=str(uuid.uuid4()), |
| 167 | + name="Legacy trajectory", |
| 168 | + config_type=LegacyTrajectoryEvaluatorConfig, |
| 169 | + evaluation_criteria_type=LegacyEvaluationCriteria, |
| 170 | + justification_type=str, |
| 171 | + category=LegacyEvaluatorCategory.Trajectory, |
| 172 | + type=LegacyEvaluatorType.Trajectory, |
| 173 | + prompt="History:\n{{AgentRunHistory}}\nExpected:\n{{ExpectedAgentBehavior}}", |
| 174 | + model=COMMUNITY_MODEL, |
| 175 | + createdAt="2026-05-14T00:00:00Z", |
| 176 | + updatedAt="2026-05-14T00:00:00Z", |
| 177 | + ) |
| 178 | + |
| 179 | + |
| 180 | +class TestLegacyTrajectoryEvaluatorSendsConfiguredModel: |
| 181 | + @pytest.mark.asyncio |
| 182 | + async def test_get_llm_response_sends_full_model_name_to_gateway(self): |
| 183 | + evaluator = _legacy_trajectory_evaluator() |
| 184 | + mock_chat_completions = AsyncMock(return_value=_fake_tool_call_response()) |
| 185 | + evaluator.llm = AsyncMock(chat_completions=mock_chat_completions) |
| 186 | + |
| 187 | + await evaluator._get_llm_response("some evaluation prompt") |
| 188 | + |
| 189 | + sent_model = mock_chat_completions.call_args.kwargs["model"] |
| 190 | + assert sent_model == COMMUNITY_MODEL |
| 191 | + |
| 192 | + |
| 193 | +def _legacy_llm_as_judge_evaluator() -> LegacyLlmAsAJudgeEvaluator: |
| 194 | + return LegacyLlmAsAJudgeEvaluator( |
| 195 | + id=str(uuid.uuid4()), |
| 196 | + name="Legacy LLM judge", |
| 197 | + config_type=LegacyLlmAsAJudgeEvaluatorConfig, |
| 198 | + evaluation_criteria_type=LegacyEvaluationCriteria, |
| 199 | + justification_type=str, |
| 200 | + category=LegacyEvaluatorCategory.LlmAsAJudge, |
| 201 | + type=LegacyEvaluatorType.Factuality, |
| 202 | + prompt="Compare {{ActualOutput}} to {{ExpectedOutput}}", |
| 203 | + model=COMMUNITY_MODEL, |
| 204 | + createdAt="2026-05-14T00:00:00Z", |
| 205 | + updatedAt="2026-05-14T00:00:00Z", |
| 206 | + ) |
| 207 | + |
| 208 | + |
| 209 | +class TestLegacyLlmAsAJudgeEvaluatorSendsConfiguredModel: |
| 210 | + @pytest.mark.asyncio |
| 211 | + async def test_get_llm_response_sends_full_model_name_to_gateway(self): |
| 212 | + evaluator = _legacy_llm_as_judge_evaluator() |
| 213 | + mock_chat_completions = AsyncMock(return_value=_fake_tool_call_response()) |
| 214 | + evaluator.llm = AsyncMock(chat_completions=mock_chat_completions) |
| 215 | + |
| 216 | + await evaluator._get_llm_response("some evaluation prompt") |
| 217 | + |
| 218 | + sent_model = mock_chat_completions.call_args.kwargs["model"] |
| 219 | + assert sent_model == COMMUNITY_MODEL |
0 commit comments