agentx-python 0.8.12__py3-none-any.whl → 0.8.13__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.
@@ -143,6 +143,9 @@ def finish_llm_call(
143
143
  input=input_repr,
144
144
  output=output,
145
145
  model=model,
146
+ # Stamp the provider literal on a span opened without one (adoption keeps an
147
+ # explicit framework= or a framework integration's label winning over this).
148
+ framework=framework,
146
149
  input_tokens=input_tokens,
147
150
  output_tokens=output_tokens,
148
151
  cache_read_tokens=cache_read_tokens,
agentx/monitor/client.py CHANGED
@@ -268,6 +268,28 @@ class MonitorClient:
268
268
  plus deltas vs the prior window and the run-outcome breakdown."""
269
269
  return self._request("GET", "/kpis", params={"window": window})
270
270
 
271
+ def metrics(
272
+ self,
273
+ window: str = "1d",
274
+ *,
275
+ agent: Optional[str] = None,
276
+ model: Optional[str] = None,
277
+ tool: Optional[str] = None,
278
+ framework: Optional[str] = None,
279
+ status: Optional[str] = None,
280
+ ) -> dict:
281
+ """The Monitor metrics grid's data over a window ("1h".."90d") - bucketed spans by kind,
282
+ latency percentiles, tokens/cost, tool executions and failures, and platform attribution
283
+ (`frameworks` window totals + per-bucket `byFramework` - the Platforms chart). Optional
284
+ filters scope every number the way the dashboard's filter chips do; `framework` matches
285
+ the platform label traces carry (see TRACING.md's Platform detection), with "other"
286
+ selecting unlabeled traffic."""
287
+ params = {"window": window}
288
+ for key, value in (("agent", agent), ("model", model), ("tool", tool), ("framework", framework), ("status", status)):
289
+ if value is not None:
290
+ params[key] = value
291
+ return self._request("GET", "/metrics", params=params)
292
+
271
293
  def topics(self, window: str = "7d") -> dict:
272
294
  """The Topics view's data over a window ("24h", "7d", "30d"): LLM-classified themes of
273
295
  sampled production traffic with per-topic counts and sentiment. Empty until Topics is
@@ -0,0 +1,64 @@
1
+ """Best-effort agent-framework auto-detection (the "platform agnostic" story).
2
+
3
+ A span whose framework was neither passed explicitly (``tracer.trace(...,
4
+ framework="...")``) nor adopted from a framework integration (callback handler,
5
+ observer, patched client - see ``_TraceSpan._captured_framework``) gets labeled
6
+ by looking at which known ORCHESTRATION framework is actually imported in this
7
+ process. ``sys.modules`` is the signal - imported, not merely installed - so a
8
+ machine with ten frameworks pip-installed but one in use still resolves.
9
+
10
+ Only unambiguous answers are given: zero or more than one known framework
11
+ loaded means ``None``, and the span goes out unlabeled rather than mislabeled.
12
+ The user's explicit ``framework=`` always wins, including totally custom names
13
+ for platforms this table has never heard of.
14
+
15
+ Raw provider SDKs (openai, anthropic, google-genai, ...) are deliberately NOT
16
+ in this table: they are transitive dependencies of nearly every framework, so
17
+ their presence says nothing about what orchestrates the agent - and their
18
+ patched-client integrations already stamp the provider literal on the spans
19
+ they create.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import sys
25
+ from typing import Optional
26
+
27
+ # Top-level module name -> the wire literal the matching integration emits.
28
+ # Multiple modules may map to one literal (langgraph is the LangChain family).
29
+ _ORCHESTRATOR_MODULES = {
30
+ "langchain": "langchain",
31
+ "langchain_core": "langchain",
32
+ "langgraph": "langchain",
33
+ "crewai": "crewai",
34
+ "llama_index": "llamaindex",
35
+ "autogen": "autogen",
36
+ "autogen_agentchat": "autogen",
37
+ "agents": "openai-agents", # the OpenAI Agents SDK's import name
38
+ "google.adk": "google-adk",
39
+ "semantic_kernel": "semantic-kernel",
40
+ "haystack": "haystack",
41
+ "pydantic_ai": "pydantic-ai",
42
+ "smolagents": "smolagents",
43
+ "dspy": "dspy",
44
+ }
45
+
46
+
47
+ def _looks_like_openai_agents_sdk() -> bool:
48
+ # "agents" is a name any user package could claim - only trust it when the
49
+ # OpenAI Agents SDK's own submodules are loaded alongside it.
50
+ return "agents.run" in sys.modules or "agents.tracing" in sys.modules
51
+
52
+
53
+ def detect_framework() -> Optional[str]:
54
+ """The single unambiguous orchestration framework imported right now, else None."""
55
+ found: set = set()
56
+ for module, literal in _ORCHESTRATOR_MODULES.items():
57
+ if module not in sys.modules:
58
+ continue
59
+ if module == "agents" and not _looks_like_openai_agents_sdk():
60
+ continue
61
+ found.add(literal)
62
+ if len(found) > 1:
63
+ return None
64
+ return found.pop() if len(found) == 1 else None
agentx/tracing/tracer.py CHANGED
@@ -14,6 +14,7 @@ from agentx.exceptions import CIGateFailure
14
14
  from agentx.tracing.ingest_client import IngestClient
15
15
  from agentx.tracing.ci_types import CIRun, CIRunResult, CIRunStatus, CIQuestionScore
16
16
  from agentx.tracing.eval_scope import EVAL_RUN_SOURCE, current_eval_run_id
17
+ from agentx.tracing.framework_detect import detect_framework
17
18
 
18
19
  F = TypeVar("F", bound=Callable[..., Any])
19
20
 
@@ -125,6 +126,10 @@ class _TraceSpan:
125
126
  # Adopted from a merged child run (e.g. AgentXCallbackHandler) when this span itself
126
127
  # wasn't opened with an explicit framework= - see _merge_child_run below.
127
128
  self._captured_framework: Optional[str] = None
129
+ # Best-effort auto-detection (framework_detect.py), resolved once at span open so child
130
+ # spans emitted mid-flight carry the same label the root will. Lowest precedence:
131
+ # explicit framework= > integration adoption > this. None when ambiguous.
132
+ self._detected_framework: Optional[str] = None if framework else detect_framework()
128
133
  self._input_tokens: int = 0
129
134
  self._output_tokens: int = 0
130
135
  # Subsets of _input_tokens (not additional tokens) - a prompt-caching write/read, when the
@@ -191,7 +196,7 @@ class _TraceSpan:
191
196
  latency_ms=latency_ms,
192
197
  error=self._error,
193
198
  metadata=metadata,
194
- framework=self._framework or self._captured_framework,
199
+ framework=self._framework or self._captured_framework or self._detected_framework or detect_framework(),
195
200
  model=self._model or self._captured_model,
196
201
  tool_calls=self.tool_calls or None,
197
202
  session_id=self._session_id,
@@ -235,14 +240,18 @@ class _TraceSpan:
235
240
  input: Any = None,
236
241
  output: Any = None,
237
242
  model: Optional[str] = None,
243
+ framework: Optional[str] = None,
238
244
  input_tokens: Optional[int] = None,
239
245
  output_tokens: Optional[int] = None,
240
246
  cache_read_tokens: Optional[int] = None,
241
247
  cache_write_tokens: Optional[int] = None,
242
248
  ) -> None:
243
249
  """Record one LLM-call child span (e.g. one patched Anthropic call) under this span -
244
- name left unset so _merge_child_run auto-numbers it "LLM Call N"."""
250
+ name left unset so _merge_child_run auto-numbers it "LLM Call N". ``framework`` lets the
251
+ patched client stamp its provider literal on a span the user opened without one - the
252
+ adoption in _merge_child_run keeps explicit/integration labels winning."""
245
253
  self._merge_child_run(
254
+ framework=framework,
246
255
  execution_steps=[{
247
256
  "duration_ms": duration_ms,
248
257
  "start_time": start_time,
@@ -301,7 +310,7 @@ class _TraceSpan:
301
310
  child = _TraceSpan(
302
311
  tracer=self._tracer,
303
312
  name=name,
304
- framework=framework or self._framework or self._captured_framework,
313
+ framework=framework or self._framework or self._captured_framework or self._detected_framework,
305
314
  model=model,
306
315
  session_id=self._session_id,
307
316
  )
@@ -397,6 +406,13 @@ class _TraceSpan:
397
406
  under this span).
398
407
  """
399
408
  with self._merge_lock:
409
+ # Adopt framework/model BEFORE emitting child spans: child_span resolves its
410
+ # framework from this span's fields, so adopting after the emission loops used to
411
+ # send every CrewAI/AutoGen child out unlabeled while only the root got stamped.
412
+ if model and not self._captured_model:
413
+ self._captured_model = model
414
+ if framework and not self._captured_framework:
415
+ self._captured_framework = framework
400
416
  for step in [] if not emit_steps else (execution_steps or []):
401
417
  self._child_span_count += 1
402
418
  self.child_span(
@@ -463,10 +479,6 @@ class _TraceSpan:
463
479
  self.input = input
464
480
  if output is not None:
465
481
  self.output = output
466
- if model and not self._captured_model:
467
- self._captured_model = model
468
- if framework and not self._captured_framework:
469
- self._captured_framework = framework
470
482
  if input_tokens:
471
483
  self._input_tokens += input_tokens
472
484
  if output_tokens:
@@ -520,7 +532,8 @@ class _TraceSpan:
520
532
  # to be called from inside another active span.
521
533
  span = self._tracer.trace(
522
534
  self.name, metadata=self._metadata, framework=self._framework, model=self._model,
523
- session_id=self._session_id,
535
+ session_id=self._session_id, sync=self._sync, monitor=self._monitor,
536
+ pattern_ids=self._pattern_ids, agent_id=self._agent_id, span_kind=self._span_kind,
524
537
  )
525
538
  span.__enter__()
526
539
  try:
@@ -542,7 +555,8 @@ class _TraceSpan:
542
555
  # See _wrap_sync's comment - same "fresh span per call" reasoning applies here.
543
556
  span = self._tracer.trace(
544
557
  self.name, metadata=self._metadata, framework=self._framework, model=self._model,
545
- session_id=self._session_id,
558
+ session_id=self._session_id, sync=self._sync, monitor=self._monitor,
559
+ pattern_ids=self._pattern_ids, agent_id=self._agent_id, span_kind=self._span_kind,
546
560
  )
547
561
  span.__enter__()
548
562
  try:
@@ -911,6 +925,22 @@ class Tracer:
911
925
 
912
926
  with client.tracer.trace("support-agent", agent_id="ag_123", sync=True) as span:
913
927
  span.output = call_llm(...)
928
+
929
+ ``framework`` names the platform the agent runs on - tracing is platform agnostic, and
930
+ this label is how the dashboard's framework filter and Monitor's Platforms chart group
931
+ traffic. Three ways it gets set, strongest first:
932
+
933
+ 1. **Explicit**: ``framework="langchain"`` - any string works, including platforms
934
+ AgentX has no integration for (``framework="my-inhouse-runner"``).
935
+ 2. **Integration**: every integration stamps its own literal automatically -
936
+ ``langchain``, ``crewai``, ``openai-agents``, ``openai``, ``anthropic``,
937
+ ``google-genai``, ``google-adk``, ``litellm``, ``llamaindex``, ``autogen``,
938
+ ``moveworks``, ``databricks``.
939
+ 3. **Auto-detection**: with neither of the above, the SDK labels the span with the one
940
+ known orchestration framework imported in the process (LangChain/LangGraph, CrewAI,
941
+ LlamaIndex, AutoGen, OpenAI Agents SDK, Google ADK, Semantic Kernel, Haystack,
942
+ Pydantic AI, smolagents, DSPy). Ambiguous (several imported) or unknown -> the span
943
+ goes out unlabeled rather than mislabeled.
914
944
  """
915
945
  return _TraceSpan(
916
946
  tracer=self,
agentx/version.py CHANGED
@@ -1,7 +1,7 @@
1
- VERSION = "0.8.12"
1
+ VERSION = "0.8.13"
2
2
 
3
3
  # The AgentX-trace-eval release this SDK version is tested against - what `agentx-trace-eval`
4
4
  # installs and converges to (see agentx/cli.py). Bump together with VERSION when releasing, so
5
5
  # every published SDK names a known-good engine+dashboard pair. Users can override with
6
6
  # AGENTX_TRACE_EVAL_VERSION=<tag|latest>.
7
- ENGINE_VERSION = "v0.3.4"
7
+ ENGINE_VERSION = "v0.3.7"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentx-python
3
- Version: 0.8.12
3
+ Version: 0.8.13
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
@@ -252,7 +252,12 @@ extra:
252
252
  | LlamaIndex | `pip install "agentx-python[llamaindex]"` | `AgentXLlamaIndexHandler` |
253
253
  | AutoGen | `pip install "agentx-python[autogen]"` | `AgentXAutoGenObserver` |
254
254
 
255
- Or plain Python - wrap any function with `@tracer.trace(...)` and it just works, no framework required.
255
+ Or plain Python - wrap any function with `@tracer.trace(...)` and it just works, no framework
256
+ required. Tracing is **platform agnostic**: each integration stamps its platform label
257
+ automatically, a plain trace auto-detects the one orchestration framework imported in the
258
+ process, and `framework="any-name"` labels platforms AgentX has never heard of - the label
259
+ drives the dashboard's framework filter and Monitor's Platforms chart. See
260
+ [Platform detection](TRACING.md#platform-detection).
256
261
 
257
262
  Running specialist agents in parallel with a `ThreadPoolExecutor`? Wrap each worker body in `tracer.use_span(span)` so their steps land on the parent trace instead of becoming independent traces - see [TRACING.md](TRACING.md) for the full pattern.
258
263
 
@@ -10,7 +10,7 @@ agentx/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  agentx/testing.py,sha256=0shZEid_vhJgBegpO_loUq6APYDxQrUgD3jvcRdIDV8,7372
11
11
  agentx/traces.py,sha256=sz9gxutlDKNgf0fdCkyzKsGwK5eMAJuIEl3NIwGrsuo,2287
12
12
  agentx/util.py,sha256=lt2Kpg4Fj8whrSuAhLEahcPEIYRVpK9RCC5y9ShdTJs,703
13
- agentx/version.py,sha256=vsrbVEe8EC1S6DCr1jnhCYco-1GCWOHdaUPGulZoMR0,365
13
+ agentx/version.py,sha256=h93nyZEahmg-F_qXioTJhKMFmXgzcYA3exV9z2on3LQ,365
14
14
  agentx/evaluations/__init__.py,sha256=Erv7RGFlRxGTG4rVb2uHhCqLLEX_iAWKqkZKzK6CumE,262
15
15
  agentx/evaluations/_term.py,sha256=WFpiNzdgDBeJJ-Gg-6X7TwwxllobuE4OqFUTuDQvS3Y,2529
16
16
  agentx/evaluations/client.py,sha256=UlYl8OFmIjk8oqmL_LEpjnTn6CmUPBM1kgVgzkUKfT8,31999
@@ -28,7 +28,7 @@ agentx/evaluations/adapters/http_endpoint.py,sha256=-Gika9lBcXjtbnyB-uNR6nYEVJhW
28
28
  agentx/evaluations/adapters/precomputed.py,sha256=vxnQELmpiU2NkQATfiVjG7v1ZmmkrEA70Y11ijfYtHw,1208
29
29
  agentx/evaluations/adapters/raw.py,sha256=FkDq_mdf21-xt5EHnGyIGcS6VZxkEkFcmM9VTd-T5sA,1130
30
30
  agentx/integrations/__init__.py,sha256=W-EcQhHE01-SGPeKTB2AgfvUyRzNP4BqUMMtP2qQ4Q0,647
31
- agentx/integrations/_traced_call.py,sha256=IUk2ZSZN8E5Th-WU1s0PcJixLguoh6LQpG8hbnRgqZU,6451
31
+ agentx/integrations/_traced_call.py,sha256=O6f8HKRHDfFwoUIZDtvENVsv_OsHwzuyPMbzBakKVdo,6662
32
32
  agentx/integrations/anthropic.py,sha256=HNFiwtljfWsAJOmc2XXseKSVb8ThUr6BZ6CWT7uGv18,10383
33
33
  agentx/integrations/autogen.py,sha256=cZryUl45Sdr9t1ba4tkz45XfkvjCud1hPp6pV0auKy8,8863
34
34
  agentx/integrations/crewai.py,sha256=AMxAP2Rpdojf2iaMVNcs8_LhnUGJnsS1NaX-w-1Gicc,10703
@@ -43,7 +43,7 @@ agentx/integrations/openai.py,sha256=1KLs-hJaeW2emHPwNkmC3zcGksL3zd87uWbcLGRW704
43
43
  agentx/integrations/openai_agents.py,sha256=tCa3kPxqux5LnNNDQ6zA05OybQrjkc_LeE08YuNPJEs,12742
44
44
  agentx/monitor/__init__.py,sha256=MLiASSvQnCy2jqVNRTgPWFhUSf8lGYRQeEgEVVhE5Tg,574
45
45
  agentx/monitor/agents.py,sha256=8Xk4jWmNTvdtjFixHiLmw4jj96uqIXWIT6KW8zXoWrc,1006
46
- agentx/monitor/client.py,sha256=XUecRuhWM80_dlKFCHORp9TPWN80XM5SApkGRTFedX4,19724
46
+ agentx/monitor/client.py,sha256=nY1cvjbCqL6BZMY6ubM-Q6JUKGgUM5CdBektV99EArQ,20812
47
47
  agentx/monitor/judge_scorers.py,sha256=Mu6OOnfjp1SRkZMcOyriO7zPawv-O2H2l2X-0io5WLM,15025
48
48
  agentx/monitor/models.py,sha256=yTC3WTdTziHMkdeAXlTro-4YiSbBUHMgf9kNZHGfPDA,8470
49
49
  agentx/monitor/online_evaluators.py,sha256=YWnsBmlIbYvj4LCaX4guwx4HS5y3oEzCQfo6ae9VH_w,8693
@@ -61,11 +61,12 @@ agentx/resources/workforce.py,sha256=lfGVkoV9lcOp-lZScjTvwRarJMkhzfMfLm4syJDujGc
61
61
  agentx/tracing/__init__.py,sha256=l2mIRILE-wWrCD0fekgrIOQUEvtDObzdrkgpQUtXroU,408
62
62
  agentx/tracing/ci_types.py,sha256=zFVcZGvc1qbVDdOlEPQ1i5R6terqJHxCzFF4ZjouxxI,1423
63
63
  agentx/tracing/eval_scope.py,sha256=ElMbPxpqpQBVuaUnHNlw9RIQu71oyOpd0yR55bDH8eI,2144
64
+ agentx/tracing/framework_detect.py,sha256=uV4O7Th-4_2UkdooAyaWCOIA0jwLJbblFQ_ucFDjeJM,2638
64
65
  agentx/tracing/ingest_client.py,sha256=spnm6bV3NXGuj2w7HwdKiJdKDJWRUFmSP3jl3rcGqkQ,18202
65
- agentx/tracing/tracer.py,sha256=qQojU-T4O8IJKyf9vue0Em66qPBTZKl3FMyr3KJKPnI,53770
66
- agentx_python-0.8.12.dist-info/licenses/LICENSE,sha256=gZVsM-nLsE8vlaY6NXXsVoo6IlCClxkToAWmhgT3y_s,10762
67
- agentx_python-0.8.12.dist-info/METADATA,sha256=3uZCbOgUOxHRzbygAFJTbVulNQqgXZONs0jMig7uGYc,20768
68
- agentx_python-0.8.12.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
69
- agentx_python-0.8.12.dist-info/entry_points.txt,sha256=rQqF1JTY3T1yfviBU1r8PU-5mBdfOk6P4bZ1L4BskIM,172
70
- agentx_python-0.8.12.dist-info/top_level.txt,sha256=s-q-HB9Gb_QdrZNacSeQyF_c25gQooMy7DlxzgLOHPk,7
71
- agentx_python-0.8.12.dist-info/RECORD,,
66
+ agentx/tracing/tracer.py,sha256=TxY6zG6hbM81jpfrqP4imaEvoyy_hnJVUSTnoAVHMG0,56240
67
+ agentx_python-0.8.13.dist-info/licenses/LICENSE,sha256=gZVsM-nLsE8vlaY6NXXsVoo6IlCClxkToAWmhgT3y_s,10762
68
+ agentx_python-0.8.13.dist-info/METADATA,sha256=cit9iBc_TXXOlcp8AObpzlXdbx3FLuaVTbBsBdggcJ8,21154
69
+ agentx_python-0.8.13.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
70
+ agentx_python-0.8.13.dist-info/entry_points.txt,sha256=rQqF1JTY3T1yfviBU1r8PU-5mBdfOk6P4bZ1L4BskIM,172
71
+ agentx_python-0.8.13.dist-info/top_level.txt,sha256=s-q-HB9Gb_QdrZNacSeQyF_c25gQooMy7DlxzgLOHPk,7
72
+ agentx_python-0.8.13.dist-info/RECORD,,