agentx-python 0.6.35__tar.gz → 0.6.36__tar.gz

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.

Potentially problematic release.


This version of agentx-python might be problematic. Click here for more details.

Files changed (80) hide show
  1. {agentx_python-0.6.35 → agentx_python-0.6.36}/PKG-INFO +1 -1
  2. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/agentx.py +12 -2
  3. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/client.py +28 -3
  4. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/datasets.py +4 -0
  5. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/evaluation_settings.py +17 -1
  6. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/models.py +1 -1
  7. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/runner.py +16 -11
  8. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/client.py +16 -1
  9. agentx_python-0.6.36/agentx/monitor/judge_scorers.py +334 -0
  10. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/online_evaluators.py +21 -2
  11. agentx_python-0.6.36/agentx/version.py +1 -0
  12. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx_python.egg-info/PKG-INFO +1 -1
  13. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx_python.egg-info/SOURCES.txt +2 -0
  14. agentx_python-0.6.36/tests/test_judge_scorers.py +270 -0
  15. agentx_python-0.6.35/agentx/version.py +0 -1
  16. {agentx_python-0.6.35 → agentx_python-0.6.36}/LICENSE +0 -0
  17. {agentx_python-0.6.35 → agentx_python-0.6.36}/README.md +0 -0
  18. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/__init__.py +0 -0
  19. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/cli.py +0 -0
  20. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/__init__.py +0 -0
  21. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/_term.py +0 -0
  22. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/adapters/__init__.py +0 -0
  23. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/adapters/http_endpoint.py +0 -0
  24. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/adapters/precomputed.py +0 -0
  25. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/adapters/raw.py +0 -0
  26. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/prompts.py +0 -0
  27. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/reporting.py +0 -0
  28. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/results.py +0 -0
  29. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/tool_schemas.py +0 -0
  30. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/evaluations/tracing.py +0 -0
  31. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/exceptions.py +0 -0
  32. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/export.py +0 -0
  33. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/feedback.py +0 -0
  34. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/__init__.py +0 -0
  35. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/_traced_call.py +0 -0
  36. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/anthropic.py +0 -0
  37. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/autogen.py +0 -0
  38. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/crewai.py +0 -0
  39. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/databricks.py +0 -0
  40. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/google_adk.py +0 -0
  41. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/google_genai.py +0 -0
  42. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/langchain.py +0 -0
  43. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/litellm.py +0 -0
  44. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/llamaindex.py +0 -0
  45. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/moveworks.py +0 -0
  46. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/openai.py +0 -0
  47. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/integrations/openai_agents.py +0 -0
  48. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/__init__.py +0 -0
  49. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/agents.py +0 -0
  50. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/models.py +0 -0
  51. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/patterns.py +0 -0
  52. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/profile.py +0 -0
  53. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/scorers.py +0 -0
  54. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/sessions.py +0 -0
  55. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/monitor/signals.py +0 -0
  56. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/outcomes.py +0 -0
  57. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/projects.py +0 -0
  58. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/py.typed +0 -0
  59. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/resources/__init__.py +0 -0
  60. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/resources/agent.py +0 -0
  61. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/resources/conversation.py +0 -0
  62. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/resources/workforce.py +0 -0
  63. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/traces.py +0 -0
  64. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/tracing/__init__.py +0 -0
  65. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/tracing/ci_types.py +0 -0
  66. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/tracing/ingest_client.py +0 -0
  67. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/tracing/tracer.py +0 -0
  68. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx/util.py +0 -0
  69. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx_python.egg-info/dependency_links.txt +0 -0
  70. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx_python.egg-info/entry_points.txt +0 -0
  71. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx_python.egg-info/not-zip-safe +0 -0
  72. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx_python.egg-info/requires.txt +0 -0
  73. {agentx_python-0.6.35 → agentx_python-0.6.36}/agentx_python.egg-info/top_level.txt +0 -0
  74. {agentx_python-0.6.35 → agentx_python-0.6.36}/setup.cfg +0 -0
  75. {agentx_python-0.6.35 → agentx_python-0.6.36}/setup.py +0 -0
  76. {agentx_python-0.6.35 → agentx_python-0.6.36}/tests/test_deep_dive_fixes.py +0 -0
  77. {agentx_python-0.6.35 → agentx_python-0.6.36}/tests/test_integration.py +0 -0
  78. {agentx_python-0.6.35 → agentx_python-0.6.36}/tests/test_integrations.py +0 -0
  79. {agentx_python-0.6.35 → agentx_python-0.6.36}/tests/test_selfhost_analysis_fallback.py +0 -0
  80. {agentx_python-0.6.35 → agentx_python-0.6.36}/tests/test_span_tree.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentx-python
