agent-tracedown 0.3.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.
- agent_tracedown-0.3.0/LICENSE +202 -0
- agent_tracedown-0.3.0/PKG-INFO +121 -0
- agent_tracedown-0.3.0/README.md +76 -0
- agent_tracedown-0.3.0/agent_tracedown/__init__.py +32 -0
- agent_tracedown-0.3.0/agent_tracedown/exporters/__init__.py +173 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/__init__.py +66 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/autogen.py +116 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/claude_agent.py +166 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/crewai.py +180 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/google_adk.py +215 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/langchain.py +214 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/llamaindex.py +136 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/mcp.py +133 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/openai_agents.py +194 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/pydantic_ai.py +151 -0
- agent_tracedown-0.3.0/agent_tracedown/integrations/semantic_kernel.py +55 -0
- agent_tracedown-0.3.0/agent_tracedown/plugins/__init__.py +47 -0
- agent_tracedown-0.3.0/agent_tracedown/plugins/anthropic_plugin.py +65 -0
- agent_tracedown-0.3.0/agent_tracedown/plugins/openai_plugin.py +77 -0
- agent_tracedown-0.3.0/agent_tracedown/redaction.py +33 -0
- agent_tracedown-0.3.0/agent_tracedown/spans.py +102 -0
- agent_tracedown-0.3.0/agent_tracedown/tracer.py +694 -0
- agent_tracedown-0.3.0/agent_tracedown.egg-info/PKG-INFO +121 -0
- agent_tracedown-0.3.0/agent_tracedown.egg-info/SOURCES.txt +28 -0
- agent_tracedown-0.3.0/agent_tracedown.egg-info/dependency_links.txt +1 -0
- agent_tracedown-0.3.0/agent_tracedown.egg-info/requires.txt +34 -0
- agent_tracedown-0.3.0/agent_tracedown.egg-info/top_level.txt +1 -0
- agent_tracedown-0.3.0/pyproject.toml +46 -0
- agent_tracedown-0.3.0/setup.cfg +4 -0
- agent_tracedown-0.3.0/tests/test_sdk.py +237 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-tracedown
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: The flight recorder for AI agents: find the step that caused a failure, then replay the run with a fix.
|
|
5
|
+
Author: Naveen Nair
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/nbn07/agent-tracedown
|
|
8
|
+
Project-URL: Source, https://github.com/nbn07/agent-tracedown
|
|
9
|
+
Project-URL: Issues, https://github.com/nbn07/agent-tracedown/issues
|
|
10
|
+
Keywords: ai-agents,llm,observability,debugging,root-cause-analysis,opentelemetry,tracing,langfuse
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: Topic :: System :: Monitoring
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
23
|
+
Provides-Extra: langgraph
|
|
24
|
+
Requires-Dist: langgraph>=1.0; extra == "langgraph"
|
|
25
|
+
Requires-Dist: langchain-core>=1.0; extra == "langgraph"
|
|
26
|
+
Provides-Extra: openai-agents
|
|
27
|
+
Requires-Dist: openai-agents>=0.2; extra == "openai-agents"
|
|
28
|
+
Provides-Extra: crewai
|
|
29
|
+
Requires-Dist: crewai>=1.0; extra == "crewai"
|
|
30
|
+
Provides-Extra: autogen
|
|
31
|
+
Requires-Dist: autogen-agentchat>=0.4; extra == "autogen"
|
|
32
|
+
Provides-Extra: semantic-kernel
|
|
33
|
+
Requires-Dist: semantic-kernel>=1.30; extra == "semantic-kernel"
|
|
34
|
+
Provides-Extra: llamaindex
|
|
35
|
+
Requires-Dist: llama-index-core>=0.12; extra == "llamaindex"
|
|
36
|
+
Provides-Extra: claude-agent-sdk
|
|
37
|
+
Requires-Dist: claude-agent-sdk>=0.2; extra == "claude-agent-sdk"
|
|
38
|
+
Provides-Extra: google-adk
|
|
39
|
+
Requires-Dist: google-adk>=2.0; extra == "google-adk"
|
|
40
|
+
Provides-Extra: pydantic-ai
|
|
41
|
+
Requires-Dist: pydantic-ai-slim>=2.0; extra == "pydantic-ai"
|
|
42
|
+
Provides-Extra: mcp
|
|
43
|
+
Requires-Dist: mcp>=1.30; extra == "mcp"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# agent-tracedown
|
|
47
|
+
|
|
48
|
+
The Python SDK for [Tracedown](https://github.com/nbn07/agent-tracedown), the flight recorder for AI agents. When an agent fails, Tracedown finds the step that caused it, not just the step that crashed. Then you can replay the run with your fix.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install agent-tracedown # the SDK: no dependencies
|
|
52
|
+
pip install agent-tracedown-server # root-cause analysis, importers, server and UI
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import agent_tracedown as tdn
|
|
57
|
+
tdn.init(project="support-bot", endpoint="http://localhost:7070")
|
|
58
|
+
|
|
59
|
+
with tdn.run("CalendarAssistant", input=user_msg) as run:
|
|
60
|
+
out = tdn.llm_call(call_model, model="gpt-4o-mini", prompt=messages)
|
|
61
|
+
result = tdn.tool_call("calendar_create_event", args, create_event)
|
|
62
|
+
run.output(answer)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
There is one-line instrumentation for LangGraph, the OpenAI Agents SDK, the Claude Agent SDK, Google ADK, Pydantic AI, MCP, CrewAI, AutoGen, Semantic Kernel and LlamaIndex (`agent_tracedown.integrations`). Runs can also be exported to any OpenTelemetry collector.
|
|
66
|
+
|
|
67
|
+
## One-line run tracing
|
|
68
|
+
|
|
69
|
+
For a single-function agent, use `@tdn.traced_run(name)` instead of opening the
|
|
70
|
+
run context yourself. The decorator records the first argument as input, the
|
|
71
|
+
return value as output, and re-raises exceptions after marking the run failed.
|
|
72
|
+
It supports both synchronous and asynchronous functions.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
@tdn.traced_run("CalendarAssistant")
|
|
76
|
+
def answer(question):
|
|
77
|
+
return call_model(question)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Framework integrations
|
|
81
|
+
|
|
82
|
+
The newer ones, briefly. Each records agents, model calls (with token usage and cost where the framework reports it) and tool calls, and marks the step where a failure happened.
|
|
83
|
+
|
|
84
|
+
**Claude Agent SDK** (`pip install "agent-tracedown[claude-agent-sdk]"`). Wrap the message stream; messages pass through unchanged. Subagents started with the Task tool nest under their own agent span, and the run's cost comes from `ResultMessage.total_cost_usd`.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from agent_tracedown.integrations import claude_agent as tdn_claude
|
|
88
|
+
|
|
89
|
+
async for msg in tdn_claude.trace_stream(query(prompt=p, options=opts), name="CodingAgent", prompt=p):
|
|
90
|
+
...
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Google ADK** (`pip install "agent-tracedown[google-adk]"`). Add the plugin to your app; it only observes.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from agent_tracedown.integrations import google_adk as tdn_adk
|
|
97
|
+
|
|
98
|
+
app = App(name="support", root_agent=root_agent, plugins=[tdn_adk.TracedownPlugin()])
|
|
99
|
+
runner = InMemoryRunner(app=app)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Pydantic AI** (`pip install "agent-tracedown[pydantic-ai]"`). Run the agent through the wrapper; runs that raise are recorded too.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from agent_tracedown.integrations import pydantic_ai as tdn_pai
|
|
106
|
+
|
|
107
|
+
result = await tdn_pai.run(agent, "Refund order 42") # or tdn_pai.run_sync(...)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**MCP** (`pip install "agent-tracedown[mcp]"`). Instrument a `mcp.Client` or `ClientSession`; inside a run, every `call_tool` becomes a step and `list_tools` records the server's tools and their input schemas.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from agent_tracedown.integrations import mcp as tdn_mcp
|
|
114
|
+
|
|
115
|
+
tdn_mcp.instrument(client, server="billing") # or tdn_mcp.instrument_all()
|
|
116
|
+
with tdn.run("SupportAgent", input=question):
|
|
117
|
+
await client.list_tools()
|
|
118
|
+
await client.call_tool("refund", {"order_id": 42})
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Documentation, benchmarks and the demo are in the [repository](https://github.com/nbn07/agent-tracedown). Licensed under Apache-2.0.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# agent-tracedown
|
|
2
|
+
|
|
3
|
+
The Python SDK for [Tracedown](https://github.com/nbn07/agent-tracedown), the flight recorder for AI agents. When an agent fails, Tracedown finds the step that caused it, not just the step that crashed. Then you can replay the run with your fix.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install agent-tracedown # the SDK: no dependencies
|
|
7
|
+
pip install agent-tracedown-server # root-cause analysis, importers, server and UI
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```python
|
|
11
|
+
import agent_tracedown as tdn
|
|
12
|
+
tdn.init(project="support-bot", endpoint="http://localhost:7070")
|
|
13
|
+
|
|
14
|
+
with tdn.run("CalendarAssistant", input=user_msg) as run:
|
|
15
|
+
out = tdn.llm_call(call_model, model="gpt-4o-mini", prompt=messages)
|
|
16
|
+
result = tdn.tool_call("calendar_create_event", args, create_event)
|
|
17
|
+
run.output(answer)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
There is one-line instrumentation for LangGraph, the OpenAI Agents SDK, the Claude Agent SDK, Google ADK, Pydantic AI, MCP, CrewAI, AutoGen, Semantic Kernel and LlamaIndex (`agent_tracedown.integrations`). Runs can also be exported to any OpenTelemetry collector.
|
|
21
|
+
|
|
22
|
+
## One-line run tracing
|
|
23
|
+
|
|
24
|
+
For a single-function agent, use `@tdn.traced_run(name)` instead of opening the
|
|
25
|
+
run context yourself. The decorator records the first argument as input, the
|
|
26
|
+
return value as output, and re-raises exceptions after marking the run failed.
|
|
27
|
+
It supports both synchronous and asynchronous functions.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
@tdn.traced_run("CalendarAssistant")
|
|
31
|
+
def answer(question):
|
|
32
|
+
return call_model(question)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Framework integrations
|
|
36
|
+
|
|
37
|
+
The newer ones, briefly. Each records agents, model calls (with token usage and cost where the framework reports it) and tool calls, and marks the step where a failure happened.
|
|
38
|
+
|
|
39
|
+
**Claude Agent SDK** (`pip install "agent-tracedown[claude-agent-sdk]"`). Wrap the message stream; messages pass through unchanged. Subagents started with the Task tool nest under their own agent span, and the run's cost comes from `ResultMessage.total_cost_usd`.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from agent_tracedown.integrations import claude_agent as tdn_claude
|
|
43
|
+
|
|
44
|
+
async for msg in tdn_claude.trace_stream(query(prompt=p, options=opts), name="CodingAgent", prompt=p):
|
|
45
|
+
...
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Google ADK** (`pip install "agent-tracedown[google-adk]"`). Add the plugin to your app; it only observes.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from agent_tracedown.integrations import google_adk as tdn_adk
|
|
52
|
+
|
|
53
|
+
app = App(name="support", root_agent=root_agent, plugins=[tdn_adk.TracedownPlugin()])
|
|
54
|
+
runner = InMemoryRunner(app=app)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Pydantic AI** (`pip install "agent-tracedown[pydantic-ai]"`). Run the agent through the wrapper; runs that raise are recorded too.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from agent_tracedown.integrations import pydantic_ai as tdn_pai
|
|
61
|
+
|
|
62
|
+
result = await tdn_pai.run(agent, "Refund order 42") # or tdn_pai.run_sync(...)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**MCP** (`pip install "agent-tracedown[mcp]"`). Instrument a `mcp.Client` or `ClientSession`; inside a run, every `call_tool` becomes a step and `list_tools` records the server's tools and their input schemas.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from agent_tracedown.integrations import mcp as tdn_mcp
|
|
69
|
+
|
|
70
|
+
tdn_mcp.instrument(client, server="billing") # or tdn_mcp.instrument_all()
|
|
71
|
+
with tdn.run("SupportAgent", input=question):
|
|
72
|
+
await client.list_tools()
|
|
73
|
+
await client.call_tool("refund", {"order_id": 42})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Documentation, benchmarks and the demo are in the [repository](https://github.com/nbn07/agent-tracedown). Licensed under Apache-2.0.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Tracedown: the flight recorder for AI agents."""
|
|
2
|
+
from . import plugins, redaction
|
|
3
|
+
from .exporters import ConsoleExporter, FanoutExporter, HttpExporter, MemoryExporter, OtlpHttpExporter, to_otlp_json
|
|
4
|
+
from .tracer import (
|
|
5
|
+
SDK_VERSION as __version__,
|
|
6
|
+
ManualTrace,
|
|
7
|
+
ReplayDivergence,
|
|
8
|
+
ToolError,
|
|
9
|
+
agent,
|
|
10
|
+
current_trace_id,
|
|
11
|
+
declare_tools,
|
|
12
|
+
decision,
|
|
13
|
+
fetch_bundle,
|
|
14
|
+
handoff,
|
|
15
|
+
init,
|
|
16
|
+
llm_call,
|
|
17
|
+
memory_read,
|
|
18
|
+
memory_write,
|
|
19
|
+
replay,
|
|
20
|
+
retrieval,
|
|
21
|
+
run,
|
|
22
|
+
tool_call,
|
|
23
|
+
traced_run,
|
|
24
|
+
validate_args,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"init", "run", "agent", "llm_call", "tool_call", "retrieval", "memory_read", "memory_write",
|
|
29
|
+
"decision", "handoff", "declare_tools", "OtlpHttpExporter", "FanoutExporter", "replay", "fetch_bundle", "current_trace_id", "validate_args",
|
|
30
|
+
"MemoryExporter", "ConsoleExporter", "HttpExporter", "to_otlp_json",
|
|
31
|
+
"ManualTrace", "ReplayDivergence", "ToolError", "traced_run", "plugins", "__version__",
|
|
32
|
+
]
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""Exporters ship finished runs (spans + content blobs) somewhere.
|
|
2
|
+
|
|
3
|
+
All exporters are stdlib-only so the SDK adds no dependencies to an agent.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
import urllib.error
|
|
10
|
+
import urllib.request
|
|
11
|
+
from typing import Any, Dict, List, Optional
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Exporter:
|
|
15
|
+
def export(self, spans: List[Dict[str, Any]], blobs: Dict[str, str]) -> None: # pragma: no cover
|
|
16
|
+
raise NotImplementedError
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class MemoryExporter(Exporter):
|
|
20
|
+
"""Keeps runs in memory. Used by tests and by replay."""
|
|
21
|
+
|
|
22
|
+
def __init__(self) -> None:
|
|
23
|
+
self.spans: List[Dict[str, Any]] = []
|
|
24
|
+
self.blobs: Dict[str, str] = {}
|
|
25
|
+
|
|
26
|
+
def export(self, spans, blobs):
|
|
27
|
+
self.spans.extend(spans)
|
|
28
|
+
self.blobs.update(blobs)
|
|
29
|
+
|
|
30
|
+
def trace(self, trace_id: str) -> List[Dict[str, Any]]:
|
|
31
|
+
return [s for s in self.spans if s["trace_id"] == trace_id]
|
|
32
|
+
|
|
33
|
+
def clear(self) -> None:
|
|
34
|
+
self.spans.clear()
|
|
35
|
+
self.blobs.clear()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ConsoleExporter(Exporter):
|
|
39
|
+
"""Prints a compact tree of each run to stderr."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, stream=None) -> None:
|
|
42
|
+
self.stream = stream or sys.stderr
|
|
43
|
+
|
|
44
|
+
def export(self, spans, blobs):
|
|
45
|
+
children: Dict[Optional[str], list] = {}
|
|
46
|
+
for s in spans:
|
|
47
|
+
children.setdefault(s["parent_span_id"], []).append(s)
|
|
48
|
+
|
|
49
|
+
def walk(parent, depth):
|
|
50
|
+
for s in sorted(children.get(parent, []), key=lambda x: x["start_time"]):
|
|
51
|
+
ms = ((s["end_time"] or s["start_time"]) - s["start_time"]) / 1e6
|
|
52
|
+
mark = "x" if s["status"]["code"] == "ERROR" else "-"
|
|
53
|
+
step = s["attributes"].get("tdn.step", "")
|
|
54
|
+
print(f"{' ' * depth}{mark} [{step}] {s['kind']:<9} {s['name']} {ms:.1f}ms", file=self.stream)
|
|
55
|
+
walk(s["span_id"], depth + 1)
|
|
56
|
+
|
|
57
|
+
walk(None, 0)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class HttpExporter(Exporter):
|
|
61
|
+
"""Posts spans and blobs to an TDN server's ingest API."""
|
|
62
|
+
|
|
63
|
+
def __init__(self, endpoint: str, api_key: Optional[str] = None, project: str = "default", timeout: float = 5.0):
|
|
64
|
+
self.endpoint = endpoint.rstrip("/")
|
|
65
|
+
self.api_key = api_key
|
|
66
|
+
self.project = project
|
|
67
|
+
self.timeout = timeout
|
|
68
|
+
self.last_error: Optional[str] = None
|
|
69
|
+
|
|
70
|
+
def _post(self, path: str, payload: Dict[str, Any]) -> None:
|
|
71
|
+
req = urllib.request.Request(
|
|
72
|
+
self.endpoint + path,
|
|
73
|
+
data=json.dumps(payload, default=str).encode("utf-8"),
|
|
74
|
+
headers={"Content-Type": "application/json"},
|
|
75
|
+
method="POST",
|
|
76
|
+
)
|
|
77
|
+
if self.api_key:
|
|
78
|
+
req.add_header("Authorization", f"Bearer {self.api_key}")
|
|
79
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
80
|
+
resp.read()
|
|
81
|
+
|
|
82
|
+
def export(self, spans, blobs):
|
|
83
|
+
# Telemetry must never crash the agent: failures are recorded, not raised.
|
|
84
|
+
try:
|
|
85
|
+
if blobs:
|
|
86
|
+
self._post("/v1/ingest/blobs", {"project": self.project, "blobs": blobs})
|
|
87
|
+
self._post("/v1/ingest/spans", {"project": self.project, "spans": spans})
|
|
88
|
+
self.last_error = None
|
|
89
|
+
except (urllib.error.URLError, OSError) as exc:
|
|
90
|
+
self.last_error = str(exc)
|
|
91
|
+
print(f"[agent-tracedown] export failed: {exc}", file=sys.stderr)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class OtlpHttpExporter(Exporter):
|
|
95
|
+
"""Send runs straight to any OTLP/HTTP endpoint: an OpenTelemetry Collector, Jaeger
|
|
96
|
+
(``:4318``), Grafana Tempo or Alloy, or the Datadog Agent's OTLP intake.
|
|
97
|
+
|
|
98
|
+
tdn.init(exporter=tdn.OtlpHttpExporter("http://localhost:4318/v1/traces"))
|
|
99
|
+
|
|
100
|
+
Payload content is not sent (spans carry digests); pair with ``HttpExporter`` via
|
|
101
|
+
``FanoutExporter`` to keep replay and RCA in Tracedown.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
def __init__(self, endpoint: str = "http://localhost:4318/v1/traces", headers: Optional[Dict[str, str]] = None,
|
|
105
|
+
service_name: str = "agent", timeout: float = 5.0) -> None:
|
|
106
|
+
self.endpoint, self.headers, self.service_name, self.timeout = endpoint, headers or {}, service_name, timeout
|
|
107
|
+
self.last_error: Optional[str] = None
|
|
108
|
+
|
|
109
|
+
def export(self, spans, blobs):
|
|
110
|
+
req = urllib.request.Request(self.endpoint, method="POST",
|
|
111
|
+
data=json.dumps(to_otlp_json(spans, self.service_name)).encode(),
|
|
112
|
+
headers={"Content-Type": "application/json", **self.headers})
|
|
113
|
+
try:
|
|
114
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as r:
|
|
115
|
+
r.read()
|
|
116
|
+
self.last_error = None
|
|
117
|
+
except (urllib.error.URLError, OSError) as exc:
|
|
118
|
+
self.last_error = str(exc)
|
|
119
|
+
print(f"[agent-tracedown] OTLP export failed: {exc}", file=sys.stderr)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class FanoutExporter(Exporter):
|
|
123
|
+
"""Send every run to several exporters (e.g. TDN server + OTLP collector)."""
|
|
124
|
+
|
|
125
|
+
def __init__(self, *exporters: Exporter) -> None:
|
|
126
|
+
self.exporters = exporters
|
|
127
|
+
|
|
128
|
+
def export(self, spans, blobs):
|
|
129
|
+
for e in self.exporters:
|
|
130
|
+
e.export(spans, blobs)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def to_otlp_json(spans: List[Dict[str, Any]], service_name: str = "agent") -> Dict[str, Any]:
|
|
134
|
+
"""Convert TDN spans to an OTLP/JSON ExportTraceServiceRequest body.
|
|
135
|
+
|
|
136
|
+
Lets TDN data go to Jaeger, Tempo, Datadog or any OTLP endpoint unchanged.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
def attr(k, v):
|
|
140
|
+
if isinstance(v, bool):
|
|
141
|
+
val = {"boolValue": v}
|
|
142
|
+
elif isinstance(v, int):
|
|
143
|
+
val = {"intValue": str(v)}
|
|
144
|
+
elif isinstance(v, float):
|
|
145
|
+
val = {"doubleValue": v}
|
|
146
|
+
else:
|
|
147
|
+
val = {"stringValue": v if isinstance(v, str) else json.dumps(v, default=str)}
|
|
148
|
+
return {"key": k, "value": val}
|
|
149
|
+
|
|
150
|
+
status_map = {"UNSET": 0, "OK": 1, "ERROR": 2}
|
|
151
|
+
otlp_spans = []
|
|
152
|
+
for s in spans:
|
|
153
|
+
attrs = dict(s["attributes"])
|
|
154
|
+
attrs["tdn.kind"] = s["kind"]
|
|
155
|
+
if s.get("input_digest"):
|
|
156
|
+
attrs["tdn.input.digest"] = s["input_digest"]
|
|
157
|
+
if s.get("output_digest"):
|
|
158
|
+
attrs["tdn.output.digest"] = s["output_digest"]
|
|
159
|
+
otlp_spans.append({
|
|
160
|
+
"traceId": s["trace_id"],
|
|
161
|
+
"spanId": s["span_id"],
|
|
162
|
+
"parentSpanId": s["parent_span_id"] or "",
|
|
163
|
+
"name": s["name"],
|
|
164
|
+
"kind": 1 if s["kind"] in ("agent", "decision", "memory") else 3, # INTERNAL / CLIENT
|
|
165
|
+
"startTimeUnixNano": str(s["start_time"]),
|
|
166
|
+
"endTimeUnixNano": str(s["end_time"] or s["start_time"]),
|
|
167
|
+
"attributes": [attr(k, v) for k, v in attrs.items()],
|
|
168
|
+
"status": {"code": status_map[s["status"]["code"]], "message": s["status"]["message"]},
|
|
169
|
+
})
|
|
170
|
+
return {"resourceSpans": [{
|
|
171
|
+
"resource": {"attributes": [attr("service.name", service_name)]},
|
|
172
|
+
"scopeSpans": [{"scope": {"name": "agent-tracedown", "version": "0.3.0"}, "spans": otlp_spans}],
|
|
173
|
+
}]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Agent framework integrations.
|
|
2
|
+
|
|
3
|
+
Each adapter turns a framework's own callbacks or events into TDN spans, so a run in
|
|
4
|
+
that framework shows up with its agents, LLM calls, tools, retrievals and handoffs.
|
|
5
|
+
|
|
6
|
+
| Framework | How to enable |
|
|
7
|
+
|-------------------|----------------------------------------------------------------------|
|
|
8
|
+
| LangChain/LangGraph | ``graph.invoke(x, config={"callbacks": [langchain.callback()]})`` |
|
|
9
|
+
| OpenAI Agents SDK | ``openai_agents.instrument()`` (adds a tracing processor) |
|
|
10
|
+
| Claude Agent SDK | ``async for m in claude_agent.trace_stream(query(...), name=...)`` |
|
|
11
|
+
| Google ADK | ``App(..., plugins=[google_adk.TracedownPlugin()])`` |
|
|
12
|
+
| Pydantic AI | ``await pydantic_ai.run(agent, prompt)`` (or ``run_sync``) |
|
|
13
|
+
| MCP clients | ``mcp.instrument(client)`` or ``mcp.instrument_all()`` |
|
|
14
|
+
| CrewAI | ``crewai.instrument()`` (registers an event listener) |
|
|
15
|
+
| AutoGen AgentChat | ``async for m in autogen.trace_stream(team.run_stream(task=t), ...)``|
|
|
16
|
+
| Semantic Kernel | ``semantic_kernel.instrument(kernel)`` inside ``tdn.run(...)`` |
|
|
17
|
+
| LlamaIndex | ``llamaindex.instrument()`` (span + event handlers) |
|
|
18
|
+
|
|
19
|
+
Adapters import their framework lazily: installing ``agent-tracedown`` never pulls in
|
|
20
|
+
a framework. Replay of adapter-traced runs works for steps that go through an
|
|
21
|
+
instrumented model client (``tdn.plugins.instrument("openai", client)``); framework
|
|
22
|
+
callbacks can observe but not substitute outputs.
|
|
23
|
+
"""
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import json
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def to_jsonable(value: Any, depth: int = 0) -> Any:
|
|
31
|
+
"""Best-effort conversion of framework objects (pydantic models, dataclasses,
|
|
32
|
+
messages) into JSON-safe values for payload capture."""
|
|
33
|
+
if depth > 6:
|
|
34
|
+
return str(value)
|
|
35
|
+
if value is None or isinstance(value, (str, int, float, bool)):
|
|
36
|
+
return value
|
|
37
|
+
if isinstance(value, dict):
|
|
38
|
+
return {str(k): to_jsonable(v, depth + 1) for k, v in value.items()}
|
|
39
|
+
if isinstance(value, (list, tuple, set)):
|
|
40
|
+
return [to_jsonable(v, depth + 1) for v in value]
|
|
41
|
+
for attr in ("model_dump", "dict", "to_dict"):
|
|
42
|
+
fn = getattr(value, attr, None)
|
|
43
|
+
if callable(fn):
|
|
44
|
+
try:
|
|
45
|
+
return to_jsonable(fn(), depth + 1)
|
|
46
|
+
except Exception: # noqa: BLE001
|
|
47
|
+
pass
|
|
48
|
+
if hasattr(value, "__dataclass_fields__"):
|
|
49
|
+
return {k: to_jsonable(getattr(value, k, None), depth + 1) for k in value.__dataclass_fields__}
|
|
50
|
+
content = getattr(value, "content", None)
|
|
51
|
+
if isinstance(content, str):
|
|
52
|
+
return content
|
|
53
|
+
try:
|
|
54
|
+
json.dumps(value)
|
|
55
|
+
return value
|
|
56
|
+
except TypeError:
|
|
57
|
+
return str(value)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def maybe_json(text: Any) -> Any:
|
|
61
|
+
if isinstance(text, str) and text[:1] in "{[":
|
|
62
|
+
try:
|
|
63
|
+
return json.loads(text)
|
|
64
|
+
except ValueError:
|
|
65
|
+
return text
|
|
66
|
+
return text
|