multi-agent-observability 0.1.0__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 multi-agent-observability might be problematic. Click here for more details.

Files changed (50) hide show
  1. multi_agent_observability-0.1.0/.gitignore +24 -0
  2. multi_agent_observability-0.1.0/CHANGELOG.md +46 -0
  3. multi_agent_observability-0.1.0/CITATION.cff +16 -0
  4. multi_agent_observability-0.1.0/LICENSE +201 -0
  5. multi_agent_observability-0.1.0/NOTICE +6 -0
  6. multi_agent_observability-0.1.0/PKG-INFO +365 -0
  7. multi_agent_observability-0.1.0/README.md +321 -0
  8. multi_agent_observability-0.1.0/docs/replay.md +95 -0
  9. multi_agent_observability-0.1.0/docs/semantic-conventions.md +126 -0
  10. multi_agent_observability-0.1.0/examples/basic_two_agents.py +121 -0
  11. multi_agent_observability-0.1.0/examples/langgraph_pipeline.py +58 -0
  12. multi_agent_observability-0.1.0/examples/otel_export.py +37 -0
  13. multi_agent_observability-0.1.0/pyproject.toml +108 -0
  14. multi_agent_observability-0.1.0/src/ma_trace/__init__.py +204 -0
  15. multi_agent_observability-0.1.0/src/ma_trace/_version.py +2 -0
  16. multi_agent_observability-0.1.0/src/ma_trace/adapters/__init__.py +9 -0
  17. multi_agent_observability-0.1.0/src/ma_trace/adapters/autogen.py +159 -0
  18. multi_agent_observability-0.1.0/src/ma_trace/adapters/crewai.py +337 -0
  19. multi_agent_observability-0.1.0/src/ma_trace/adapters/langchain.py +395 -0
  20. multi_agent_observability-0.1.0/src/ma_trace/adapters/langgraph.py +100 -0
  21. multi_agent_observability-0.1.0/src/ma_trace/cli.py +349 -0
  22. multi_agent_observability-0.1.0/src/ma_trace/context.py +29 -0
  23. multi_agent_observability-0.1.0/src/ma_trace/contracts.py +107 -0
  24. multi_agent_observability-0.1.0/src/ma_trace/episode.py +208 -0
  25. multi_agent_observability-0.1.0/src/ma_trace/events.py +291 -0
  26. multi_agent_observability-0.1.0/src/ma_trace/exporters.py +154 -0
  27. multi_agent_observability-0.1.0/src/ma_trace/graph.py +211 -0
  28. multi_agent_observability-0.1.0/src/ma_trace/memory.py +174 -0
  29. multi_agent_observability-0.1.0/src/ma_trace/metrics.py +340 -0
  30. multi_agent_observability-0.1.0/src/ma_trace/py.typed +0 -0
  31. multi_agent_observability-0.1.0/src/ma_trace/replay.py +398 -0
  32. multi_agent_observability-0.1.0/src/ma_trace/sampling.py +117 -0
  33. multi_agent_observability-0.1.0/src/ma_trace/semconv.py +140 -0
  34. multi_agent_observability-0.1.0/src/ma_trace/store.py +185 -0
  35. multi_agent_observability-0.1.0/src/ma_trace/tracer.py +779 -0
  36. multi_agent_observability-0.1.0/tests/conftest.py +30 -0
  37. multi_agent_observability-0.1.0/tests/test_adapters_autogen.py +116 -0
  38. multi_agent_observability-0.1.0/tests/test_adapters_crewai.py +129 -0
  39. multi_agent_observability-0.1.0/tests/test_adapters_langchain.py +73 -0
  40. multi_agent_observability-0.1.0/tests/test_adapters_langgraph.py +74 -0
  41. multi_agent_observability-0.1.0/tests/test_cli.py +120 -0
  42. multi_agent_observability-0.1.0/tests/test_contracts.py +28 -0
  43. multi_agent_observability-0.1.0/tests/test_events.py +79 -0
  44. multi_agent_observability-0.1.0/tests/test_graph.py +52 -0
  45. multi_agent_observability-0.1.0/tests/test_memory.py +59 -0
  46. multi_agent_observability-0.1.0/tests/test_metrics.py +94 -0
  47. multi_agent_observability-0.1.0/tests/test_replay.py +175 -0
  48. multi_agent_observability-0.1.0/tests/test_sampling.py +60 -0
  49. multi_agent_observability-0.1.0/tests/test_store.py +81 -0
  50. multi_agent_observability-0.1.0/tests/test_tracer.py +280 -0