3
- Version: 0.6.35
3
+ Version: 0.6.36
4
4
  Summary: Official Python SDK for AgentX (https://www.agentx.so/)
5
5
  Home-page: https://github.com/AgentX-ai/AgentX-python
6
6
  Author: Robin Wang and AgentX Team
@@ -94,8 +94,18 @@ class AgentX:
94
94
 
95
95
  @classmethod
96
96
  def from_env(cls) -> "AgentX":
97
- """Create an AgentX client using AGENTX_API_KEY (and optionally AGENTX_API_BASE_URL) from the environment."""
98
- return cls()
97
+ """Create an AgentX client from the environment: AGENTX_API_KEY plus, for the base URL,
98
+ the first of AGENTX_API_BASE_URL / AGENTX_SELFHOST_BASE_URL / BASE_URL that is set.
99
+ The fallbacks match the conventions the self-host samples and .env files already use,
100
+ so from_env works wherever an explicit AgentX(base_url=...) would."""
101
+ import os
102
+
103
+ base_url = (
104
+ os.getenv("AGENTX_API_BASE_URL")
105
+ or os.getenv("AGENTX_SELFHOST_BASE_URL")
106
+ or os.getenv("BASE_URL")
107
+ )
108
+ return cls(base_url=base_url) if base_url else cls()
99
109
 
100
110
  def get_agent(self, id: str) -> Agent:
101
111
  url = f"{self.base_url or api_base()}/access/agents/{id}"
@@ -59,6 +59,15 @@ class AgentXValidationError(AgentXEvaluationsError):
59
59
  pass
60
60
 
61
61
 
62
+ def _resolve_scorer_id(scorer_id: Optional[str], evaluation_settings_id: Optional[str]) -> Optional[str]:
63
+ """One grader, two spellings: ``scorer_id`` is the post-consolidation name for what the wire
64
+ still calls ``evaluationSettingsId`` (the ids are identical by design). Both kwargs are
65
+ accepted everywhere a run picks its grader; passing both with different values is a bug."""
66
+ if scorer_id and evaluation_settings_id and scorer_id != evaluation_settings_id:
67
+ raise ValueError("Pass either scorer_id or evaluation_settings_id (they are the same id), not two different ids")
68
+ return scorer_id or evaluation_settings_id
69
+
70
+
62
71
  class EvaluationsClient:
63
72
  def __init__(
64
73
  self,
@@ -100,11 +109,21 @@ class EvaluationsClient:
100
109
  from agentx.evaluations.prompts import PromptClient
101
110
 
102
111
  self.datasets = DatasetClient(self)
103
- self.settings = EvaluationSettingsClient(self)
112
+ # Legacy view of an LLM Judge Scorer's offline profile - constructed lazily so its
113
+ # DeprecationWarning fires on first USE, not for every client that never touches it.
114
+ self._settings: "EvaluationSettingsClient | None" = None
104
115
  self.prompts = PromptClient(self)
105
116
  from agentx.evaluations.tool_schemas import ToolSchemaClient
106
117
  self.tool_schemas = ToolSchemaClient(self)
107
118
 
119
+ @property
120
+ def settings(self) -> "EvaluationSettingsClient":
121
+ if self._settings is None:
122
+ from agentx.evaluations.evaluation_settings import EvaluationSettingsClient
123
+
124
+ self._settings = EvaluationSettingsClient(self)
125
+ return self._settings
126
+
108
127
  # ------------------------------------------------------------------
109
128
  # Low-level HTTP
110
129
  # ------------------------------------------------------------------
@@ -275,10 +294,16 @@ class EvaluationsClient:
275
294
  dataset_id: str,
276
295
  subject: EvaluationSubject,
277
296
  python_version: Optional[str] = None,
297
+ scorer_id: Optional[str] = None,
278
298
  evaluation_settings_id: Optional[str] = None,
279
299
  ) -> EvaluationRun:
300
+ """``scorer_id`` names the LLM Judge Scorer grading this run (its id doubles as the
301
+ wire's ``evaluationSettingsId``). ``evaluation_settings_id`` is the pre-consolidation
302
+ alias and keeps working."""
280
303
  from agentx.version import VERSION
281
304
 
305
+ grader_id = _resolve_scorer_id(scorer_id, evaluation_settings_id)
306
+
282
307
  payload = {
283
308
  "datasetId": dataset_id,
284
309
  "evaluationSubject": subject.model_dump(by_alias=True, exclude_none=True),
@@ -290,8 +315,8 @@ class EvaluationsClient:
290
315
  "pythonVersion": python_version or _python_version(),
291
316
  },
292
317
  }
293
- if evaluation_settings_id:
294
- payload["evaluationSettingsId"] = evaluation_settings_id
318
+ if grader_id:
319
+ payload["evaluationSettingsId"] = grader_id
295
320
  data = self._request("POST", "/runs", json=self._with_workspace(payload))
296
321
  return EvaluationRun(**data)
297
322
 
@@ -290,6 +290,7 @@ class DatasetClient:
290
290
  rouge_score: bool = False,
291
291
  similarity_model: Optional[str] = None,
292
292
  sovereignty_models: Optional[List[str]] = None,
293
+ code_scorers: Optional[List[Dict[str, Any]]] = None,
293
294
  ) -> DatasetBuilder:
294
295
  return DatasetBuilder(
295
296
  self._client,
@@ -307,6 +308,9 @@ class DatasetClient:
307
308
  rouge_score=rouge_score,
308
309
  similarity_model=similarity_model,
309
310
  sovereignty_models=sovereignty_models,
311
+ # Was documented (evaluation/code-scorers.mdx) but not forwarded - DatasetBuilder
312
+ # itself always accepted it. Fixed with the judge-scorer unification.
313
+ code_scorers=code_scorers,
310
314
  )
311
315
 
312
316
  def from_csv(self, path: str, name: str, **kwargs) -> DatasetBuilder:
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import logging
4
+ import warnings
4
5
  from typing import Any, Dict, List, Optional, TYPE_CHECKING
5
6
 
6
7
  from agentx.evaluations.models import EvaluationSettings
@@ -81,10 +82,25 @@ class EvaluationSettingsBuilder:
81
82
 
82
83
 
83
84
  class EvaluationSettingsClient:
84
- """Thin wrapper surfaced as client.evaluations.settings."""
85
+ """Thin wrapper surfaced as ``client.evaluations.settings``.
86
+
87
+ Note: an evaluation-settings record is the judge rubric + OFFLINE profile of an
88
+ **LLM Judge Scorer** - the unified entity at ``client.monitor.judge_scorers``, which also
89
+ carries the optional online (live-traffic) profile. This client keeps working unchanged;
90
+ prefer ``judge_scorers`` for new code so both profiles live in one place -
91
+ ``client.monitor.judge_scorers.builder(...)`` has the same snake_case ergonomics as the
92
+ builder below, plus tool_context, thresholds, and the live profile in one call."""
85
93
 
86
94
  def __init__(self, client: "EvaluationsClient"):
87
95
  self._client = client
96
+ # Soft deprecation: hidden by default (DeprecationWarning), visible under -W or pytest.
97
+ warnings.warn(
98
+ "client.evaluations.settings is the legacy view of an LLM Judge Scorer's offline "
99
+ "profile; prefer client.monitor.judge_scorers, which manages the judge rubric, "
100
+ "offline profile, and online (live-traffic) profile as one entity.",
101
+ DeprecationWarning,
102
+ stacklevel=3,
103
+ )
88
104
 
