evoloop-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. evoloop_cli/__init__.py +3 -0
  2. evoloop_cli/__main__.py +10 -0
  3. evoloop_cli/_skills/evoloop-constitution/SKILL.md +59 -0
  4. evoloop_cli/_skills/evoloop-constitution/references/writing-guide.md +89 -0
  5. evoloop_cli/_skills/evoloop-constitution/templates/config.yaml +52 -0
  6. evoloop_cli/_skills/evoloop-constitution/templates/constitution.md +39 -0
  7. evoloop_cli/_skills/evoloop-evaluate/SKILL.md +85 -0
  8. evoloop_cli/_skills/evoloop-evaluate/schemas/parsed_report.schema.json +170 -0
  9. evoloop_cli/_skills/evoloop-evaluate/scripts/parse_junit_report.py +311 -0
  10. evoloop_cli/_skills/evoloop-evaluate/scripts/parse_pytest_report.py +276 -0
  11. evoloop_cli/_skills/evoloop-evaluate/scripts/parse_report.py +101 -0
  12. evoloop_cli/_skills/evoloop-evaluate/scripts/update_eval_index.py +111 -0
  13. evoloop_cli/_skills/evoloop-evaluate/scripts/validate_parsed_report.py +178 -0
  14. evoloop_cli/_skills/evoloop-evaluate/templates/analysis.md +51 -0
  15. evoloop_cli/_skills/evoloop-evaluate/templates/progress.md +42 -0
  16. evoloop_cli/_skills/evoloop-evaluate/templates/tasks.md +34 -0
  17. evoloop_cli/_skills/evoloop-evolve/SKILL.md +76 -0
  18. evoloop_cli/_skills/evoloop-evolve/scripts/evolve_state.py +333 -0
  19. evoloop_cli/_skills/evoloop-implement/SKILL.md +57 -0
  20. evoloop_cli/_skills/evoloop-implement/scripts/check_scope.py +154 -0
  21. evoloop_cli/_skills/evoloop-implement/scripts/commit_section.py +78 -0
  22. evoloop_cli/_skills/evoloop-init/SKILL.md +95 -0
  23. evoloop_cli/_skills/evoloop-init/scripts/scaffold_evals.py +546 -0
  24. evoloop_cli/_skills/evoloop-init/templates/common/evals/datasets/domain_flows.yaml +33 -0
  25. evoloop_cli/_skills/evoloop-init/templates/common/evaluations/README.md +9 -0
  26. evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/AgentAdapter.java +13 -0
  27. evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/AgenticFlowEvalTest.java +71 -0
  28. evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/DeterministicEvaluators.java +174 -0
  29. evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/EvalFrameworkTest.java +45 -0
  30. evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/FlowRunResult.java +25 -0
  31. evoloop_cli/_skills/evoloop-init/templates/python/evals/__init__.py +1 -0
  32. evoloop_cli/_skills/evoloop-init/templates/python/evals/adapter.py +63 -0
  33. evoloop_cli/_skills/evoloop-init/templates/python/evals/deepagents_adapter.py +223 -0
  34. evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/__init__.py +1 -0
  35. evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/deterministic.py +234 -0
  36. evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/llm_judge.py +189 -0
  37. evoloop_cli/_skills/evoloop-init/templates/python/evals/fakes.py +26 -0
  38. evoloop_cli/_skills/evoloop-init/templates/python/evals/harness.py +100 -0
  39. evoloop_cli/_skills/evoloop-init/templates/python/tests/conftest.py +38 -0
  40. evoloop_cli/_skills/evoloop-init/templates/python/tests/test_agentic_flows.py +36 -0
  41. evoloop_cli/_skills/evoloop-init/templates/python/tests/test_eval_framework.py +175 -0
  42. evoloop_cli/_skills/evoloop-new/SKILL.md +125 -0
  43. evoloop_cli/_skills/evoloop-new/scripts/scaffold_agent.py +911 -0
  44. evoloop_cli/_skills/evoloop-new/templates/common/.evoloop/constitution.md +34 -0
  45. evoloop_cli/_skills/evoloop-new/templates/common/.gitignore +22 -0
  46. evoloop_cli/_skills/evoloop-new/templates/common/AGENTS.md +17 -0
  47. evoloop_cli/_skills/evoloop-new/templates/common/README.md +83 -0
  48. evoloop_cli/_skills/evoloop-new/templates/common/skills/__DOMAIN__/SKILL.md +21 -0
  49. evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/AgenticFlowEvalTest.java +113 -0
  50. evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/EvalFrameworkTest.java +85 -0
  51. evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/Fake__DOMAIN_PASCAL__Client.java +37 -0
  52. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/Application.java +46 -0
  53. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/OpenAiCompatibleRunner.java +433 -0
  54. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +125 -0
  55. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/Application.java +46 -0
  56. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +163 -0
  57. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +18 -0
  58. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/Application.java +15 -0
  59. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +167 -0
  60. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Controller.java +41 -0
  61. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Factory.java +32 -0
  62. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +20 -0
  63. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/resources/application.yml +17 -0
  64. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/Application.java +17 -0
  65. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +159 -0
  66. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Config.java +32 -0
  67. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Controller.java +40 -0
  68. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +25 -0
  69. evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/resources/application.yml +19 -0
  70. evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_custom.gradle +33 -0
  71. evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_langchain4j.gradle +40 -0
  72. evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_micronaut.gradle +52 -0
  73. evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_spring-ai.gradle +45 -0
  74. evoloop_cli/_skills/evoloop-new/templates/java/gradle/settings.gradle +1 -0
  75. evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_custom.xml +57 -0
  76. evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_langchain4j.xml +87 -0
  77. evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_micronaut.xml +101 -0
  78. evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_spring-ai.xml +61 -0
  79. evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/ConversationMemory.java +36 -0
  80. evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/Default__DOMAIN_PASCAL__Client.java +9 -0
  81. evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/DomainRecord.java +10 -0
  82. evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/TurnOutcome.java +15 -0
  83. evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Client.java +8 -0
  84. evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/fakes.py +22 -0
  85. evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/harness_custom.py +186 -0
  86. evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/harness_deepagents.py +100 -0
  87. evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/tests/test_eval_framework.py +196 -0
  88. evoloop_cli/_skills/evoloop-new/templates/python/pyproject.toml +18 -0
  89. evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/__init__.py +13 -0
  90. evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/__main__.py +6 -0
  91. evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/agent_custom.py +209 -0
  92. evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/agent_deepagents.py +61 -0
  93. evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/cli.py +71 -0
  94. evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/client.py +31 -0
  95. evoloop_cli/_skills/evoloop-scenarios/SKILL.md +49 -0
  96. evoloop_cli/_skills/evoloop-scenarios/scripts/validate_scenarios.py +261 -0
  97. evoloop_cli/_skills/evoloop-scenarios/templates/scenario_schema.md +49 -0
  98. evoloop_cli/cli.py +331 -0
  99. evoloop_cli-0.1.0.dist-info/METADATA +214 -0
  100. evoloop_cli-0.1.0.dist-info/RECORD +103 -0
  101. evoloop_cli-0.1.0.dist-info/WHEEL +4 -0
  102. evoloop_cli-0.1.0.dist-info/entry_points.txt +2 -0
  103. evoloop_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,234 @@
