agent-strace 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.
- agent_strace-0.1.0/.github/workflows/publish.yml +26 -0
- agent_strace-0.1.0/.github/workflows/test.yml +27 -0
- agent_strace-0.1.0/.gitignore +16 -0
- agent_strace-0.1.0/LICENSE +190 -0
- agent_strace-0.1.0/PKG-INFO +375 -0
- agent_strace-0.1.0/README.md +350 -0
- agent_strace-0.1.0/examples/basic_agent.py +135 -0
- agent_strace-0.1.0/examples/claude_code_config.md +73 -0
- agent_strace-0.1.0/examples/cursor_config.md +66 -0
- agent_strace-0.1.0/examples/windsurf_config.md +50 -0
- agent_strace-0.1.0/pyproject.toml +39 -0
- agent_strace-0.1.0/src/agent_trace/__init__.py +3 -0
- agent_strace-0.1.0/src/agent_trace/cli.py +315 -0
- agent_strace-0.1.0/src/agent_trace/decorator.py +256 -0
- agent_strace-0.1.0/src/agent_trace/models.py +87 -0
- agent_strace-0.1.0/src/agent_trace/proxy.py +330 -0
- agent_strace-0.1.0/src/agent_trace/replay.py +256 -0
- agent_strace-0.1.0/src/agent_trace/store.py +88 -0
- agent_strace-0.1.0/tests/__init__.py +0 -0
- agent_strace-0.1.0/tests/test_decorator.py +153 -0
- agent_strace-0.1.0/tests/test_models.py +79 -0
- agent_strace-0.1.0/tests/test_store.py +102 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
environment:
|
|
14
|
+
name: pypi
|
|
15
|
+
url: https://pypi.org/p/agent-trace
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v4
|
|
21
|
+
|
|
22
|
+
- name: Build package
|
|
23
|
+
run: uv build
|
|
24
|
+
|
|
25
|
+
- name: Publish to PyPI
|
|
26
|
+
run: uv publish
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Run tests
|
|
25
|
+
run: python -m unittest discover -s tests -v
|
|
26
|
+
env:
|
|
27
|
+
PYTHONPATH: src
|
|
@@ -0,0 +1,190 @@
|
|
|
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 the 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 the 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 any 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
|
+
Copyright 2026 Siddhant Khare
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-strace
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: strace for AI agents. Capture and replay every tool call, LLM request, and decision point.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Siddhant-K-code/agent-trace
|
|
6
|
+
Project-URL: Repository, https://github.com/Siddhant-K-code/agent-trace
|
|
7
|
+
Project-URL: Issues, https://github.com/Siddhant-K-code/agent-trace/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/Siddhant-K-code/agent-trace#readme
|
|
9
|
+
Author-email: Siddhant Khare <siddhantkhare2694@gmail.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,ai,llm,mcp,observability,tool-calls,tracing
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
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
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# agent-trace
|
|
27
|
+
|
|
28
|
+
`strace` for AI agents.
|
|
29
|
+
|
|
30
|
+
Capture every tool call, LLM request, and decision point. Replay the session later. See what the agent did, in what order, and how long each step took.
|
|
31
|
+
|
|
32
|
+
We have `strace` for syscalls. We have `tcpdump` for packets. We have nothing for agent tool calls. This fills that gap.
|
|
33
|
+
|
|
34
|
+
## Why
|
|
35
|
+
|
|
36
|
+
When a coding agent rewrites 20 files in a background session, you get a pull request. You don't get the story of how it got there. Which files did it read first? What context was in the window when it decided to change the approach? Why did it call the same tool three times?
|
|
37
|
+
|
|
38
|
+
LangSmith traces LLM calls. That's one layer. The gap is everything around it: tool calls, file operations, decision points, error recovery. `agent-strace` captures the full picture.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# With uv (recommended)
|
|
44
|
+
uv tool install agent-strace
|
|
45
|
+
|
|
46
|
+
# Or with pip
|
|
47
|
+
pip install agent-strace
|
|
48
|
+
|
|
49
|
+
# Or run without installing
|
|
50
|
+
uvx agent-strace replay
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Zero dependencies.** Python 3.10+ standard library only.
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
### Option 1: MCP proxy
|
|
58
|
+
|
|
59
|
+
Wrap any MCP server. Every message between agent and server is captured.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Record a session
|
|
63
|
+
agent-strace record -- npx -y @modelcontextprotocol/server-filesystem /tmp
|
|
64
|
+
|
|
65
|
+
# List recorded sessions
|
|
66
|
+
agent-strace list
|
|
67
|
+
|
|
68
|
+
# Replay the last session
|
|
69
|
+
agent-strace replay
|
|
70
|
+
|
|
71
|
+
# Replay a specific session (prefix match works)
|
|
72
|
+
agent-strace replay a84664
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Option 2: Python decorator
|
|
76
|
+
|
|
77
|
+
Wrap your tool functions. No MCP required.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from agent_trace import trace_tool, trace_llm_call, start_session, end_session, log_decision
|
|
81
|
+
|
|
82
|
+
start_session(name="my-agent")
|
|
83
|
+
|
|
84
|
+
@trace_tool
|
|
85
|
+
def search_codebase(query: str) -> str:
|
|
86
|
+
return search(query)
|
|
87
|
+
|
|
88
|
+
@trace_llm_call
|
|
89
|
+
def call_llm(messages: list, model: str = "claude-4") -> str:
|
|
90
|
+
return client.chat(messages=messages, model=model)
|
|
91
|
+
|
|
92
|
+
# Log decision points explicitly
|
|
93
|
+
log_decision(
|
|
94
|
+
choice="read_file_first",
|
|
95
|
+
reason="Need to understand current implementation before making changes",
|
|
96
|
+
alternatives=["read_file_first", "search_codebase", "write_fix_directly"],
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
search_codebase("authenticate")
|
|
100
|
+
call_llm([{"role": "user", "content": "Fix the bug"}])
|
|
101
|
+
|
|
102
|
+
meta = end_session()
|
|
103
|
+
print(f"Replay with: agent-strace replay {meta.session_id}")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## CLI commands
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
agent-strace record -- <command> Record an MCP server session
|
|
110
|
+
agent-strace replay [session-id] Replay a session (default: latest)
|
|
111
|
+
agent-strace list List all sessions
|
|
112
|
+
agent-strace stats [session-id] Show tool call frequency and timing
|
|
113
|
+
agent-strace inspect <session-id> Dump full session as JSON
|
|
114
|
+
agent-strace export <session-id> Export as JSON, CSV, or NDJSON
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Replay output
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
Session Summary
|
|
121
|
+
──────────────────────────────────────────────────
|
|
122
|
+
Session: a84664242afa4516
|
|
123
|
+
Agent: coding-agent
|
|
124
|
+
Duration: 0.85s
|
|
125
|
+
Tool calls: 6
|
|
126
|
+
LLM reqs: 2
|
|
127
|
+
Errors: 1
|
|
128
|
+
──────────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
+ 0.00s ▶ session_start
|
|
131
|
+
+ 0.00s ⬆ llm_request claude-4 (1 messages)
|
|
132
|
+
+ 0.13s ⬇ llm_response (132ms)
|
|
133
|
+
+ 0.13s ◆ decision read_file_first
|
|
134
|
+
reason: Need to understand current implementation before making changes
|
|
135
|
+
+ 0.13s → tool_call read_file (path)
|
|
136
|
+
+ 0.16s ← tool_result [text] (22ms)
|
|
137
|
+
"contents of src/auth.py: def hello(): print('world')"
|
|
138
|
+
+ 0.16s → tool_call search_codebase (query)
|
|
139
|
+
+ 0.25s ← tool_result [text] (96ms)
|
|
140
|
+
+ 0.25s ⬆ llm_request claude-4 (3 messages)
|
|
141
|
+
+ 0.36s ⬇ llm_response (109ms)
|
|
142
|
+
+ 0.36s ◆ decision apply_fix
|
|
143
|
+
reason: LLM provided a clear fix, confidence is high
|
|
144
|
+
+ 0.36s → tool_call write_file (path, content)
|
|
145
|
+
+ 0.41s ← tool_result [text] (45ms)
|
|
146
|
+
+ 0.41s → tool_call run_tests (test_path)
|
|
147
|
+
+ 0.61s ✗ error Test failed: tests/test_auth.py
|
|
148
|
+
+ 0.61s ◆ decision retry_fix
|
|
149
|
+
reason: Tests failed, need to adjust the implementation
|
|
150
|
+
+ 0.61s → tool_call write_file (path, content)
|
|
151
|
+
+ 0.63s ← tool_result [text] (27ms)
|
|
152
|
+
+ 0.64s → tool_call run_tests (test_path)
|
|
153
|
+
+ 0.85s ← tool_result [text] (216ms)
|
|
154
|
+
+ 0.85s ■ session_end
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Stats output
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
Tool Call Frequency:
|
|
161
|
+
write_file 2x avg: 36ms
|
|
162
|
+
run_tests 2x avg: 216ms
|
|
163
|
+
read_file 1x avg: 22ms
|
|
164
|
+
search_codebase 1x avg: 96ms
|
|
165
|
+
|
|
166
|
+
Errors (1):
|
|
167
|
+
Test failed: tests/test_auth.py
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Filtering
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# Show only tool calls and errors
|
|
174
|
+
agent-strace replay --filter tool_call,error
|
|
175
|
+
|
|
176
|
+
# Replay with timing (watch it unfold)
|
|
177
|
+
agent-strace replay --live --speed 2
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Export
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
# JSON array
|
|
184
|
+
agent-strace export a84664 --format json
|
|
185
|
+
|
|
186
|
+
# CSV (for spreadsheets)
|
|
187
|
+
agent-strace export a84664 --format csv
|
|
188
|
+
|
|
189
|
+
# NDJSON (for streaming pipelines)
|
|
190
|
+
agent-strace export a84664 --format ndjson
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Trace format
|
|
194
|
+
|
|
195
|
+
Traces are stored as directories in `.agent-traces/`:
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
.agent-traces/
|
|
199
|
+
a84664242afa4516/
|
|
200
|
+
meta.json # session metadata
|
|
201
|
+
events.ndjson # newline-delimited JSON events
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Each event is a single JSON line:
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"event_type": "tool_call",
|
|
209
|
+
"timestamp": 1773562735.09,
|
|
210
|
+
"event_id": "bf1207728ee6",
|
|
211
|
+
"session_id": "a84664242afa4516",
|
|
212
|
+
"data": {
|
|
213
|
+
"tool_name": "read_file",
|
|
214
|
+
"arguments": {"path": "src/auth.py"}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Event types
|
|
220
|
+
|
|
221
|
+
| Type | Description |
|
|
222
|
+
|------|-------------|
|
|
223
|
+
| `session_start` | Trace session began |
|
|
224
|
+
| `session_end` | Trace session ended |
|
|
225
|
+
| `tool_call` | Agent invoked a tool |
|
|
226
|
+
| `tool_result` | Tool returned a result |
|
|
227
|
+
| `llm_request` | Agent sent a prompt to an LLM |
|
|
228
|
+
| `llm_response` | LLM returned a completion |
|
|
229
|
+
| `file_read` | Agent read a file |
|
|
230
|
+
| `file_write` | Agent wrote a file |
|
|
231
|
+
| `decision` | Agent chose between alternatives |
|
|
232
|
+
| `error` | Something failed |
|
|
233
|
+
|
|
234
|
+
Events link to each other. A `tool_result` has a `parent_id` pointing to its `tool_call`. This lets you measure latency per tool and trace the full call chain.
|
|
235
|
+
|
|
236
|
+
## Use with Claude Code, Cursor, Windsurf
|
|
237
|
+
|
|
238
|
+
agent-strace works with any tool that launches MCP servers. The idea is simple: instead of launching the MCP server directly, launch it through `agent-strace record`. The agent and server don't know the proxy exists.
|
|
239
|
+
|
|
240
|
+
### Claude Code
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# Instead of:
|
|
244
|
+
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /tmp
|
|
245
|
+
|
|
246
|
+
# Use:
|
|
247
|
+
claude mcp add filesystem -- agent-strace record --name filesystem -- npx -y @modelcontextprotocol/server-filesystem /tmp
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Or edit `.claude/mcp.json`:
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"mcpServers": {
|
|
255
|
+
"filesystem": {
|
|
256
|
+
"command": "agent-strace",
|
|
257
|
+
"args": ["record", "--name", "filesystem", "--", "npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Cursor
|
|
264
|
+
|
|
265
|
+
Edit `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` (per-project):
|
|
266
|
+
|
|
267
|
+
```json
|
|
268
|
+
{
|
|
269
|
+
"mcpServers": {
|
|
270
|
+
"filesystem": {
|
|
271
|
+
"command": "agent-strace",
|
|
272
|
+
"args": ["record", "--name", "filesystem", "--", "npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Windsurf
|
|
279
|
+
|
|
280
|
+
Edit `~/.codeium/windsurf/mcp_config.json`:
|
|
281
|
+
|
|
282
|
+
```json
|
|
283
|
+
{
|
|
284
|
+
"mcpServers": {
|
|
285
|
+
"filesystem": {
|
|
286
|
+
"command": "agent-strace",
|
|
287
|
+
"args": ["record", "--name", "filesystem", "--", "npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Any MCP client
|
|
294
|
+
|
|
295
|
+
The pattern is the same for any tool that uses MCP over stdio:
|
|
296
|
+
|
|
297
|
+
1. Replace the server `command` with `agent-strace`
|
|
298
|
+
2. Prepend `record --name <label> --` to the original args
|
|
299
|
+
3. Use the tool normally
|
|
300
|
+
4. Run `agent-strace replay` to see what happened
|
|
301
|
+
|
|
302
|
+
See the [examples/](examples/) directory for full config files.
|
|
303
|
+
|
|
304
|
+
## How it works
|
|
305
|
+
|
|
306
|
+
### MCP proxy mode
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
Agent ←→ agent-strace proxy ←→ MCP Server
|
|
310
|
+
↓
|
|
311
|
+
.agent-traces/
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
The proxy reads JSON-RPC messages (Content-Length framed, like LSP), classifies each message as a tool call, result, error, or notification, and writes a trace event. The message is forwarded unchanged. The agent and server don't know the proxy exists.
|
|
315
|
+
|
|
316
|
+
### Decorator mode
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
@trace_tool
|
|
320
|
+
def my_function(x):
|
|
321
|
+
return x * 2
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
The decorator wraps the function call. It logs a `tool_call` event before execution and a `tool_result` event after. If the function raises, it logs an `error` event. Timing is captured automatically.
|
|
325
|
+
|
|
326
|
+
## Project structure
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
src/agent_trace/
|
|
330
|
+
__init__.py # version
|
|
331
|
+
models.py # TraceEvent, SessionMeta, EventType
|
|
332
|
+
store.py # NDJSON file storage
|
|
333
|
+
proxy.py # MCP stdio proxy
|
|
334
|
+
replay.py # terminal replay and display
|
|
335
|
+
decorator.py # @trace_tool, @trace_llm_call, log_decision
|
|
336
|
+
cli.py # CLI entry point
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Running tests
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
python -m unittest discover -s tests -v
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Development
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
git clone https://github.com/Siddhant-K-code/agent-trace.git
|
|
349
|
+
cd agent-trace
|
|
350
|
+
|
|
351
|
+
# Run tests
|
|
352
|
+
python -m unittest discover -s tests -v
|
|
353
|
+
|
|
354
|
+
# Run the example
|
|
355
|
+
PYTHONPATH=src python examples/basic_agent.py
|
|
356
|
+
|
|
357
|
+
# Replay the example
|
|
358
|
+
PYTHONPATH=src python -m agent_trace.cli replay
|
|
359
|
+
|
|
360
|
+
# Build the package
|
|
361
|
+
uv build
|
|
362
|
+
|
|
363
|
+
# Install locally for testing
|
|
364
|
+
uv tool install -e .
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Related
|
|
368
|
+
|
|
369
|
+
- [The agent observability gap](https://siddhantkhare.com/blog/agent-observability-gap) - the problem this tool addresses
|
|
370
|
+
- [The Agentic Engineering Guide](https://agents.siddhantkhare.com) - chapters 7, 9, 10 cover agent security and observability
|
|
371
|
+
- [OpenTelemetry GenAI](https://opentelemetry.io/docs/specs/semconv/gen-ai/) - semantic conventions for LLM tracing (complementary)
|
|
372
|
+
|
|
373
|
+
## License
|
|
374
|
+
|
|
375
|
+
Apache 2.0
|