89
105
  def builder(
90
106
  self,
@@ -94,7 +94,7 @@ class Dataset(BaseModel):
94
94
 
95
95
  class EvaluationSettings(BaseModel):
96
96
  """A standalone, reusable grading config - no dataset/questions attached.
97
- Created via ``client.evaluations.settings.builder(...).publish()`` and run
97
+ Created via ``client.monitor.judge_scorers.builder(...).publish()`` (or the legacy ``client.evaluations.settings.builder``) and run
98
98
  against any dataset by passing its id as ``evaluation_settings_id`` to
99
99
  ``client.evaluations.run(...)``."""
100
100
 
@@ -421,10 +421,15 @@ class EvaluationsRunner:
421
421
  def __init__(self, client: EvaluationsClient):
422
422
  self._client = client
423
423
  self.datasets = client.datasets
424
- self.settings = client.settings
425
424
  self.prompts = client.prompts
426
425
  self.tool_schemas = client.tool_schemas
427
426
 
427
+ @property
428
+ def settings(self):
429
+ # Deferred: touching client.settings eagerly here would fire its legacy-surface
430
+ # DeprecationWarning for every runner, used or not.
431
+ return self._client.settings
432
+
428
433
  def list_models(self, provider: Optional[str] = None) -> List[ModelInfo]:
429
434
  """List the LLM models AgentX supports - the same set selectable for
430
435
  the Sovereignty & Portability Index. Pass ``provider`` (e.g. "Google")
@@ -482,24 +487,24 @@ class EvaluationsRunner:
482
487
  self,
483
488
  dataset_id: str,
484
489
  subject: Union[Dict[str, Any], EvaluationSubject],
490
+ scorer_id: Optional[str] = None,
485
491
  evaluation_settings_id: Optional[str] = None,
486
492
  ) -> EvaluationRunContext:
487
- """Start a run of ``dataset_id`` against ``subject``. Pass
488
- ``evaluation_settings_id`` to grade against a standalone, reusable
489
- config (created via ``client.evaluations.settings.builder(...)``)
490
- instead of the dataset's own default config."""
493
+ """Start a run of ``dataset_id`` against ``subject``. Pass ``scorer_id`` (an LLM Judge
494
+ Scorer's id, e.g. from ``client.monitor.judge_scorers``) to grade with a specific
495
+ scorer instead of the dataset's default. ``evaluation_settings_id`` is the
496
+ pre-consolidation alias for the same id and keeps working."""
497
+ from agentx.evaluations.client import _resolve_scorer_id
498
+
491
499
  if isinstance(subject, dict):
492
500
  subject = EvaluationSubject(**subject)
493
501
 
502
+ grader_id = _resolve_scorer_id(scorer_id, evaluation_settings_id)
494
503
  dataset = self._client.get_dataset(dataset_id)
495
504
  evaluation_settings = (
496
- self._client.get_evaluation_settings(evaluation_settings_id)
497
- if evaluation_settings_id
498
- else None
499
- )
500
- run = self._client.init_run(
501
- dataset_id, subject, evaluation_settings_id=evaluation_settings_id
505
+ self._client.get_evaluation_settings(grader_id) if grader_id else None
502
506
  )
507
+ run = self._client.init_run(dataset_id, subject, scorer_id=grader_id)
503
508
  logger.info(
504
509
  "Started evaluation run %s on dataset %s (%d case(s), %d repetition(s))",
505
510
  run.run_id,
@@ -88,8 +88,15 @@ class MonitorClient:
88
88
  # Handed this client's own resolved API root, never the process-global default, so a
89
89
  # second AgentX() with a different base_url can't re-point it (deep-dive bug #1).
90
90
  self.scorers = ScorersClient(api_key=api_key, base_url=self._api_root())
91
+ from agentx.monitor.judge_scorers import JudgeScorersClient
92
+ # The unified LLM Judge Scorer (rubric + offline/online profiles in one entity) - the
93
+ # surface that matches the product; evaluations.settings and online_evaluators below
94
+ # remain as its profile-level views.
95
+ self.judge_scorers = JudgeScorersClient(api_key=api_key, base_url=self._api_root())
91
96
  self.profile = MonitorProfileClient(self)
92
- self.online_evaluators = MonitorOnlineEvaluatorClient(self)
97
+ # Legacy view of an LLM Judge Scorer's online profile - constructed lazily so its
98
+ # DeprecationWarning fires on first USE, not for every client that never touches it.
99
+ self._online_evaluators: "MonitorOnlineEvaluatorClient | None" = None
93
100
  from agentx.monitor.sessions import MonitorSessionClient
94
101
  from agentx.monitor.agents import MonitorAgentClient
95
102
  self.sessions = MonitorSessionClient(self)
@@ -173,6 +180,14 @@ class MonitorClient:
173
180
  data = self._request("POST", "/online-evaluators", json=self._with_workspace(payload))
174
181
  return MonitorOnlineEvaluator(**data["evaluator"])
175
182
 
183
+ @property
184
+ def online_evaluators(self) -> "MonitorOnlineEvaluatorClient":
185
+ if self._online_evaluators is None:
186
+ from agentx.monitor.online_evaluators import MonitorOnlineEvaluatorClient
187
+
188
+ self._online_evaluators = MonitorOnlineEvaluatorClient(self)
189
+ return self._online_evaluators
190
+
176
191
  def list_online_evaluators(self) -> List[MonitorOnlineEvaluator]:
177
192
  data = self._request("GET", "/online-evaluators", params=self._workspace_params())
178
193
  return [MonitorOnlineEvaluator(**e) for e in data.get("evaluators", [])]
@@ -0,0 +1,334 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from typing import Any, Dict, List, Optional
5
+
6
+ import requests
7
+
8
+ from agentx.util import api_base, get_headers
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+ _SENTINEL: Any = object()
13
+
14
+
15
+ class AgentXJudgeScorersError(Exception):
16
+ pass
17
+
18
+
19
+ class JudgeScorer(dict):
20
+ """Wire object for the unified LLM Judge Scorer (dict subclass so unknown fields
21
+ round-trip). Convenience properties expose the pieces scripts reach for most."""
22
+
23
+ @property
24
+ def id(self) -> str:
25
+ return self["_id"]
26
+
27
+ @property
28
+ def name(self) -> str:
29
+ return self["name"]
30
+
31
+ @property
32
+ def judge(self) -> Dict[str, Any]:
33
+ return self.get("judge", {})
34
+
35
+ @property
36
+ def offline(self) -> Dict[str, Any]:
37
+ return self.get("offline", {})
38
+
39
+ @property
40
+ def online(self) -> Optional[Dict[str, Any]]:
41
+ return self.get("online")
42
+
43
+ @property
44
+ def online_profile_id(self) -> Optional[str]:
45
+ online = self.online
46
+ return online.get("profileId") if online else None
47
+
48
+
49
+ class JudgeScorersClient:
50
+ """Surfaced as ``client.monitor.judge_scorers``: the unified LLM Judge Scorer.
51
+
52
+ One scorer = one judge rubric (``judge``: acceptance/rejection/evaluation criteria, judge
53
+ prompt, judge model) + two setting profiles:
54
+
55
+ - ``offline`` - how dataset runs grade with it (repetitions, similarity metrics, code
56
+ scorers, default/status). The scorer's ``id`` is exactly what
57
+ ``client.evaluations.run(dataset_id, scorer_id=scorer.id)`` takes.
58
+ - ``online`` - whether/how it scores live traffic (enabled, sample rate, scope,
59
+ alert threshold). ``None`` means offline-only.
60
+
61
+ Strictly one online profile per scorer. This supersedes the split between
62
+ ``client.evaluations.settings`` (the offline half) and ``client.monitor.online_evaluators``
63
+ (the online half) - both keep working, but this is the surface that matches the product.
64
+
65
+ Example::
66
+
67
+ scorer = client.monitor.judge_scorers.create(
68
+ "Support quality",
69
+ judge={"acceptanceCriteria": "Concrete, correct, cites the policy."},
70
+ online={"enabled": True, "sampleRate": 0.2, "alertThreshold": 6},
71
+ )
72
+ client.evaluations.run(dataset_id, subject, scorer_id=scorer.id)
73
+ cal = client.monitor.judge_scorers.calibration(scorer.id)
74
+ """
75
+
76
+ def __init__(self, api_key: Optional[str] = None, base_url: Optional[str] = None):
77
+ self._api_key = api_key
78
+ # Captured once at construction so two clients with different bases can coexist.
79
+ self._base_url = (base_url or api_base()).rstrip("/")
80
+
81
+ def _request(self, method: str, path: str, json: Any = None, timeout: int = 60) -> Any:
82
+ resp = requests.request(
83
+ method,
84
+ f"{self._base_url}/agent-monitoring{path}",
85
+ headers={**get_headers(self._api_key), "Content-Type": "application/json"},
86
+ json=json,
87
+ timeout=timeout,
88
+ )
89
+ if resp.status_code >= 400:
90
+ try:
91
+ detail = resp.json().get("error", resp.reason)
92
+ except ValueError:
93
+ detail = resp.reason
94
+ raise AgentXJudgeScorersError(f"Judge scorer request failed ({resp.status_code}): {detail}")
95
+ return resp.json() if resp.text else {}
96
+
97
+ # ------------------------------------------------------------------
98
+ # CRUD
99
+ # ------------------------------------------------------------------
100
+
101
+ def builder(
102
+ self,
103
+ name: str,
104
+ description: Optional[str] = None,
105
+ *,
106
+ # Judge rubric (shared by every surface that runs this scorer)
107
+ acceptance_criteria: Optional[str] = None,
108
+ rejection_criteria: Optional[str] = None,
109
+ evaluation_criteria: Optional[str] = None,
110
+ judge_prompt: Optional[str] = None,
111
+ judge_model: Optional[str] = None,
112
+ tool_context: Optional[str] = None,
113
+ # Offline profile (dataset-run grading)
114
+ number_of_requests: int = 1,
115
+ vector_similarity: bool = False,
116
+ jaccard_similarity: bool = False,
117
+ bleu_score: bool = False,
118
+ rouge_score: bool = False,
119
+ similarity_model: Optional[str] = None,
120
+ sovereignty_models: Optional[List[str]] = None,
121
+ thresholds: Optional[Dict[str, Any]] = None,
122
+ code_scorers: Optional[List[Dict[str, Any]]] = None,
123
+ is_default: bool = False,
124
+ # Online profile (live traffic). live=True enables scoring immediately - every check is
125
+ # a real judge call on your own key.
126
+ live: bool = False,
127
+ sample_rate: float = 0.1,
128
+ scope: str = "trace",
129
+ alert_threshold: Optional[float] = 5,
130
+ severity: str = "medium",
131
+ agent_ids: Optional[List[str]] = None,
132
+ idle_seconds: int = 120,
133
+ ) -> "JudgeScorerBuilder":
134
+ """Snake_case builder with ``.publish()``, the unified successor of
135
+ ``client.evaluations.settings.builder(...)`` - same offline fields (plus ``thresholds``,
136
+ ``tool_context``) and, new here, the online profile in the same call. The scorer the
137
+ builder publishes is one entity: its ``.id`` is what ``client.evaluations.run(...,
138
+ scorer_id=...)`` takes, and its live profile is what online scoring keys on."""
139
+ judge: Dict[str, Any] = {}
140
+ for key, value in (
141
+ ("acceptanceCriteria", acceptance_criteria),
142
+ ("rejectionCriteria", rejection_criteria),
143
+ ("evaluationCriteria", evaluation_criteria),
144
+ ("judgePrompt", judge_prompt),
145
+ ("judgeModel", judge_model),
146
+ ("toolContext", tool_context),
147
+ ):
148
+ if value is not None:
149
+ judge[key] = value
150
+ offline: Dict[str, Any] = {"numberOfRequests": number_of_requests, "isDefault": is_default}
151
+ if vector_similarity:
152
+ offline["vectorSimilarity"] = (
153
+ {"enabled": True, "model": similarity_model} if similarity_model else {"enabled": True}
154
+ )
155
+ if jaccard_similarity:
156
+ offline["jaccardSimilarity"] = {"enabled": True}
157
+ if bleu_score:
158
+ offline["bleuScore"] = {"enabled": True}
159
+ if rouge_score:
160
+ offline["rougeScore"] = {"enabled": True}
161
+ if sovereignty_models is not None:
162
+ offline["sovereigntyIndex"] = {"enabled": bool(sovereignty_models), "models": sovereignty_models}
163
+ if thresholds is not None:
164
+ offline["thresholds"] = thresholds
165
+ if code_scorers is not None:
166
+ offline["codeScorers"] = code_scorers
167
+ online: Optional[Dict[str, Any]] = None
168
+ if live:
169
+ online = {
170
+ "enabled": True,
171
+ "sampleRate": sample_rate,
172
+ "scope": scope,
173
+ "alertThreshold": alert_threshold,
174
+ "severity": severity,
175
+ "idleSeconds": idle_seconds,
176
+ }
177
+ if agent_ids:
178
+ online["scopeMode"] = "selected"
179
+ online["agentIds"] = agent_ids
180
+ return JudgeScorerBuilder(self, name=name, description=description, judge=judge, offline=offline, online=online)
181
+
182
+ def create(
183
+ self,
184
+ name: str,
185
+ *,
186
+ description: Optional[str] = None,
187
+ judge: Optional[Dict[str, Any]] = None,
188
+ offline: Optional[Dict[str, Any]] = None,
189
+ online: Optional[Dict[str, Any]] = None,
190
+ ) -> JudgeScorer:
191
+ """Create a scorer. ``online=None`` (default) creates it offline-only; pass e.g.
192
+ ``online={"enabled": True, "sampleRate": 0.1, "alertThreshold": 5}`` to score live
193
+ traffic from the start. Section dicts use the wire's camelCase keys."""
194
+ payload: Dict[str, Any] = {"name": name}
195
+ if description is not None:
196
+ payload["description"] = description
197
+ if judge is not None:
198
+ payload["judge"] = judge
199
+ if offline is not None:
200
+ payload["offline"] = offline
201
+ if online is not None:
202
+ payload["online"] = online
203
+ return JudgeScorer(self._request("POST", "/judge-scorers", json=payload)["judgeScorer"])
204
+
205
+ def get(self, scorer_id: str) -> JudgeScorer:
206
+ return JudgeScorer(self._request("GET", f"/judge-scorers/{scorer_id}")["judgeScorer"])
207
+
208
+ def list(self) -> List[JudgeScorer]:
209
+ return [JudgeScorer(s) for s in self._request("GET", "/judge-scorers").get("judgeScorers", [])]
210
+
211
+ def update(
212
+ self,
213
+ scorer_id: str,
214
+ *,
215
+ name: Optional[str] = None,
216
+ description: Optional[str] = None,
217
+ judge: Optional[Dict[str, Any]] = None,
218
+ offline: Optional[Dict[str, Any]] = None,
219
+ online: Any = _SENTINEL,
220
+ ) -> JudgeScorer:
221
+ """Sparse update: only the sections you pass change. ``online={...}`` upserts the
222
+ online profile (this is how an offline-only scorer goes live); ``online=None``
223
+ detaches it (refused for the built-in Session Baseline Judge)."""
224
+ payload: Dict[str, Any] = {}
225
+ if name is not None:
226
+ payload["name"] = name
227
+ if description is not None:
228
+ payload["description"] = description
229
+ if judge is not None:
230
+ payload["judge"] = judge
231
+ if offline is not None:
232
+ payload["offline"] = offline
233
+ if online is not _SENTINEL:
234
+ payload["online"] = online
235
+ return JudgeScorer(self._request("PUT", f"/judge-scorers/{scorer_id}", json=payload)["judgeScorer"])
236
+
237
+ def delete(self, scorer_id: str) -> None:
238
+ """Delete the scorer: rubric, version history, and online profile together.
239
+ Irreversible; refused for the built-in Session Baseline Judge."""
240
+ self._request("DELETE", f"/judge-scorers/{scorer_id}")
241
+
242
+ # ------------------------------------------------------------------
243
+ # Online-profile pass-throughs (calibration / tuning / ratings / events)
244
+ # These endpoints key on the online profile's id, resolved here so callers only ever
245
+ # handle the scorer id.
246
+ # ------------------------------------------------------------------
247
+
248
+ def _profile_id(self, scorer_id: str) -> str:
249
+ scorer = self.get(scorer_id)
250
+ profile_id = scorer.online_profile_id
251
+ if not profile_id:
252
+ raise AgentXJudgeScorersError(
253
+ f"Judge scorer {scorer_id!r} has no online profile - calibration/tuning/ratings "
254
+ "cover live-traffic scoring. Give it one first: "
255
+ "update(scorer_id, online={'enabled': True})."
256
+ )
257
+ return profile_id
258
+
259
+ def calibration(self, scorer_id: str, window: str = "7d") -> dict:
260
+ """How this scorer's verdicts compare against recorded ground truth (triage
261
+ corrections, outcomes, end-user votes) over the window."""
262
+ return self._request("GET", f"/online-evaluators/{self._profile_id(scorer_id)}/calibration?window={window}")
263
+
264
+ def tune(self, scorer_id: str, window: str = "7d") -> dict:
265
+ """Propose a rewrite of the rubric from calibration disagreements (LLM call, slow)."""
266
+ data = self._request(
267
+ "POST", f"/online-evaluators/{self._profile_id(scorer_id)}/tune", json={"window": window}, timeout=300
268
+ )
269
+ # The wire wraps the proposal ({"proposal": {...}}); unwrap like the legacy client so
270
+ # proposal["reasoning"] / the criteria fields are directly addressable.
271
+ return data.get("proposal", data) if isinstance(data, dict) else data
272
+
273
+ def validate_tuning(self, scorer_id: str, criteria: Dict[str, Any], window: str = "7d") -> dict:
274
+ """Re-judge the disagreement + control cases with candidate criteria (LLM calls, slow)."""
275
+ # The wire takes the criteria fields at the TOP level of the body, not nested.
276
+ return self._request(
277
+ "POST",
278
+ f"/online-evaluators/{self._profile_id(scorer_id)}/tune/validate",
279
+ json={**criteria, "window": window},
280
+ timeout=600,
281
+ )
282
+
283
+ def publish_tuning(self, scorer_id: str, criteria: Dict[str, Any]) -> dict:
284
+ """Write tuned criteria onto the scorer's rubric - it applies everywhere the scorer is
285
+ used: online scoring, offline dataset runs, and the playground."""
286
+ return self._request(
287
+ "POST", f"/online-evaluators/{self._profile_id(scorer_id)}/tune/publish", json=dict(criteria)
288
+ )
289
+
290
+ def ratings(self, scorer_id: str, window: str = "7d") -> "List[OnlineEvaluatorRatingPoint]":
291
+ """Bucketed average-rating-over-time for this scorer's live checks - same typed points
292
+ the legacy online_evaluators client returns, so scripts migrate without shape changes."""
293
+ from agentx.monitor.models import OnlineEvaluatorRatingPoint
294
+
295
+ data = self._request("GET", f"/online-evaluators/{self._profile_id(scorer_id)}/ratings?window={window}")
296
+ return [OnlineEvaluatorRatingPoint(**p) for p in data.get("points", [])]
297
+
298
+ def events(self, scorer_id: str, window: str = "7d") -> "List[OnlineEvaluatorEvent]":
299
+ """Individually scored traces behind the ratings series, worst-rated first - typed, same
300
+ as the legacy online_evaluators client."""
301
+ from agentx.monitor.models import OnlineEvaluatorEvent
302
+
303
+ data = self._request("GET", f"/online-evaluators/{self._profile_id(scorer_id)}/events?window={window}")
304
+ return [OnlineEvaluatorEvent(**e) for e in data.get("events", [])]
305
+
306
+
307
+ class JudgeScorerBuilder:
308
+ """Assembled by :meth:`JudgeScorersClient.builder`; ``.publish()`` creates the scorer."""
309
+
310
+ def __init__(
311
+ self,
312
+ client: "JudgeScorersClient",
313
+ *,
314
+ name: str,
315
+ description: Optional[str],
316
+ judge: Dict[str, Any],
317
+ offline: Dict[str, Any],
318
+ online: Optional[Dict[str, Any]],
319
+ ):
320
+ self._client = client
321
+ self._name = name
322
+ self._description = description
323
+ self._judge = judge
324
+ self._offline = offline
325
+ self._online = online
326
+
327
+ def publish(self) -> JudgeScorer:
328
+ return self._client.create(
329
+ self._name,
330
+ description=self._description,
331
+ judge=self._judge or None,
332
+ offline=self._offline or None,
333
+ online=self._online,
334
+ )
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import logging
4
+ import warnings
4
5
  from typing import Any, Dict, List, Optional, TYPE_CHECKING
5
6
 
6
7
  from agentx.monitor.models import MonitorOnlineEvaluator, OnlineEvaluatorRatingPoint, OnlineEvaluatorEvent
@@ -17,7 +18,12 @@ class MonitorOnlineEvaluatorBuilder:
17
18
  ``evaluation_settings_id`` must reference an existing Evaluator config (criteria, judge
18
19
  prompt, judge model), the same config datasets/Evaluate runs use, see
19
20
  ``client.evaluations.settings.builder(...)``.
20
- """
21
+
22
+ Note: an online evaluator is the ONLINE profile of an **LLM Judge Scorer** - the unified
23
+ entity at ``client.monitor.judge_scorers``. Strictly one profile per config since the
24
+ unification: binding a config that is already another evaluator's profile transparently
25
+ binds a fresh copy of it instead (the response's ``evaluationSettingsId`` is the copy).
26
+ This surface keeps working unchanged; prefer ``judge_scorers`` for new code."""
21
27
 
22
28
  def __init__(
23
29
  self,
@@ -60,10 +66,23 @@ class MonitorOnlineEvaluatorBuilder:
60
66
 
61
67
 
62
68
  class MonitorOnlineEvaluatorClient:
63
- """Thin wrapper surfaced as ``client.monitor.online_evaluators``."""
69
+ """Thin wrapper surfaced as ``client.monitor.online_evaluators``.
70
+
71
+ Note: an online evaluator is the ONLINE (live-traffic) profile of an **LLM Judge Scorer** -
72
+ the unified entity at ``client.monitor.judge_scorers``, which also carries the judge rubric
73
+ and the offline profile. This client keeps working unchanged; prefer ``judge_scorers`` for
74
+ new code so both profiles live in one place."""
64
75
 
65
76
  def __init__(self, client: "MonitorClient"):
66
77
  self._client = client
78
+ # Soft deprecation: hidden by default (DeprecationWarning), visible under -W or pytest.
79
+ warnings.warn(
80
+ "client.monitor.online_evaluators is the legacy view of an LLM Judge Scorer's "
81
+ "online profile; prefer client.monitor.judge_scorers, which manages the judge "
82
+ "rubric, offline profile, and online profile as one entity.",
83
+ DeprecationWarning,
84
+ stacklevel=3,
85
+ )
67
86
 
68
87
  def builder(
69
88
  self,
@@ -0,0 +1 @@
1
+ VERSION = "0.6.36"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentx-python
3
- Version: 0.6.35
3
+ Version: 0.6.36
4
4
  Summary: Official Python SDK for AgentX (https://www.agentx.so/)
5
5
  Home-page: https://github.com/AgentX-ai/AgentX-python
6
6
  Author: Robin Wang and AgentX Team
@@ -46,6 +46,7 @@ agentx/integrations/openai_agents.py
46
46
  agentx/monitor/__init__.py
47
47
  agentx/monitor/agents.py
48
48
  agentx/monitor/client.py
49
+ agentx/monitor/judge_scorers.py
49
50
  agentx/monitor/models.py
50
51
  agentx/monitor/online_evaluators.py
51
52
  agentx/monitor/patterns.py
@@ -71,5 +72,6 @@ agentx_python.egg-info/top_level.txt
71
72
  tests/test_deep_dive_fixes.py
72
73
  tests/test_integration.py
73
74
  tests/test_integrations.py
75
+ tests/test_judge_scorers.py
74
76
  tests/test_selfhost_analysis_fallback.py
75
77
  tests/test_span_tree.py
@@ -0,0 +1,270 @@
1
+ """Unit tests for the unified LLM Judge Scorer surface (client.monitor.judge_scorers) and the
2
+ dataset-builder code_scorers forwarding fix - wire-level, no engine required (requests is
3
+ monkeypatched; the engine-side contract is pinned by the engine's own
4
+ judgeScorers.integration.test.ts)."""
5
+
6
+ from typing import Any, Dict, List, Optional
7
+
8
+ import pytest
9
+
10
+ from agentx.monitor.judge_scorers import AgentXJudgeScorersError, JudgeScorersClient
11
+
12
+
13
+ class FakeResponse:
14
+ def __init__(self, payload: Dict[str, Any], status_code: int = 200):
15
+ self._payload = payload
16
+ self.status_code = status_code
17
+ self.text = "x"
18
+ self.reason = "reason"
19
+
20
+ def json(self) -> Dict[str, Any]:
21
+ return self._payload
22
+
23
+
24
+ @pytest.fixture()
25
+ def recorded(monkeypatch):
26
+ calls: List[Dict[str, Any]] = []
27
+ responses: List[FakeResponse] = []
28
+
29
+ def fake_request(method, url, headers=None, json=None, timeout=None):
30
+ calls.append({"method": method, "url": url, "json": json})
31
+ return responses.pop(0) if responses else FakeResponse({"judgeScorer": {"_id": "s1", "name": "n"}})
32
+
33
+ monkeypatch.setattr("agentx.monitor.judge_scorers.requests.request", fake_request)
34
+ return calls, responses
35
+
36
+
37
+ def make_client() -> JudgeScorersClient:
38
+ return JudgeScorersClient(api_key="k", base_url="http://engine:4700/api/v1")
39
+
40
+
41
+ def test_create_hits_the_unified_route_with_sections(recorded):
42
+ calls, _ = recorded
43
+ make_client().create(
44
+ "Support quality",
45
+ judge={"acceptanceCriteria": "Concrete."},
46
+ online={"enabled": True, "sampleRate": 0.2},
47
+ )
48
+ assert calls[0]["method"] == "POST"
49
+ assert calls[0]["url"].endswith("/agent-monitoring/judge-scorers")
50
+ assert calls[0]["json"] == {
51
+ "name": "Support quality",
52
+ "judge": {"acceptanceCriteria": "Concrete."},
53
+ "online": {"enabled": True, "sampleRate": 0.2},
54
+ }
55
+
56
+
57
+ def test_update_distinguishes_online_none_from_online_absent(recorded):
58
+ calls, _ = recorded
59
+ client = make_client()
60
+ client.update("s1", judge={"judgePrompt": "p"})
61
+ assert "online" not in calls[0]["json"] # absent section untouched
62
+
63
+ client.update("s1", online=None)
64
+ assert calls[1]["json"] == {"online": None} # explicit detach
65
+
66
+
67
+ def test_online_passthroughs_resolve_the_profile_id(recorded):
68
+ calls, responses = recorded
69
+ responses.append(FakeResponse({"judgeScorer": {"_id": "s1", "name": "n", "online": {"profileId": "prof-9"}}}))
70
+ responses.append(FakeResponse({"agreementRate": 0.5}))
71
+ result = make_client().calibration("s1", window="24h")
72
+ assert result == {"agreementRate": 0.5}
73
+ assert calls[1]["url"].endswith("/agent-monitoring/online-evaluators/prof-9/calibration?window=24h")
74
+
75
+
76
+ def test_offline_only_scorers_get_a_clear_error_for_online_surfaces(recorded):
77
+ _, responses = recorded
78
+ responses.append(FakeResponse({"judgeScorer": {"_id": "s1", "name": "n", "online": None}}))
79
+ with pytest.raises(AgentXJudgeScorersError, match="no online profile"):
80
+ make_client().ratings("s1")
81
+
82
+
83
+ def test_http_errors_surface_the_engine_message(recorded):
84
+ _, responses = recorded
85
+ responses.append(FakeResponse({"error": "built-in judge scorer"}, status_code=409))
86
+ with pytest.raises(AgentXJudgeScorersError, match="409.*built-in judge scorer"):
87
+ make_client().delete("baseline")
88
+
89
+
90
+ def test_dataset_builder_forwards_code_scorers(monkeypatch):
91
+ # The documented kwarg (evaluation/code-scorers.mdx) raised TypeError before the fix.
92
+ from agentx.evaluations.datasets import DatasetClient
93
+
94
+ class FakeEvalClient:
95
+ def create_dataset(self, payload):
96
+ self.payload = payload
97
+ return {"_id": "d1"}
98
+
99
+ fake = FakeEvalClient()
100
+ builder = DatasetClient(fake).builder(
101
+ "ds", code_scorers=[{"name": "tool order", "code": "def handler(...): pass"}]
102
+ )
103
+ payload = builder._payload # noqa: SLF001 - asserting the wire body the builder assembled
104
+ assert "codeScorers" in payload
105
+ assert payload["codeScorers"][0]["name"] == "tool order"
106
+ assert payload["codeScorers"][0]["enabled"] is True
107
+ assert payload["codeScorers"][0]["id"]
108
+
109
+
110
+ def test_legacy_profile_clients_warn_once_on_first_access():
111
+ """The legacy views (evaluations.settings / monitor.online_evaluators) stay functional but
112
+ emit a DeprecationWarning pointing at judge_scorers - lazily, so a client that never touches
113
+ them never warns."""
114
+ import warnings
115
+
116
+ from agentx import AgentX
117
+
118
+ with warnings.catch_warnings(record=True) as during_init:
119
+ warnings.simplefilter("always")
120
+ client = AgentX(api_key="agtx_local_test", base_url="http://localhost:1")
121
+ _ = client.monitor.judge_scorers # the unified surface never warns
122
+ assert not [w for w in during_init if "judge_scorers" in str(w.message)]
123
+
124
+ with warnings.catch_warnings(record=True) as caught:
125
+ warnings.simplefilter("always")
126
+ _ = client.evaluations.settings
127
+ _ = client.monitor.online_evaluators
128
+ messages = [str(w.message) for w in caught if issubclass(w.category, DeprecationWarning)]
129
+ assert any("judge_scorers" in m for m in messages), messages
130
+ assert len(messages) >= 2
131
+
132
+
133
+ def test_scorer_id_is_the_preferred_run_kwarg():
134
+ """Runs pick their grader as scorer_id (post-consolidation name); the legacy
135
+ evaluation_settings_id kwarg maps to the same wire field, and passing two DIFFERENT ids is
136
+ rejected."""
137
+ import pytest
138
+
139
+ from agentx.evaluations.client import _resolve_scorer_id
140
+
141
+ assert _resolve_scorer_id("s1", None) == "s1"
142
+ assert _resolve_scorer_id(None, "s1") == "s1"
143
+ assert _resolve_scorer_id("s1", "s1") == "s1"
144
+ assert _resolve_scorer_id(None, None) is None
145
+ with pytest.raises(ValueError):
146
+ _resolve_scorer_id("s1", "s2")
147
+
148
+
149
+ def test_init_run_sends_scorer_id_as_evaluationSettingsId(monkeypatch):
150
+ from agentx.evaluations.client import EvaluationsClient
151
+ from agentx.evaluations.models import EvaluationSubject
152
+
153
+ client = EvaluationsClient(api_key="agtx_local_test", base_url="http://localhost:1")
154
+ captured = {}
155
+
156
+ def fake_request(method, path, **kwargs):
157
+ captured["payload"] = kwargs.get("json")
158
+ return {
159
+ "runId": "r1",
160
+ "datasetId": "d1",
161
+ "status": "running",
162
+ "numberOfRequests": 1,
163
+ }
164
+
165
+ monkeypatch.setattr(client, "_request", fake_request)
166
+ client.init_run("d1", EvaluationSubject(type="external"), scorer_id="scorer-123")
167
+ assert captured["payload"]["evaluationSettingsId"] == "scorer-123"
168
+
169
+
170
+ def test_judge_scorers_builder_matches_legacy_builder_ergonomics(monkeypatch):
171
+ """The unified successor of evaluations.settings.builder: snake_case kwargs, .publish(),
172
+ plus what the legacy builder never had - tool_context, thresholds, and the live profile in
173
+ the same call. The payload it assembles is plain judge-scorers wire."""
174
+ from agentx.monitor.judge_scorers import JudgeScorersClient
175
+
176
+ client = JudgeScorersClient(api_key="agtx_local_test", base_url="http://localhost:1")
177
+ captured = {}
178
+
179
+ def fake_request(method, path, **kwargs):
180
+ captured["method"] = method
181
+ captured["path"] = path
182
+ captured["payload"] = kwargs.get("json")
183
+ return {"judgeScorer": {"_id": "s1", "name": "Support quality", "judge": {}, "offline": {}, "online": None}}
184
+
185
+ monkeypatch.setattr(client, "_request", fake_request)
186
+ scorer = (
187
+ client.builder(
188
+ "Support quality",
189
+ acceptance_criteria="Concrete and correct.",
190
+ judge_model="gpt-4.1-mini",
191
+ tool_context="detailed",
192
+ number_of_requests=2,
193
+ vector_similarity=True,
194
+ thresholds={"enabled": True, "gates": [{"metric": "rating", "operator": "lt", "value": 5}]},
195
+ live=True,
196
+ sample_rate=0.25,
197
+ agent_ids=["support-agent"],
198
+ ).publish()
199
+ )
200
+ assert scorer.id == "s1"
201
+ payload = captured["payload"]
202
+ assert captured["path"] == "/judge-scorers"
203
+ assert payload["judge"] == {
204
+ "acceptanceCriteria": "Concrete and correct.",
205
+ "judgeModel": "gpt-4.1-mini",
206
+ "toolContext": "detailed",
207
+ }
208
+ assert payload["offline"]["numberOfRequests"] == 2
209
+ assert payload["offline"]["vectorSimilarity"] == {"enabled": True}
210
+ assert payload["offline"]["thresholds"]["gates"][0]["value"] == 5
211
+ assert payload["online"]["enabled"] is True
212
+ assert payload["online"]["sampleRate"] == 0.25
213
+ assert payload["online"]["scopeMode"] == "selected"
214
+ assert payload["online"]["agentIds"] == ["support-agent"]
215
+
216
+
217
+ def test_from_env_honors_selfhost_base_url_conventions(monkeypatch):
218
+ """from_env silently targeting the hosted default while the shell exports the self-host
219
+ conventions (AGENTX_SELFHOST_BASE_URL / BASE_URL) produced confusing auth errors - it now
220
+ picks up the first convention that is set."""
221
+ from agentx import AgentX
222
+
223
+ monkeypatch.setenv("AGENTX_API_KEY", "agtx_local_test")
224
+ monkeypatch.delenv("AGENTX_API_BASE_URL", raising=False)
225
+ monkeypatch.setenv("AGENTX_SELFHOST_BASE_URL", "http://localhost:4999/api/v1")
226
+ client = AgentX.from_env()
227
+ assert client.base_url == "http://localhost:4999/api/v1"
228
+
229
+ monkeypatch.setenv("AGENTX_API_BASE_URL", "http://localhost:5000/api/v1")
230
+ assert AgentX.from_env().base_url == "http://localhost:5000/api/v1" # explicit name wins
231
+
232
+
233
+ def test_tune_unwraps_the_proposal_envelope(monkeypatch):
234
+ """The tune wire wraps its result in {"proposal": {...}} - judge_scorers.tune must unwrap it
235
+ like the legacy client does, so proposal["reasoning"]/criteria are directly addressable
236
+ (selfhost_demo/11 crashed on the wrapped form)."""
237
+ from agentx.monitor.judge_scorers import JudgeScorersClient
238
+
239
+ client = JudgeScorersClient(api_key="agtx_local_test", base_url="http://localhost:1")
240
+ monkeypatch.setattr(client, "_profile_id", lambda scorer_id: "prof-1")
241
+ monkeypatch.setattr(
242
+ client,
243
+ "_request",
244
+ lambda *a, **k: {"proposal": {"reasoning": "why", "acceptanceCriteria": "a"}},
245
+ )
246
+ proposal = client.tune("s1")
247
+ assert proposal["reasoning"] == "why"
248
+
249
+
250
+ def test_validate_and_publish_send_criteria_at_top_level(monkeypatch):
251
+ """The tuning wire takes the criteria fields at the TOP level of the body (the legacy client
252
+ always did) - nesting them under "criteria" 400s with 'acceptanceCriteria is required'."""
253
+ from agentx.monitor.judge_scorers import JudgeScorersClient
254
+
255
+ client = JudgeScorersClient(api_key="agtx_local_test", base_url="http://localhost:1")
256
+ monkeypatch.setattr(client, "_profile_id", lambda scorer_id: "prof-1")
257
+ captured = {}
258
+
259
+ def fake_request(method, path, json=None, timeout=60):
260
+ captured[path.rsplit("/", 1)[-1]] = json
261
+ return {}
262
+
263
+ monkeypatch.setattr(client, "_request", fake_request)
264
+ criteria = {"acceptanceCriteria": "a", "rejectionCriteria": "r", "evaluationCriteria": "e"}
265
+ client.validate_tuning("s1", criteria, window="24h")
266
+ client.publish_tuning("s1", criteria)
267
+ assert captured["validate"]["acceptanceCriteria"] == "a"
268
+ assert captured["validate"]["window"] == "24h"
269
+ assert "criteria" not in captured["validate"]
270
+ assert captured["publish"]["acceptanceCriteria"] == "a"
@@ -1 +0,0 @@
1
- VERSION = "0.6.35"
File without changes
File without changes
File without changes
File without changes