1
+ """Deterministic evaluators for agentic flow trajectories and outputs."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from collections.abc import Callable
7
+ from dataclasses import dataclass
8
+ from typing import Any
9
+
10
+ from agentevals.trajectory.match import create_trajectory_match_evaluator
11
+
12
+ from evals.adapter import DomainToolCall, FlowRunResult
13
+
14
+ ArgMatcher = Callable[[dict[str, Any], dict[str, Any]], bool]
15
+ ArgNormalizer = Callable[[dict[str, Any]], dict[str, Any]]
16
+
17
+ # TODO(domain): Register per-tool argument matchers for trajectory_match (optional).
18
+ # Example: TOOL_ARG_MATCHERS = {"lookup_record": _match_record_args}
19
+ TOOL_ARG_MATCHERS: dict[str, ArgMatcher] = {}
20
+
21
+ # TODO(domain): Register per-tool argument normalizers for duplicate-call detection (optional).
22
+ # Example: TOOL_ARG_NORMALIZERS = {"lookup_record": _normalize_record_args}
23
+ TOOL_ARG_NORMALIZERS: dict[str, ArgNormalizer] = {}
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class EvalOutcome:
28
+ """Standardized result for a single evaluator check."""
29
+
30
+ name: str
31
+ passed: bool
32
+ score: float
33
+ reason: str
34
+
35
+
36
+ def _build_reference_trajectory(expected_tool_calls: list[dict[str, Any]]) -> list[dict[str, Any]]:
37
+ if not expected_tool_calls:
38
+ return []
39
+ return [
40
+ {
41
+ "role": "assistant",
42
+ "content": "",
43
+ "tool_calls": [
44
+ {
45
+ "function": {
46
+ "name": tc["name"],
47
+ "arguments": json.dumps(tc.get("args") or {}, sort_keys=True),
48
+ }
49
+ }
50
+ for tc in expected_tool_calls
51
+ ],
52
+ }
53
+ ]
54
+
55
+
56
+ def evaluate_trajectory_match(
57
+ run: FlowRunResult,
58
+ case: dict[str, Any],
59
+ *,
60
+ tool_args_match_overrides: dict[str, ArgMatcher] | None = None,
61
+ ) -> EvalOutcome:
62
+ """Compare captured domain tool-call trajectory against expected reference calls."""
63
+ expected_calls: list[dict[str, Any]] = list(case.get("expected_tool_calls") or [])
64
+ mode: str = case.get("trajectory_match_mode", "unordered")
65
+
66
+ if not expected_calls:
67
+ if mode == "strict":
68
+ passed = len(run.domain_tool_calls) == 0
69
+ reason = (
70
+ "No domain tool calls made as expected."
71
+ if passed
72
+ else f"Expected 0 domain tool calls, got: {[(c.name, c.args) for c in run.domain_tool_calls]}"
73
+ )
74
+ return EvalOutcome(
75
+ name="trajectory_match",
76
+ passed=passed,
77
+ score=1.0 if passed else 0.0,
78
+ reason=reason,
79
+ )
80
+ return EvalOutcome(
81
+ name="trajectory_match",
82
+ passed=True,
83
+ score=1.0,
84
+ reason=f"No mandatory reference tool calls required (mode={mode}).",
85
+ )
86
+
87
+ overrides = tool_args_match_overrides if tool_args_match_overrides is not None else TOOL_ARG_MATCHERS
88
+ evaluator = create_trajectory_match_evaluator(
89
+ trajectory_match_mode=mode,
90
+ tool_args_match_mode="exact",
91
+ tool_args_match_overrides=overrides or None,
92
+ )
93
+ reference_outputs = _build_reference_trajectory(expected_calls)
94
+ result = evaluator(outputs=run.openai_trajectory, reference_outputs=reference_outputs)
95
+ passed = bool(result.get("score"))
96
+ actual_summary = [(c.name, c.args) for c in run.domain_tool_calls]
97
+ expected_summary = [(c["name"], c.get("args", {})) for c in expected_calls]
98
+ reason = (
99
+ f"Trajectory matched ({mode}): {actual_summary}"
100
+ if passed
101
+ else f"Trajectory mismatch ({mode}). Expected {expected_summary}, got {actual_summary}"
102
+ )
103
+ return EvalOutcome(
104
+ name="trajectory_match",
105
+ passed=passed,
106
+ score=1.0 if passed else 0.0,
107
+ reason=reason,
108
+ )
109
+
110
+
111
+ def evaluate_forbidden_and_turn_tools(
112
+ run: FlowRunResult,
113
+ case: dict[str, Any],
114
+ ) -> EvalOutcome:
115
+ """Verify overall forbidden tools and per-turn forbidden/required tool constraints."""
116
+ violations: list[str] = []
117
+
118
+ overall_forbidden = set(case.get("forbidden_tools") or [])
119
+ if overall_forbidden:
120
+ called = [c.name for c in run.domain_tool_calls if c.name in overall_forbidden]
121
+ if called:
122
+ violations.append(f"Forbidden tool(s) called: {called}")
123
+
124
+ for assertion in case.get("turn_assertions") or []:
125
+ turn_idx = int(assertion["turn_index"])
126
+ if turn_idx >= len(run.turns):
127
+ violations.append(f"Turn {turn_idx} missing from run (only {len(run.turns)} turns).")
128
+ continue
129
+
130
+ turn_tool_names = [c.name for c in run.turns[turn_idx].domain_tool_calls]
131
+ turn_forbidden = set(assertion.get("forbidden_tools") or [])
132
+ bad = [t for t in turn_tool_names if t in turn_forbidden]
133
+ if bad:
134
+ violations.append(f"Turn {turn_idx} called forbidden tool(s): {bad}")
135
+
136
+ turn_required = list(assertion.get("required_tools") or [])
137
+ missing = [t for t in turn_required if t not in turn_tool_names]
138
+ if missing:
139
+ violations.append(
140
+ f"Turn {turn_idx} missed required tool(s): {missing} (called: {turn_tool_names})"
141
+ )
142
+
143
+ passed = len(violations) == 0
144
+ return EvalOutcome(
145
+ name="tool_policy",
146
+ passed=passed,
147
+ score=1.0 if passed else 0.0,
148
+ reason="All tool policy and per-turn constraints satisfied."
149
+ if passed
150
+ else "; ".join(violations),
151
+ )
152
+
153
+
154
+ def _canonical_call_key(call: DomainToolCall) -> tuple[int, str, str]:
155
+ normalizer = TOOL_ARG_NORMALIZERS.get(call.name)
156
+ normalized_args = normalizer(dict(call.args)) if normalizer else dict(call.args)
157
+ return (call.turn_index, call.name, json.dumps(normalized_args, sort_keys=True))
158
+
159
+
160
+ def evaluate_efficiency_budget(
161
+ run: FlowRunResult,
162
+ case: dict[str, Any],
163
+ ) -> EvalOutcome:
164
+ """Check domain tool-call budget and detect redundant duplicate tool calls."""
165
+ issues: list[str] = []
166
+ max_calls = case.get("max_tool_calls")
167
+ if max_calls is not None and len(run.domain_tool_calls) > int(max_calls):
168
+ issues.append(
169
+ f"Exceeded max_tool_calls ({len(run.domain_tool_calls)} > {max_calls})."
170
+ )
171
+
172
+ if not case.get("allow_duplicate_calls", False):
173
+ seen: set[tuple[int, str, str]] = set()
174
+ duplicates: list[str] = []
175
+ for call in run.domain_tool_calls:
176
+ key = _canonical_call_key(call)
177
+ if key in seen:
178
+ duplicates.append(f"turn {call.turn_index}: {call.name}({call.args})")
179
+ seen.add(key)
180
+ if duplicates:
181
+ issues.append(f"Duplicate redundant tool call(s) detected: {duplicates}")
182
+
183
+ passed = len(issues) == 0
184
+ return EvalOutcome(
185
+ name="efficiency_budget",
186
+ passed=passed,
187
+ score=1.0 if passed else 0.0,
188
+ reason=f"Within budget ({len(run.domain_tool_calls)} tool calls, no duplicate loops)."
189
+ if passed
190
+ else "; ".join(issues),
191
+ )
192
+
193
+
194
+ def evaluate_groundedness(
195
+ run: FlowRunResult,
196
+ case: dict[str, Any],
197
+ ) -> EvalOutcome:
198
+ """Verify grounded factual tokens appear in the final response and forbidden strings do not."""
199
+ response_lower = run.final_response.lower()
200
+ issues: list[str] = []
201
+
202
+ if not response_lower.strip():
203
+ issues.append("Final agent response is empty.")
204
+ else:
205
+ for group in case.get("grounded_any_of") or []:
206
+ if not any(token.lower() in response_lower for token in group):
207
+ issues.append(f"Expected one of {group} in final response.")
208
+
209
+ for forbidden in case.get("forbidden_substrings") or []:
210
+ if forbidden.lower() in response_lower:
211
+ issues.append(f"Found forbidden substring {forbidden!r} in final response.")
212
+
213
+ passed = len(issues) == 0
214
+ return EvalOutcome(
215
+ name="groundedness",
216
+ passed=passed,
217
+ score=1.0 if passed else 0.0,
218
+ reason="Final response is grounded in expected tool outputs."
219
+ if passed
220
+ else "; ".join(issues),
221
+ )
222
+
223
+
224
+ def run_deterministic_evaluators(
225
+ run: FlowRunResult,
226
+ case: dict[str, Any],
227
+ ) -> list[EvalOutcome]:
228
+ """Run the full deterministic evaluator suite for a flow run."""
229
+ return [
230
+ evaluate_trajectory_match(run, case),
231
+ evaluate_forbidden_and_turn_tools(run, case),
232
+ evaluate_efficiency_budget(run, case),
233
+ evaluate_groundedness(run, case),
234
+ ]
@@ -0,0 +1,189 @@
1
+ """Framework-agnostic LLM-as-a-Judge rubric evaluators backed by Arize Phoenix Evals."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ from typing import Any
8
+
9
+ from phoenix.evals import LLM, create_classifier
10
+
11
+ from evals.adapter import FlowRunResult
12
+ from evals.evaluators.deterministic import EvalOutcome
13
+
14
+ # TODO(domain): Adjust default fallback URL/model or set EVAL_JUDGE_BASE_URL / EVAL_JUDGE_MODEL.
15
+ DEFAULT_JUDGE_BASE_URL = "http://localhost:8080/v1"
16
+ DEFAULT_JUDGE_MODEL = "local-model"
17
+
18
+ # TODO(domain): Customize the judge persona and style guidelines for __DOMAIN_TITLE__.
19
+ TRAJECTORY_QUALITY_TEMPLATE = """You are an expert evaluator of AI __DOMAIN_TITLE__ agents.
20
+ Review the multi-turn conversation and tool-call trajectory below, and judge whether the
21
+ agent followed the required behavior cleanly, efficiently, and honestly.
22
+
23
+ Rubric Criteria:
24
+ {rubric_criteria}
25
+
26
+ Agent Trajectory (grouped by user turn):
27
+ {trajectory}
28
+
29
+ Did the agent's trajectory satisfy the rubric criteria?
30
+ Respond with 'pass' if all key requirements were met, or 'fail' if the agent violated any requirement."""
31
+
32
+ RESPONSE_QUALITY_TEMPLATE = """You are an expert evaluator grading a __DOMAIN_TITLE__ Assistant's final response.
33
+ The assistant must follow these style and accuracy guidelines:
34
+ - Clear, helpful, and concise (human-friendly, not raw tool output)
35
+ - Accurate to tool results (never fabricates data)
36
+ - Honest and transparent when a lookup fails, a service errors, or a request is out of scope
37
+
38
+ Task Rubric:
39
+ {rubric_criteria}
40
+
41
+ Conversation (all turns):
42
+ {conversation}
43
+
44
+ Final Assistant Response:
45
+ {final_response}
46
+
47
+ Does the final response (in the context of the conversation above) meet these quality guidelines?
48
+ Respond with 'pass' or 'fail'."""
49
+
50
+
51
+ def build_judge_llm(
52
+ *,
53
+ base_url: str | None = None,
54
+ model: str | None = None,
55
+ api_key: str | None = None,
56
+ ) -> LLM:
57
+ """Create a Phoenix Evals LLM configured for a local or remote OpenAI-compatible server."""
58
+ resolved_base_url = (
59
+ base_url
60
+ or os.environ.get("EVAL_JUDGE_BASE_URL")
61
+ or os.environ.get("LLM_BASE_URL")
62
+ or DEFAULT_JUDGE_BASE_URL
63
+ )
64
+ resolved_model = (
65
+ model
66
+ or os.environ.get("EVAL_JUDGE_MODEL")
67
+ or os.environ.get("LLM_MODEL")
68
+ or DEFAULT_JUDGE_MODEL
69
+ )
70
+ resolved_api_key = (
71
+ api_key
72
+ or os.environ.get("EVAL_JUDGE_API_KEY")
73
+ or os.environ.get("LLM_API_KEY")
74
+ or "not-needed"
75
+ )
76
+ return LLM(
77
+ provider="openai",
78
+ model=resolved_model,
79
+ base_url=resolved_base_url,
80
+ api_key=resolved_api_key,
81
+ )
82
+
83
+
84
+ def _format_trajectory(run: FlowRunResult) -> str:
85
+ """Group trajectory messages by explicit user turn to avoid turn-boundary miscounts."""
86
+ if not run.turns or not any(t.openai_turn_messages for t in run.turns):
87
+ return json.dumps(run.openai_trajectory, indent=2, ensure_ascii=False)
88
+ structured = [
89
+ {
90
+ "turn": i,
91
+ "user_input": turn.user_input,
92
+ "messages": turn.openai_turn_messages,
93
+ }
94
+ for i, turn in enumerate(run.turns, start=1)
95
+ ]
96
+ return json.dumps(structured, indent=2, ensure_ascii=False)
97
+
98
+
99
+ def _format_conversation(run: FlowRunResult) -> str:
100
+ """Render full multi-turn user/assistant conversation for response quality grading."""
101
+ lines: list[str] = []
102
+ for i, turn in enumerate(run.turns, start=1):
103
+ lines.append(f"Turn {i} User: {turn.user_input}")
104
+ lines.append(f"Turn {i} Assistant: {turn.final_response}")
105
+ return "\n".join(lines)
106
+
107
+
108
+ def _score_to_outcome(name: str, eval_result: Any) -> EvalOutcome:
109
+ score_obj = eval_result[0] if isinstance(eval_result, list) else eval_result
110
+ label = str(getattr(score_obj, "label", "")).strip().lower()
111
+ numeric = getattr(score_obj, "score", None)
112
+ explanation = str(getattr(score_obj, "explanation", "") or f"Judge label: {label}")
113
+ passed = label == "pass" or (numeric is not None and float(numeric) >= 0.5)
114
+ final_score = float(numeric) if numeric is not None else (1.0 if passed else 0.0)
115
+ return EvalOutcome(
116
+ name=name,
117
+ passed=passed,
118
+ score=final_score,
119
+ reason=explanation,
120
+ )
121
+
122
+
123
+ def evaluate_trajectory_quality(
124
+ run: FlowRunResult,
125
+ case: dict[str, Any],
126
+ *,
127
+ judge_llm: LLM | None = None,
128
+ ) -> EvalOutcome:
129
+ """Grade overall multi-turn trajectory quality using an LLM judge."""
130
+ llm = judge_llm or build_judge_llm()
131
+ evaluator = create_classifier(
132
+ name="trajectory_quality",
133
+ prompt_template=TRAJECTORY_QUALITY_TEMPLATE,
134
+ llm=llm,
135
+ choices={"pass": 1.0, "fail": 0.0},
136
+ )
137
+ result = evaluator.evaluate(
138
+ {
139
+ "rubric_criteria": case.get("rubric_criteria", "Follow assistant rules."),
140
+ "trajectory": _format_trajectory(run),
141
+ }
142
+ )
143
+ return _score_to_outcome("trajectory_quality", result)
144
+
145
+
146
+ def evaluate_response_quality(
147
+ run: FlowRunResult,
148
+ case: dict[str, Any],
149
+ *,
150
+ judge_llm: LLM | None = None,
151
+ ) -> EvalOutcome:
152
+ """Grade final response tone, formatting, and honesty using an LLM judge."""
153
+ if not run.final_response.strip():
154
+ return EvalOutcome(
155
+ name="response_quality",
156
+ passed=False,
157
+ score=0.0,
158
+ reason="Final agent response is empty.",
159
+ )
160
+
161
+ llm = judge_llm or build_judge_llm()
162
+ evaluator = create_classifier(
163
+ name="response_quality",
164
+ prompt_template=RESPONSE_QUALITY_TEMPLATE,
165
+ llm=llm,
166
+ choices={"pass": 1.0, "fail": 0.0},
167
+ )
168
+ result = evaluator.evaluate(
169
+ {
170
+ "rubric_criteria": case.get("rubric_criteria", "Follow assistant rules."),
171
+ "conversation": _format_conversation(run),
172
+ "final_response": run.final_response,
173
+ }
174
+ )
175
+ return _score_to_outcome("response_quality", result)
176
+
177
+
178
+ def run_llm_judge_evaluators(
179
+ run: FlowRunResult,
180
+ case: dict[str, Any],
181
+ *,
182
+ judge_llm: LLM | None = None,
183
+ ) -> list[EvalOutcome]:
184
+ """Run all LLM-as-a-Judge rubric evaluators."""
185
+ llm = judge_llm or build_judge_llm()
186
+ return [
187
+ evaluate_trajectory_quality(run, case, judge_llm=llm),
188
+ evaluate_response_quality(run, case, judge_llm=llm),
189
+ ]
@@ -0,0 +1,26 @@
1
+ """Deterministic fake client with fault injection for __DOMAIN_TITLE__ evaluations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Any
7
+
8
+
9
+ @dataclass
10
+ class FakeDomainClient:
11
+ """TODO(domain): Replace with deterministic fixtures for your domain's external services."""
12
+
13
+ fail_mode: str | None = None
14
+ call_log: list[dict[str, Any]] = field(default_factory=list)
15
+
16
+ def _check_faults(self) -> None:
17
+ if self.fail_mode == "service_outage":
18
+ raise RuntimeError("Simulated service outage.")
19
+
20
+ def example_lookup(self, query: str) -> dict[str, Any]:
21
+ self.call_log.append({"method": "example_lookup", "query": query})
22
+ self._check_faults()
23
+ cleaned = query.strip()
24
+ if not cleaned:
25
+ raise ValueError("Query cannot be empty.")
26
+ return {"query": cleaned, "status": "ok"}
@@ -0,0 +1,100 @@
1
+ """Execution harness for single-turn and multi-turn __DOMAIN_TITLE__ flow evaluations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import yaml
9
+
10
+ from .adapter import AgentAdapter, DomainToolCall, FlowRunResult, TurnResult
11
+ from .deepagents_adapter import (
12
+ DeepAgentsAdapter,
13
+ detect_skill_loaded,
14
+ extract_domain_tool_calls,
15
+ extract_text_content,
16
+ to_openai_domain_trajectory,
17
+ )
18
+ from .fakes import FakeDomainClient
19
+
20
+ # TODO(domain): List all domain tool names exposed by your agent.
21
+ DOMAIN_TOOLS: frozenset[str] = frozenset({"example_tool"})
22
+ DEFAULT_DATASET_PATH = Path(__file__).parent / "datasets" / "__DOMAIN___flows.yaml"
23
+
24
+
25
+ def load_flow_cases(path: Path | str = DEFAULT_DATASET_PATH) -> list[dict[str, Any]]:
26
+ """Load evaluation flow cases from a YAML dataset file."""
27
+ dataset_path = Path(path)
28
+ with dataset_path.open("r", encoding="utf-8") as fh:
29
+ data = yaml.safe_load(fh)
30
+ return list((data or {}).get("cases", []))
31
+
32
+
33
+ def build_fake_client(case: dict[str, Any]) -> FakeDomainClient:
34
+ """Instantiate a deterministic fake client configured for a specific flow case."""
35
+ cfg = case.get("fake_client") or {}
36
+ return FakeDomainClient(fail_mode=cfg.get("fail_mode"))
37
+
38
+
39
+ def create_agent_for_eval(
40
+ *,
41
+ client: Any,
42
+ base_url: str | None = None,
43
+ model: str | None = None,
44
+ api_key: str | None = None,
45
+ ) -> Any:
46
+ """TODO(domain): Wire this factory to your project's agent constructor.
47
+
48
+ Ensure your agent configures a checkpointer (e.g., MemorySaver()) for multi-turn state.
49
+ """
50
+ raise NotImplementedError(
51
+ "Wire evals/harness.py:create_agent_for_eval() to your project's agent factory."
52
+ )
53
+
54
+
55
+ def build_adapter() -> AgentAdapter:
56
+ """Return the configured AgentAdapter (defaults to DeepAgentsAdapter)."""
57
+ return DeepAgentsAdapter(create_agent_for_eval)
58
+
59
+
60
+ async def run_flow_case(
61
+ case: dict[str, Any],
62
+ *,
63
+ adapter: AgentAdapter | None = None,
64
+ base_url: str | None = None,
65
+ model: str | None = None,
66
+ api_key: str | None = None,
67
+ thread_id: str | None = None,
68
+ ) -> FlowRunResult:
69
+ """Run a single-turn or multi-turn evaluation case via the configured AgentAdapter."""
70
+ resolved_adapter = adapter or build_adapter()
71
+ fake_client = build_fake_client(case)
72
+ return await resolved_adapter.run_case(
73
+ case,
74
+ fake_client=fake_client,
75
+ domain_tools=DOMAIN_TOOLS,
76
+ base_url=base_url,
77
+ model=model,
78
+ api_key=api_key,
79
+ thread_id=thread_id,
80
+ )
81
+
82
+
83
+ __all__ = [
84
+ "DEFAULT_DATASET_PATH",
85
+ "DOMAIN_TOOLS",
86
+ "AgentAdapter",
87
+ "DeepAgentsAdapter",
88
+ "DomainToolCall",
89
+ "FlowRunResult",
90
+ "TurnResult",
91
+ "build_adapter",
92
+ "build_fake_client",
93
+ "create_agent_for_eval",
94
+ "detect_skill_loaded",
95
+ "extract_domain_tool_calls",
96
+ "extract_text_content",
97
+ "load_flow_cases",
98
+ "run_flow_case",
99
+ "to_openai_domain_trajectory",
100
+ ]
@@ -0,0 +1,38 @@
1
+ """Pytest configuration and CLI options for agentic flow evaluations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+
7
+
8
+ def pytest_addoption(parser: pytest.Parser) -> None:
9
+ parser.addoption(
10
+ "--run-live-agent",
11
+ action="store_true",
12
+ default=False,
13
+ help="Run end-to-end agentic flow evals against the configured LLM server.",
14
+ )
15
+ parser.addoption(
16
+ "--run-judge",
17
+ action="store_true",
18
+ default=False,
19
+ help="Also run LLM-as-a-Judge rubric evaluators on live agent flows.",
20
+ )
21
+
22
+
23
+ def pytest_configure(config: pytest.Config) -> None:
24
+ config.addinivalue_line(
25
+ "markers",
26
+ "live_agent: marks end-to-end tests that require a running LLM server (use --run-live-agent).",
27
+ )
28
+
29
+
30
+ def pytest_collection_modifyitems(
31
+ config: pytest.Config, items: list[pytest.Item]
32
+ ) -> None:
33
+ if config.getoption("--run-live-agent"):
34
+ return
35
+ skip_live = pytest.mark.skip(reason="Pass --run-live-agent to run live LLM flow evals.")
36
+ for item in items:
37
+ if "live_agent" in item.keywords:
38
+ item.add_marker(skip_live)
@@ -0,0 +1,36 @@
1
+ """End-to-end agentic flow evaluation suite.
2
+
3
+ Run with:
4
+ uv run pytest tests/test_agentic_flows.py --run-live-agent
5
+ uv run pytest tests/test_agentic_flows.py --run-live-agent --run-judge
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import pytest
11
+
12
+ from evals.evaluators.deterministic import run_deterministic_evaluators
13
+ from evals.evaluators.llm_judge import run_llm_judge_evaluators
14
+ from evals.harness import load_flow_cases, run_flow_case
15
+
16
+ FLOW_CASES = load_flow_cases()
17
+
18
+
19
+ @pytest.mark.live_agent
20
+ @pytest.mark.asyncio
21
+ @pytest.mark.parametrize("case", FLOW_CASES, ids=[c["id"] for c in FLOW_CASES])
22
+ async def test_agentic_flow(case: dict, request: pytest.FixtureRequest) -> None:
23
+ run_result = await run_flow_case(case)
24
+
25
+ outcomes = run_deterministic_evaluators(run_result, case)
26
+ if request.config.getoption("--run-judge"):
27
+ outcomes.extend(run_llm_judge_evaluators(run_result, case))
28
+
29
+ failures = [f"[{o.name}] {o.reason}" for o in outcomes if not o.passed]
30
+ assert not failures, (
31
+ f"Flow '{case['id']}' failed {len(failures)} check(s):\n"
32
+ + "\n".join(f" - {f}" for f in failures)
33
+ + f"\nFinal response: {run_result.final_response!r}"
34
+ + f"\nDomain tool calls: {[(c.turn_index, c.name, c.args) for c in run_result.domain_tool_calls]}"
35
+ + f"\nSkill loaded (SKILL.md): {run_result.skill_loaded}"
36
+ )