@@ -0,0 +1,24 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ wheels/
8
+ .venv/
9
+ venv/
10
+ # Tooling caches
11
+ .pytest_cache/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+ .coverage
15
+ coverage.xml
16
+ htmlcov/
17
+ uv.lock
18
+ # Editors / OS
19
+ .vscode/
20
+ .idea/
21
+ *.swp
22
+ .DS_Store
23
+ # Runtime artefacts
24
+ .ma-trace/
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ All notable changes to `multi-agent-observability` are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-10-03
10
+
11
+ First release on PyPI: the initial version of 27 September 2026 (*Added*) together with
12
+ the changes made to it before publishing.
13
+
14
+ ### Added
15
+ - Episodes with seeded randomness, an ordered event log and JSON persistence (`EpisodeStore`).
16
+ - Coordination graphs (typed, confidence-scored edges; bottlenecks, cycles, delegation depth; DOT/Mermaid/JSON export).
17
+ - Memory operation traces (`mt.memory`, `TracedMemory`; hit ratio, eviction reasons, thrashing detection).
18
+ - Environment contracts with per-action seeds and pre/post-state fingerprints.
19
+ - SLO metrics: coordination overhead, redundant action rate, oscillation rate, memory hit ratio; thresholds and violations.
20
+ - OpenTelemetry spans (standard `gen_ai.*` attributes plus `ma_trace.*` extensions), OTel metrics and Prometheus gauges.
21
+ - `AdaptiveSampler`: baseline ratio with anomaly escalation, implemented as an OpenTelemetry `Sampler`.
22
+ - Deterministic replay engine (`mt.replay`, `ma-trace replay`) with divergence reporting.
23
+ - CLI: `list`, `show`, `graph`, `metrics`, `memory`, `replay`, `diff`, `export`, `import`, `delete`.
24
+ - Adapters: LangChain/LangGraph callback handler and helpers, CrewAI event-bus listener, AutoGen AgentChat message tracer and AG2 hooks.
25
+
26
+ ### Changed
27
+ - README, `NOTICE`, `CITATION.cff` and the package metadata now describe the software only;
28
+ the SLO thresholds and the sampler default are documented as library defaults to calibrate.
29
+
30
+ ### Removed
31
+ - Unused `ReplaySession.note_contract_result` (contract pass counts come from the replayed episode).
32
+
33
+ ### Fixed
34
+ - `EpisodeStore.resolve("latest")` chose an episode by file modification time only, which returned the
35
+ wrong episode on file systems with coarse timestamps (seen on Windows); it now uses the recorded start
36
+ time, with the file time and the id as tie-breakers. A test no longer assumes `/` path separators.
37
+ - Episodes started back to back could share a start time where the wall clock advances in coarse
38
+ steps (about 16 ms on Windows before Python 3.13), so `latest` and `ma-trace list` ordered them by
39
+ the random part of the id. Start, event and end times recorded by the tracer now strictly increase
40
+ within a process.
41
+ - CI caches uv by `pyproject.toml` (the lock file is not committed), which newer `setup-uv` releases require.
42
+ - `ma-trace show --events` now prints meaningful `False` flags (`hit=false` for memory misses,
43
+ `verified=false`, `output_recorded=false`) and zero-valued fields such as `index=0`; only the
44
+ `noop` and `replayed` flags are hidden when false.
45
+ - The bundled demo and the README explain that `ma-trace replay` must run from the directory
46
+ that contains the entrypoint module (`examples/`), and the demo's `sys.path` handling is portable.
@@ -0,0 +1,16 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use multi-agent-observability, please cite it as below."
3
+ type: software
4
+ title: "multi-agent-observability (MA-Trace): causal tracing, coordination SLOs and deterministic replay for multi-agent LLM systems"
5
+ version: 0.1.0
6
+ date-released: "2026-10-03"
7
+ license: Apache-2.0
8
+ repository-code: "https://github.com/nunar-nexus-forge/multi-agent-observability"
9
+ authors:
10
+ - name: nunar-nexus-forge
11
+ keywords:
12
+ - observability
13
+ - opentelemetry
14
+ - multi-agent systems
15
+ - large language models
16
+ - deterministic replay
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ multi-agent-observability
2
+ Copyright 2026 nunar-nexus-forge
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
+ this software except in compliance with the License. You may obtain a copy of
6
+ the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,365 @@
1
+ Metadata-Version: 2.5
2
+ Name: multi-agent-observability
3
+ Version: 0.1.0
4
+ Summary: MA-Trace: causal tracing, coordination SLOs and deterministic replay for multi-agent LLM systems (multi-agent observability on OpenTelemetry).
5
+ Project-URL: Homepage, https://github.com/nunar-nexus-forge/multi-agent-observability
6
+ Project-URL: Documentation, https://github.com/nunar-nexus-forge/multi-agent-observability/tree/main/docs
7
+ Project-URL: Changelog, https://github.com/nunar-nexus-forge/multi-agent-observability/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/nunar-nexus-forge/multi-agent-observability/issues
9
+ Author: nunar-nexus-forge
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: agents,autogen,crewai,langgraph,llm,multi-agent,multi-agent-observability,observability,opentelemetry,replay,slo,tracing
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Debuggers
22
+ Classifier: Topic :: System :: Monitoring
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: opentelemetry-api>=1.20
26
+ Requires-Dist: opentelemetry-sdk>=1.20
27
+ Provides-Extra: all
28
+ Requires-Dist: langchain-core>=0.3; extra == 'all'
29
+ Requires-Dist: langgraph>=0.2; extra == 'all'
30
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.20; extra == 'all'
31
+ Requires-Dist: prometheus-client>=0.17; extra == 'all'
32
+ Provides-Extra: autogen
33
+ Requires-Dist: autogen-agentchat>=0.4; extra == 'autogen'
34
+ Provides-Extra: crewai
35
+ Requires-Dist: crewai>=0.100; extra == 'crewai'
36
+ Provides-Extra: langgraph
37
+ Requires-Dist: langchain-core>=0.3; extra == 'langgraph'
38
+ Requires-Dist: langgraph>=0.2; extra == 'langgraph'
39
+ Provides-Extra: otlp
40
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.20; extra == 'otlp'
41
+ Provides-Extra: prometheus
42
+ Requires-Dist: prometheus-client>=0.17; extra == 'prometheus'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # multi-agent-observability
46
+
47
+ **MA-Trace - causal tracing, coordination SLOs and deterministic replay for multi-agent LLM systems - exported through OpenTelemetry.**
48
+
49
+ [![CI](https://github.com/nunar-nexus-forge/multi-agent-observability/actions/workflows/ci.yml/badge.svg)](https://github.com/nunar-nexus-forge/multi-agent-observability/actions/workflows/ci.yml)
50
+ [![PyPI](https://img.shields.io/pypi/v/multi-agent-observability.svg)](https://pypi.org/project/multi-agent-observability/)
51
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
52
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)
53
+
54
+ "My agents did something weird and I can't reproduce it."
55
+
56
+ `multi-agent-observability` is an open-source implementation of **MA-Trace**, an observability
57
+ framework for multi-agent LLM systems. It adds three things that single-agent LLM tracing
58
+ tools and generic distributed tracing do not give you:
59
+
60
+ | What | Why it matters |
61
+ |---|---|
62
+ | **Coordination graphs** - every agent-to-agent message is a typed, timestamped, confidence-scored edge | see delegation chains, negotiation loops, bottleneck agents and cycles instead of a flat list of spans |
63
+ | **Memory operation traces** - reads, writes and evictions on episodic/semantic memory, with hit/miss, confidence and *eviction reason* | diagnose retrieval bias, stale reads and memory thrashing |
64
+ | **Environment contracts + deterministic replay** - seed-controlled pre/post-state hashes for every action, and recorded LLM/tool outputs | `ma-trace replay <episode>` re-executes a run **without calling the model** and tells you exactly where it diverged |
65
+
66
+ On top of that it computes three **multi-agent SLOs** (coordination overhead, redundant
67
+ action rate, oscillation rate) plus the memory hit ratio, exports everything as
68
+ OpenTelemetry spans and metrics (Jaeger, Phoenix, Langfuse, Datadog, Prometheus ...),
69
+ and ships adapters for **LangGraph / LangChain, CrewAI and AutoGen**.
70
+
71
+ It is additive: it plugs into the observability stack you already run.
72
+
73
+ ---
74
+
75
+ ## Install
76
+
77
+ ```bash
78
+ pip install multi-agent-observability # core (OpenTelemetry API + SDK only)
79
+ pip install 'multi-agent-observability[langgraph]' # + LangGraph / LangChain adapter
80
+ pip install 'multi-agent-observability[otlp,prometheus]' # + OTLP exporter, Prometheus gauges
81
+ pip install 'multi-agent-observability[all]'
82
+ ```
83
+
84
+ Python 3.10+. No API keys are needed for anything in this README; the examples use
85
+ seeded fake models.
86
+
87
+ > **Naming:** the distribution is `multi-agent-observability`; the framework itself is called
88
+ > MA-Trace, so the import is `import ma_trace as mt` and the CLI is `ma-trace <command>`.
89
+
90
+ ## 60-second tour
91
+
92
+ ```python
93
+ import ma_trace as mt
94
+
95
+ mt.configure("checkout-bot", exporter="console") # optional: OTel export (console / otlp / SpanExporter)
96
+
97
+
98
+ @mt.llm("planner", provider="openai", model="gpt-4o") # the wrapped call is recorded for replay
99
+ def ask(prompt: str) -> str:
100
+ return client.chat(prompt) # your code, unchanged
101
+
102
+
103
+ @mt.tool("search")
104
+ def search(query: str) -> list[str]:
105
+ return backend.search(query)
106
+
107
+
108
+ def run(order_id: str):
109
+ state = {"order": order_id, "charged": False}
110
+ with mt.agent_span("planner"):
111
+ plan = ask(f"plan the checkout of {order_id}")
112
+ mt.coordination("planner", "executor", plan, kind="delegation", confidence=0.9)
113
+
114
+ with mt.agent_span("executor"):
115
+ mt.memory("executor", "read", "episodic", f"order:{order_id}", hit=False)
116
+ with mt.contract("executor", "charge", pre_state=state) as c: # seed-controlled contract
117
+ state = charge(state, seed=c.seed)
118
+ c.set_post_state(state)
119
+ mt.action("executor", "charge", {"order": order_id}) # feeds the redundancy SLO
120
+
121
+
122
+ with mt.episode("checkout", seed=42, entrypoint="myapp:run", entrypoint_args={"order_id": "A1"}) as ep:
123
+ run("A1")
124
+
125
+ print(ep.metrics().format()) # CO / RAR / OR / MHR for this episode
126
+ print(ep.coordination_graph().to_mermaid())
127
+ ```
128
+
129
+ Later, when episode `ep-20260927-…` misbehaves:
130
+
131
+ ```bash
132
+ ma-trace list # what was recorded (default store: ./.ma-trace/episodes)
133
+ ma-trace show latest --events # timeline: agents, edges, memory ops, contracts, calls
134
+ ma-trace graph latest --format dot # coordination graph for Graphviz (or mermaid / json)
135
+ ma-trace metrics latest # SLOs + threshold check (exit 1 with --fail-on-violation)
136
+ ma-trace replay latest # deterministic re-execution: recorded LLM/tool outputs, verified contracts
137
+ ma-trace diff <ep-a> <ep-b> # why did two runs differ?
138
+ ```
139
+
140
+ `ma-trace replay` prints a report like:
141
+
142
+ ```
143
+ replay of ep-20260927-141502-a3f1c2 -> ep-20260927-141530-9b0e77: DETERMINISTIC
144
+ entrypoint : myapp:run
145
+ calls replayed : 7 (executed live: 0)
146
+ contracts checked : 4 (passed: 4)
147
+ coordination_overhead: recorded=0.310 replayed=0.302
148
+ ```
149
+
150
+ or, when the code path changed, a list of divergences (`input_mismatch`, `unexpected_call`,
151
+ `missing_call`, `contract_post_mismatch`, ...), each naming the agent and call.
152
+
153
+ Try it now with the bundled demo (no dependencies beyond `multi-agent-observability`):
154
+
155
+ ```bash
156
+ python examples/basic_two_agents.py
157
+ ```
158
+
159
+ To replay that episode from the CLI, work from the `examples/` directory: `ma-trace replay`
160
+ imports the recorded entrypoint module from the current working directory, and the store is
161
+ `./.ma-trace/episodes` relative to where the demo ran.
162
+
163
+ ```bash
164
+ cd examples && python basic_two_agents.py && ma-trace list && ma-trace replay latest
165
+ ```
166
+
167
+ ## Concepts
168
+
169
+ ### Episodes
170
+
171
+ An **episode** is one run of your workflow (`with mt.episode(name, seed=...)`). Everything
172
+ recorded inside - agent invocations, coordination edges, memory operations, contracts,
173
+ LLM/tool calls, actions and state snapshots - is stored as an ordered event log, persisted
174
+ as one JSON document, and mapped to an OpenTelemetry `invoke_workflow` span.
175
+
176
+ Seeding an episode seeds Python's `random` module and provides `episode.rng`; contracts
177
+ derive per-action seeds from it, so a replay sees the same sequence of seeds.
178
+
179
+ ### Coordination graph `G = (A, E)`
180
+
181
+ Each `mt.coordination(source, target, message, kind, confidence)` call is a directed edge
182
+ `(source, target, message, confidence, timestamp)`. Kinds: `message`, `delegation`,
183
+ `negotiation`, `consensus`, `response`, `broadcast`, `handoff`.
184
+ `episode.coordination_graph()` gives you degrees, bottlenecks, cycle detection,
185
+ delegation depth and DOT / Mermaid / JSON export.
186
+
187
+ ### Memory operations `m = (agent, op, type, key, confidence, t)`
188
+
189
+ `mt.memory(agent, op, memory_type, key, hit=..., confidence=..., eviction_reason=...)`, or
190
+ wrap any dict-like store in `TracedMemory` to record automatically (with capacity-based
191
+ eviction). `episode.memory_trace()` reports hit ratio, eviction reasons, thrashing keys and
192
+ low-confidence reads.
193
+
194
+ ### Environment contracts `Contract(a) = (s_pre, s_post, seed, result)`
195
+
196
+ ```python
197
+ with mt.contract("executor", "move", pre_state=state) as c:
198
+ state = env.step(action, seed=c.seed)
199
+ c.set_post_state(state)
200
+ c.set_result("ok")
201
+ ```
202
+
203
+ States are fingerprinted (SHA-256 of canonical JSON). Under replay the pre- and post-state
204
+ hashes are compared with the recording; a mismatch is a divergence.
205
+
206
+ ### SLO metrics
207
+
208
+ | Metric | Definition | Reading |
209
+ |---|---|---|
210
+ | Coordination overhead `CO` | `(T_wall − Σ T_llm+tool) / T_wall` | share of time spent waiting/coordinating rather than working; clamped to `[0, 1]` (`coordination_overhead_raw` keeps the unclamped value, which goes negative under concurrency) |
211
+ | Redundant action rate `RAR` | `redundant actions / total actions` | duplicates (same agent, action and arguments seen before in the episode) and no-ops (`noop=True`, or unchanged state). `redundant_actions_per_second` is the time-normalised form |
212
+ | Oscillation rate `OR` | `repeated state transitions / total state transitions` | agents flipping between states already visited (from `mt.state(...)`, contracts and actions with state hashes) |
213
+ | Memory hit ratio `MHR` | `successful retrievals / (reads + writes)` | `memory_trace().hit_ratio(reads_only=True)` for the reads-only denominator |
214
+
215
+ `mt.evaluate(metrics, SLOThresholds(...))` returns violations; the CLI exposes the same via
216
+ `ma-trace metrics --co-max/--rar-max/--or-max/--mhr-min`. The default thresholds (CO 0.42,
217
+ RAR 0.18, OR 0.23) are conservative alert levels for an un-optimised multi-agent system;
218
+ calibrate them against your own baseline episodes. Metrics are recorded through the
219
+ OpenTelemetry metrics API (`ma_trace.coordination_overhead` etc.) and optionally as
220
+ Prometheus gauges (`metrics_exporter="prometheus"`).
221
+
222
+ ### Adaptive sampling
223
+
224
+ `AdaptiveSampler(base_ratio=1.0, anomaly_ratio=1.0, escalation_episodes=20)` decides per
225
+ episode whether it is captured in full. The library default captures every episode; a
226
+ production setting such as `AdaptiveSampler(base_ratio=0.1)` captures 10 % of episodes and
227
+ switches to 100 % for the next 20 episodes after `mt.flag_anomaly(reason)`. It is a real
228
+ OpenTelemetry `Sampler`, so span export and episode recording always agree. Unsampled
229
+ episodes still produce SLO metrics but store no call outputs, so they cannot be replayed.
230
+
231
+ ## OpenTelemetry mapping
232
+
233
+ | Span | `gen_ai.operation.name` | Notable attributes |
234
+ |---|---|---|
235
+ | `invoke_workflow <episode>` | `invoke_workflow` | `ma_trace.episode.{id,name,seed,sampled,replay_of}`, `ma_trace.slo.*` |
236
+ | `invoke_agent <agent>` | `invoke_agent` | `gen_ai.agent.name` |
237
+ | `chat <model>` | `chat` | `gen_ai.provider.name`, `gen_ai.request.model`, `ma_trace.call.{index,input_fingerprint,output_fingerprint,replayed}` |
238
+ | `execute_tool <tool>` | `execute_tool` | `gen_ai.tool.name`, `gen_ai.tool.call.id` |
239
+ | `coordinate <src>-><tgt>` | `coordinate` (extension) | `ma_trace.coordination.{source,target,kind,message,confidence,message_id,in_reply_to}` |
240
+ | `memory_access <op> <key>` | `memory_access` (extension) | `ma_trace.memory.{agent,operation,type,key,confidence,hit,eviction_reason}` |
241
+ | `environment_contract <action>` | `environment_contract` (extension) | `ma_trace.contract.{action,pre_state_hash,post_state_hash,seed,result,verified}` |
242
+
243
+ Standard `gen_ai.*` attributes follow the OpenTelemetry GenAI semantic conventions. The
244
+ extension attributes live under `ma_trace.*` by default; `MATrace(namespace="gen_ai")`
245
+ emits the proposed `gen_ai.*` spelling described in
246
+ [docs/semantic-conventions.md](docs/semantic-conventions.md), which is written as a
247
+ contribution proposal to the OpenTelemetry GenAI conventions.
248
+
249
+ Export: `mt.configure(exporter="otlp")` (uses `OTEL_EXPORTER_OTLP_ENDPOINT`), `"console"`,
250
+ or pass any `SpanExporter`. Spans are batched and flushed every 10 s by default.
251
+
252
+ ## Framework adapters
253
+
254
+ **LangGraph / LangChain** - zero code changes:
255
+
256
+ ```python
257
+ from ma_trace.adapters.langgraph import trace_config
258
+
259
+ with mt.episode("pipeline", seed=1):
260
+ graph.invoke(inputs, config=trace_config())
261
+ ```
262
+
263
+ Each node becomes an `invoke_agent` span, node transitions become `handoff` edges, and
264
+ model/tool calls inside nodes are recorded (pass `config` through to them). Plain LangChain
265
+ runnables are attributed to an agent through `metadata={"ma_trace_agent": "planner"}` or
266
+ `MATraceCallbackHandler(agent_chains=[...])`. Decorate node functions with `@traced_node()`
267
+ to also snapshot their output state for oscillation detection.
268
+
269
+ **CrewAI** - one line, uses the CrewAI event bus:
270
+
271
+ ```python
272
+ from ma_trace.adapters.crewai import create_listener
273
+
274
+ listener = create_listener() # kickoff -> episode; tasks -> delegation edges; tools/LLM/memory -> events
275
+ crew.kickoff()
276
+ ```
277
+
278
+ **AutoGen (AgentChat 0.4+)**:
279
+
280
+ ```python
281
+ from ma_trace.adapters.autogen import trace_task_result, traced_run_stream
282
+
283
+ result = await team.run(task="...")
284
+ episode = trace_task_result(result, episode_name="haiku")
285
+ # or, live: async for msg in traced_run_stream(team.run_stream(task="...")): ...
286
+ ```
287
+
288
+ For AG2 / pyautogen `ConversableAgent`s use `register_ag2_hooks(agent)`.
289
+
290
+ Anything else: the core API (`agent_span`, `llm`, `tool`, `coordination`, `memory`,
291
+ `contract`, `action`, `state`) is framework-independent.
292
+
293
+ ## Deterministic replay - how it works
294
+
295
+ 1. While recording, every `@mt.llm` / `@mt.tool` call stores a fingerprint of its inputs
296
+ and its output (JSON), and every contract stores `(pre_hash, post_hash, seed)`.
297
+ 2. `mt.replay(episode, entrypoint)` seeds `random`, opens a new episode marked
298
+ `replay_of=<id>`, and runs the entrypoint. Each recorded call is served from the
299
+ recording (FIFO per agent/call name); the real function is not executed.
300
+ 3. Differences are collected as divergences: `input_mismatch` (same call, different inputs),
301
+ `unexpected_call` / `missing_call`, `output_unavailable` (output was not serialisable),
302
+ `contract_pre_mismatch` / `contract_post_mismatch`, `unexpected_contract` /
303
+ `missing_contract`, `action_sequence_mismatch`, `coordination_mismatch`, `error`.
304
+ 4. `strict=True` raises on the first divergence; otherwise you get a full `ReplayReport`
305
+ with recorded vs replayed SLO metrics.
306
+
307
+ Replayed outputs are JSON values; use `mt.llm(..., encode=..., decode=...)` when your call
308
+ returns rich objects. See [docs/replay.md](docs/replay.md).
309
+
310
+ ## CLI
311
+
312
+ ```
313
+ ma-trace [--store DIR] list|show|graph|metrics|memory|replay|diff|export|import|delete
314
+ ```
315
+
316
+ The store defaults to `$MA_TRACE_STORE` or `./.ma-trace/episodes`. Episode references
317
+ accept a full id, a unique prefix, or `latest`.
318
+
319
+ ## Architecture
320
+
321
+ ```mermaid
322
+ flowchart LR
323
+ subgraph app["your multi-agent app"]
324
+ A1[agent spans] --> R
325
+ A2[coordination edges] --> R
326
+ A3[memory ops] --> R
327
+ A4[contracts / calls] --> R
328
+ end
329
+ R[episode recorder] --> S[(episode store<br/>JSON)]
330
+ R --> M[SLO metrics<br/>CO · RAR · OR · MHR]
331
+ R --> O[OpenTelemetry spans]
332
+ M --> P[OTel metrics / Prometheus]
333
+ O --> B[(Jaeger · Phoenix · Langfuse · Datadog)]
334
+ S --> C[ma-trace CLI<br/>show · graph · diff]
335
+ S --> RP[replay engine] --> app
336
+ ```
337
+
338
+ ## Scope
339
+
340
+ MA-Trace is a library, not a benchmark: it records, measures, exports and replays what your
341
+ agents do, and makes no performance claims of its own beyond its test suite. The examples use
342
+ seeded fake models so that everything in this repository runs offline. Longer documents live
343
+ in `docs/`: [replay.md](docs/replay.md) (matching rules, divergence kinds, limitations) and
344
+ [semantic-conventions.md](docs/semantic-conventions.md) (the proposed `gen_ai.*` attributes).
345
+ To cite the software, use [CITATION.cff](CITATION.cff).
346
+
347
+ ## Companion projects
348
+
349
+ - [`agent-chaos-engineering`](https://github.com/nunar-nexus-forge/agent-chaos-engineering) - fault injection ("chaos monkey for agents") and self-healing recovery patterns.
350
+ - [`agent-tool-guardrails`](https://github.com/nunar-nexus-forge/agent-tool-guardrails) - policy contracts for agent-tool calls, a policy compiler, a tamper-evident evidence store and an MCP proxy.
351
+
352
+ ## Contributing
353
+
354
+ Bug reports, adapter contributions (Semantic Kernel, OpenAI Agents SDK, smolagents ...) and
355
+ semantic-convention feedback are very welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
356
+
357
+ ```bash
358
+ git clone https://github.com/nunar-nexus-forge/multi-agent-observability && cd multi-agent-observability
359
+ make sync # creates ./.venv with uv and installs everything (nothing is installed globally)
360
+ make check # ruff + mypy + pytest
361
+ ```
362
+
363
+ ## License
364
+
365
+ Apache License 2.0 - see [LICENSE](LICENSE) and [NOTICE](NOTICE).