agentx-python 0.6.35__tar.gz → 0.6.37__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 (81) hide show
  1. {agentx_python-0.6.35 → agentx_python-0.6.37}/PKG-INFO +16 -1
  2. {agentx_python-0.6.35 → agentx_python-0.6.37}/README.md +15 -0
  3. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/agentx.py +12 -2
  4. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/client.py +28 -3
  5. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/datasets.py +4 -0
  6. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/evaluation_settings.py +17 -1
  7. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/models.py +1 -1
  8. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/runner.py +16 -11
  9. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/client.py +16 -1
  10. agentx_python-0.6.37/agentx/monitor/judge_scorers.py +334 -0
  11. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/online_evaluators.py +21 -2
  12. agentx_python-0.6.37/agentx/version.py +1 -0
  13. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx_python.egg-info/PKG-INFO +16 -1
  14. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx_python.egg-info/SOURCES.txt +3 -0
  15. agentx_python-0.6.37/tests/test_docs_match_sdk.py +176 -0
  16. agentx_python-0.6.37/tests/test_judge_scorers.py +270 -0
  17. agentx_python-0.6.35/agentx/version.py +0 -1
  18. {agentx_python-0.6.35 → agentx_python-0.6.37}/LICENSE +0 -0
  19. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/__init__.py +0 -0
  20. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/cli.py +0 -0
  21. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/__init__.py +0 -0
  22. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/_term.py +0 -0
  23. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/adapters/__init__.py +0 -0
  24. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/adapters/http_endpoint.py +0 -0
  25. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/adapters/precomputed.py +0 -0
  26. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/adapters/raw.py +0 -0
  27. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/prompts.py +0 -0
  28. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/reporting.py +0 -0
  29. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/results.py +0 -0
  30. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/tool_schemas.py +0 -0
  31. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/evaluations/tracing.py +0 -0
  32. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/exceptions.py +0 -0
  33. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/export.py +0 -0
  34. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/feedback.py +0 -0
  35. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/__init__.py +0 -0
  36. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/_traced_call.py +0 -0
  37. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/anthropic.py +0 -0
  38. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/autogen.py +0 -0
  39. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/crewai.py +0 -0
  40. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/databricks.py +0 -0
  41. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/google_adk.py +0 -0
  42. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/google_genai.py +0 -0
  43. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/langchain.py +0 -0
  44. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/litellm.py +0 -0
  45. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/llamaindex.py +0 -0
  46. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/moveworks.py +0 -0
  47. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/openai.py +0 -0
  48. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/integrations/openai_agents.py +0 -0
  49. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/__init__.py +0 -0
  50. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/agents.py +0 -0
  51. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/models.py +0 -0
  52. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/patterns.py +0 -0
  53. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/profile.py +0 -0
  54. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/scorers.py +0 -0
  55. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/sessions.py +0 -0
  56. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/monitor/signals.py +0 -0
  57. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/outcomes.py +0 -0
  58. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/projects.py +0 -0
  59. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/py.typed +0 -0
  60. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/resources/__init__.py +0 -0
  61. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/resources/agent.py +0 -0
  62. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/resources/conversation.py +0 -0
  63. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/resources/workforce.py +0 -0
  64. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/traces.py +0 -0
  65. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/tracing/__init__.py +0 -0
  66. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/tracing/ci_types.py +0 -0
  67. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/tracing/ingest_client.py +0 -0
  68. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/tracing/tracer.py +0 -0
  69. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx/util.py +0 -0
  70. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx_python.egg-info/dependency_links.txt +0 -0
  71. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx_python.egg-info/entry_points.txt +0 -0
  72. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx_python.egg-info/not-zip-safe +0 -0
  73. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx_python.egg-info/requires.txt +0 -0
  74. {agentx_python-0.6.35 → agentx_python-0.6.37}/agentx_python.egg-info/top_level.txt +0 -0
  75. {agentx_python-0.6.35 → agentx_python-0.6.37}/setup.cfg +0 -0
  76. {agentx_python-0.6.35 → agentx_python-0.6.37}/setup.py +0 -0
  77. {agentx_python-0.6.35 → agentx_python-0.6.37}/tests/test_deep_dive_fixes.py +0 -0
  78. {agentx_python-0.6.35 → agentx_python-0.6.37}/tests/test_integration.py +0 -0
  79. {agentx_python-0.6.35 → agentx_python-0.6.37}/tests/test_integrations.py +0 -0
  80. {agentx_python-0.6.35 → agentx_python-0.6.37}/tests/test_selfhost_analysis_fallback.py +0 -0
  81. {agentx_python-0.6.35 → agentx_python-0.6.37}/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.37
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
@@ -315,6 +315,21 @@ evaluator = client.monitor.online_evaluators.builder(
315
315
  client.monitor.online_evaluators.ratings(evaluator.id, window="7d")
316
316
  ```
317
317
 
318
+ An online evaluator and a dataset run's grading config are two profiles of one **LLM Judge Scorer**, and `client.monitor.judge_scorers` manages both in a single call - one rubric, one id, used offline and online:
319
+
320
+ ```python
321
+ scorer = client.monitor.judge_scorers.builder(
322
+ name="Helpfulness",
323
+ acceptance_criteria="Concrete, correct, cites the policy.",
324
+ live=True, sample_rate=0.1, alert_threshold=5, # the online profile
325
+ ).publish()
326
+
327
+ client.evaluations.run(dataset_id=dataset.id, subject={...}, scorer_id=scorer.id)
328
+ client.monitor.judge_scorers.ratings(scorer.id, window="7d")
329
+ ```
330
+
331
+ The two clients above are that entity's per-profile legacy views; they keep working and share the same ids. See [LLM Judge Scorers](EVALUATIONS.md#llm-judge-scorers---reusable-grading-configs) for the full surface, including which self-host engine builds serve it.
332
+
318
333
  An online evaluator can also judge **whole conversations** instead of single traces: pass `scope="session"` and the engine scores each multi-turn session once it's been idle for `idle_seconds`, re-scoring if the conversation resumes. And to close the loop with reality, two ground-truth streams feed the dashboard's Judge Calibration view (which measures how often AgentX's automated verdicts agree with what actually happened): `client.outcomes.report(...)` for after-the-fact system results (a reopened ticket, a human confirmation), and `client.feedback.report(...)` for end-user votes forwarded from your own app's UI - a "down" raises a "Negative user feedback" signal directly, no sampling or judge call involved. All self-host features.
319
334
 
320
335
  ```python
@@ -251,6 +251,21 @@ evaluator = client.monitor.online_evaluators.builder(
251
251
  client.monitor.online_evaluators.ratings(evaluator.id, window="7d")
252
252
  ```
253
253
 
254
+ An online evaluator and a dataset run's grading config are two profiles of one **LLM Judge Scorer**, and `client.monitor.judge_scorers` manages both in a single call - one rubric, one id, used offline and online:
255
+
256
+ ```python
257
+ scorer = client.monitor.judge_scorers.builder(
258
+ name="Helpfulness",
259
+ acceptance_criteria="Concrete, correct, cites the policy.",
260
+ live=True, sample_rate=0.1, alert_threshold=5, # the online profile
261
+ ).publish()
262
+
263
+ client.evaluations.run(dataset_id=dataset.id, subject={...}, scorer_id=scorer.id)
264
+ client.monitor.judge_scorers.ratings(scorer.id, window="7d")
265
+ ```
266
+
267
+ The two clients above are that entity's per-profile legacy views; they keep working and share the same ids. See [LLM Judge Scorers](EVALUATIONS.md#llm-judge-scorers---reusable-grading-configs) for the full surface, including which self-host engine builds serve it.
268
+
254
269
  An online evaluator can also judge **whole conversations** instead of single traces: pass `scope="session"` and the engine scores each multi-turn session once it's been idle for `idle_seconds`, re-scoring if the conversation resumes. And to close the loop with reality, two ground-truth streams feed the dashboard's Judge Calibration view (which measures how often AgentX's automated verdicts agree with what actually happened): `client.outcomes.report(...)` for after-the-fact system results (a reopened ticket, a human confirmation), and `client.feedback.report(...)` for end-user votes forwarded from your own app's UI - a "down" raises a "Negative user feedback" signal directly, no sampling or judge call involved. All self-host features.
255
270
 
256
271
  ```python
@@ -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
+ )