agent-doctor-cli 0.5.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.
Files changed (117) hide show
  1. agent_doctor_cli-0.5.0/.gitattributes +4 -0
  2. agent_doctor_cli-0.5.0/.github/workflows/release.yml +47 -0
  3. agent_doctor_cli-0.5.0/.github/workflows/tests.yml +26 -0
  4. agent_doctor_cli-0.5.0/.gitignore +28 -0
  5. agent_doctor_cli-0.5.0/CHANGELOG.md +57 -0
  6. agent_doctor_cli-0.5.0/LAUNCH_TODO.txt +56 -0
  7. agent_doctor_cli-0.5.0/LICENSE +21 -0
  8. agent_doctor_cli-0.5.0/PKG-INFO +378 -0
  9. agent_doctor_cli-0.5.0/README.md +344 -0
  10. agent_doctor_cli-0.5.0/evals/.gitkeep +0 -0
  11. agent_doctor_cli-0.5.0/examples/__init__.py +1 -0
  12. agent_doctor_cli-0.5.0/examples/bad_agent/.gitkeep +0 -0
  13. agent_doctor_cli-0.5.0/examples/bad_agent/README.md +51 -0
  14. agent_doctor_cli-0.5.0/examples/bad_agent/__init__.py +12 -0
  15. agent_doctor_cli-0.5.0/examples/bad_agent/agent.py +294 -0
  16. agent_doctor_cli-0.5.0/examples/bad_agent/eval_suite.py +89 -0
  17. agent_doctor_cli-0.5.0/examples/bad_agent/fake_llm.py +144 -0
  18. agent_doctor_cli-0.5.0/examples/bad_agent/generate.py +106 -0
  19. agent_doctor_cli-0.5.0/examples/bad_agent/scenarios.py +77 -0
  20. agent_doctor_cli-0.5.0/examples/bad_agent/score.py +108 -0
  21. agent_doctor_cli-0.5.0/examples/bad_agent/tools.py +96 -0
  22. agent_doctor_cli-0.5.0/examples/demo_pricing.yaml +5 -0
  23. agent_doctor_cli-0.5.0/examples/hf_quickstart.py +65 -0
  24. agent_doctor_cli-0.5.0/examples/offline_demo.py +105 -0
  25. agent_doctor_cli-0.5.0/examples/real_agent/README.md +84 -0
  26. agent_doctor_cli-0.5.0/examples/real_agent/__init__.py +1 -0
  27. agent_doctor_cli-0.5.0/examples/real_agent/agent.py +195 -0
  28. agent_doctor_cli-0.5.0/examples/real_agent/eval_suite.py +87 -0
  29. agent_doctor_cli-0.5.0/examples/real_agent/local_pricing.yaml +6 -0
  30. agent_doctor_cli-0.5.0/examples/real_agent/questions.py +25 -0
  31. agent_doctor_cli-0.5.0/examples/real_agent/record.py +36 -0
  32. agent_doctor_cli-0.5.0/pyproject.toml +68 -0
  33. agent_doctor_cli-0.5.0/space/README.md +35 -0
  34. agent_doctor_cli-0.5.0/space/app.py +247 -0
  35. agent_doctor_cli-0.5.0/space/requirements.txt +1 -0
  36. agent_doctor_cli-0.5.0/space/sync.py +39 -0
  37. agent_doctor_cli-0.5.0/src/agent_doctor/__init__.py +42 -0
  38. agent_doctor_cli-0.5.0/src/agent_doctor/_util.py +166 -0
  39. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/__init__.py +34 -0
  40. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/base.py +208 -0
  41. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/bloat.py +44 -0
  42. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/compare.py +96 -0
  43. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/cost.py +97 -0
  44. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/latency.py +89 -0
  45. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/loops.py +168 -0
  46. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/redundancy.py +123 -0
  47. agent_doctor_cli-0.5.0/src/agent_doctor/analyzers/report.py +181 -0
  48. agent_doctor_cli-0.5.0/src/agent_doctor/cli.py +770 -0
  49. agent_doctor_cli-0.5.0/src/agent_doctor/config.py +41 -0
  50. agent_doctor_cli-0.5.0/src/agent_doctor/core.py +212 -0
  51. agent_doctor_cli-0.5.0/src/agent_doctor/evals/__init__.py +52 -0
  52. agent_doctor_cli-0.5.0/src/agent_doctor/evals/cases.py +67 -0
  53. agent_doctor_cli-0.5.0/src/agent_doctor/evals/results.py +46 -0
  54. agent_doctor_cli-0.5.0/src/agent_doctor/evals/runner.py +332 -0
  55. agent_doctor_cli-0.5.0/src/agent_doctor/evals/scorers.py +196 -0
  56. agent_doctor_cli-0.5.0/src/agent_doctor/evals/stats.py +48 -0
  57. agent_doctor_cli-0.5.0/src/agent_doctor/evals/suite.py +72 -0
  58. agent_doctor_cli-0.5.0/src/agent_doctor/ingest/__init__.py +75 -0
  59. agent_doctor_cli-0.5.0/src/agent_doctor/ingest/common.py +165 -0
  60. agent_doctor_cli-0.5.0/src/agent_doctor/ingest/langfuse.py +96 -0
  61. agent_doctor_cli-0.5.0/src/agent_doctor/ingest/langsmith.py +111 -0
  62. agent_doctor_cli-0.5.0/src/agent_doctor/ingest/otel.py +123 -0
  63. agent_doctor_cli-0.5.0/src/agent_doctor/ingest/redact.py +102 -0
  64. agent_doctor_cli-0.5.0/src/agent_doctor/mcp_server.py +344 -0
  65. agent_doctor_cli-0.5.0/src/agent_doctor/pricing/__init__.py +14 -0
  66. agent_doctor_cli-0.5.0/src/agent_doctor/pricing/cost.py +110 -0
  67. agent_doctor_cli-0.5.0/src/agent_doctor/pricing/pricing.yaml +50 -0
  68. agent_doctor_cli-0.5.0/src/agent_doctor/pricing/table.py +121 -0
  69. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/__init__.py +30 -0
  70. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/knowledge.py +106 -0
  71. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/llm.py +81 -0
  72. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/anthropic-prompt-caching.md +43 -0
  73. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/cache-tool-results.md +45 -0
  74. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/circuit-breaker.md +48 -0
  75. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/dedupe-model-queries.md +37 -0
  76. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/llm-rate-limit-backoff.md +35 -0
  77. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/openai-prompt-caching.md +36 -0
  78. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/parallel-tool-calls.md +43 -0
  79. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/remove-unused-tool-calls.md +32 -0
  80. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/retry-with-backoff.md +49 -0
  81. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/route-to-small-model.md +37 -0
  82. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/speed-up-slow-tools.md +41 -0
  83. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/stable-prompt-prefix.md +35 -0
  84. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/stop-no-progress-loops.md +34 -0
  85. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/surface-tool-failures.md +33 -0
  86. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/playbooks/trim-context.md +32 -0
  87. agent_doctor_cli-0.5.0/src/agent_doctor/recommender/recommend.py +181 -0
  88. agent_doctor_cli-0.5.0/src/agent_doctor/replay/__init__.py +26 -0
  89. agent_doctor_cli-0.5.0/src/agent_doctor/replay/engine.py +300 -0
  90. agent_doctor_cli-0.5.0/src/agent_doctor/schema.py +277 -0
  91. agent_doctor_cli-0.5.0/src/agent_doctor/sdk/__init__.py +17 -0
  92. agent_doctor_cli-0.5.0/src/agent_doctor/sdk/decorators.py +259 -0
  93. agent_doctor_cli-0.5.0/src/agent_doctor/sdk/instrument.py +419 -0
  94. agent_doctor_cli-0.5.0/src/agent_doctor/sdk/recorder.py +272 -0
  95. agent_doctor_cli-0.5.0/src/agent_doctor/store/__init__.py +14 -0
  96. agent_doctor_cli-0.5.0/src/agent_doctor/store/sqlite.py +312 -0
  97. agent_doctor_cli-0.5.0/src/agent_doctor/testing.py +75 -0
  98. agent_doctor_cli-0.5.0/tests/__init__.py +0 -0
  99. agent_doctor_cli-0.5.0/tests/conftest.py +44 -0
  100. agent_doctor_cli-0.5.0/tests/fakes.py +132 -0
  101. agent_doctor_cli-0.5.0/tests/fixtures/bad_agent/labels.json +743 -0
  102. agent_doctor_cli-0.5.0/tests/fixtures/bad_agent/runs.json +17246 -0
  103. agent_doctor_cli-0.5.0/tests/fixtures/sample_run.json +51 -0
  104. agent_doctor_cli-0.5.0/tests/test_analyzers.py +280 -0
  105. agent_doctor_cli-0.5.0/tests/test_bad_agent.py +184 -0
  106. agent_doctor_cli-0.5.0/tests/test_cli.py +118 -0
  107. agent_doctor_cli-0.5.0/tests/test_evals.py +341 -0
  108. agent_doctor_cli-0.5.0/tests/test_ingest.py +220 -0
  109. agent_doctor_cli-0.5.0/tests/test_instrument.py +217 -0
  110. agent_doctor_cli-0.5.0/tests/test_mcp_server.py +208 -0
  111. agent_doctor_cli-0.5.0/tests/test_pricing.py +128 -0
  112. agent_doctor_cli-0.5.0/tests/test_recommender.py +147 -0
  113. agent_doctor_cli-0.5.0/tests/test_replay.py +289 -0
  114. agent_doctor_cli-0.5.0/tests/test_schema.py +222 -0
  115. agent_doctor_cli-0.5.0/tests/test_sdk.py +262 -0
  116. agent_doctor_cli-0.5.0/tests/test_space.py +51 -0
  117. agent_doctor_cli-0.5.0/tests/test_store.py +104 -0
@@ -0,0 +1,4 @@
1
+ # Keep fixtures byte-identical across Windows and Linux checkouts.
2
+ *.json text eol=lf
3
+ *.yaml text eol=lf
4
+ *.py text eol=lf
@@ -0,0 +1,47 @@
1
+ name: release
2
+
3
+ # Publishes to PyPI when a version tag (v0.5.0, ...) is pushed. Uses PyPI trusted publishing:
4
+ # add this repository and workflow as a trusted publisher on pypi.org first; no token needed.
5
+ on:
6
+ push:
7
+ tags: ["v*"]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+ - name: Test
18
+ run: |
19
+ python -m pip install -e ".[dev]"
20
+ ruff check .
21
+ pytest
22
+ - name: Check the tag matches the version
23
+ run: |
24
+ version=$(python -c "import agent_doctor; print(agent_doctor.__version__)")
25
+ test "v$version" = "$GITHUB_REF_NAME" || { echo "tag $GITHUB_REF_NAME != version $version"; exit 1; }
26
+ - name: Build
27
+ run: |
28
+ python -m pip install build twine
29
+ python -m build
30
+ twine check dist/*
31
+ - uses: actions/upload-artifact@v4
32
+ with:
33
+ name: dist
34
+ path: dist/
35
+
36
+ publish:
37
+ needs: build
38
+ runs-on: ubuntu-latest
39
+ environment: pypi
40
+ permissions:
41
+ id-token: write
42
+ steps:
43
+ - uses: actions/download-artifact@v4
44
+ with:
45
+ name: dist
46
+ path: dist/
47
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,26 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, windows-latest]
15
+ python-version: ["3.10", "3.11", "3.12"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+ - name: Install
22
+ run: python -m pip install -e ".[dev]"
23
+ - name: Lint
24
+ run: ruff check .
25
+ - name: Test
26
+ run: pytest
@@ -0,0 +1,28 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .venv/
6
+ venv/
7
+ dist/
8
+ build/
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ htmlcov/
13
+
14
+ # Agent Doctor local data
15
+ *.db
16
+ .agent-doctor/
17
+
18
+ # Secrets
19
+ .env
20
+
21
+ # Editors / OS
22
+ .vscode/
23
+ .idea/
24
+ .DS_Store
25
+ Thumbs.db
26
+
27
+ # Generated by space/sync.py; uploaded with the Space, not committed
28
+ space/data/
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ ## 0.5.0
4
+
5
+ First public release, on PyPI as `agent-doctor-cli` (PyPI treats `agentdoctor` as the same name
6
+ as the existing `agent-doctor`).
7
+ The command is still `agent-doctor` and the import is still `agent_doctor`.
8
+
9
+ - **Recommender**: `agent-doctor recommend [RUN]` turns findings into a ranked fix plan from a
10
+ library of 15 playbooks (why, fix with code, how to verify). Retrieval is deterministic
11
+ (problem match + BM25 + provider filter); `--llm anthropic|openai:MODEL|hf:MODEL` also has an
12
+ LLM write the plan from the evidence and the retrieved playbooks. `agent-doctor playbooks`
13
+ lists and searches them; add your own with `--playbooks DIR`.
14
+ - **Importers**: `agent-doctor import` reads OpenTelemetry (OTLP JSON, GenAI conventions),
15
+ Langfuse and LangSmith exports, as well as Agent Doctor JSON.
16
+ - **Redaction**: `--redact` on import, or `AGENT_DOCTOR_REDACT=1` while recording, scrubs
17
+ emails, phone numbers, card numbers, API keys, tokens and IP addresses.
18
+ - **Saved evaluations**: `agent-doctor eval` saves its results; `agent-doctor evals [ID]`
19
+ lists or shows them.
20
+ - **MCP**: new `recommend_fixes`, `search_playbooks`, `list_evals` and `get_eval` tools.
21
+ - **Hugging Face Space** demo in `space/`.
22
+
23
+ Fixes found by running it on a real tool-calling agent (`examples/real_agent/`):
24
+
25
+ - Eval comparisons now say what each scorer fixed and broke. Before, one scorer that failed
26
+ every case kept the overall verdict at "same" and hid a drop in the others.
27
+ `ScorerComparison` has new `improved` and `regressed` case lists.
28
+ - Replayed and evaluated runs keep the agent's `@trace_run` labels (`prompt_version`,
29
+ `agent_version`, tags). They used to be dropped.
30
+ - "Swallowed tool failure" no longer fires when the answer tells the user the data is
31
+ unavailable or timed out. When the tool worked for other inputs, the title names the
32
+ failing arguments.
33
+ - New example: `examples/real_agent/`, with a recording script, an eval suite comparing two
34
+ prompts and two models, and a write-up of what it found.
35
+
36
+ ## 0.4.0
37
+
38
+ - Replay: `agent-doctor replay RUN --agent module:function` re-runs your agent on a saved run,
39
+ with tool calls answered from the recording, side-effect tools blocked, and `-m OLD=NEW`
40
+ model swaps.
41
+ - Evaluation: `agent-doctor eval SUITE.py` scores agent versions with built-in or custom
42
+ scorers, compares them case by case with an exact McNemar test, and exits 1 on regressions.
43
+
44
+ ## 0.3.0
45
+
46
+ - MCP server (`agent-doctor mcp`) with seven read-only tools for Claude, Cursor and other
47
+ MCP clients.
48
+
49
+ ## 0.2.0
50
+
51
+ - Twelve deterministic detectors, `agent-doctor analyze` and `agent-doctor scan`.
52
+ - The bad agent: 32 fixture runs with 36 planted problems and an answer key.
53
+
54
+ ## 0.1.0
55
+
56
+ - Recording SDK (`instrument()`, `@trace_run`, `@trace_tool`), SQLite store, pricing and
57
+ `agent-doctor cost`.
@@ -0,0 +1,56 @@
1
+ AGENT DOCTOR - LAUNCH CHECKLIST (things only you can do)
2
+ =========================================================
3
+
4
+ Package name on PyPI: agent-doctor-cli (agent-doctor was already taken)
5
+ Command stays: agent-doctor
6
+ Python import stays: agent_doctor
7
+ Version to release: 0.5.0
8
+ GitHub repo: https://github.com/kushagra2304/agent-doctor (currently PRIVATE)
9
+
10
+
11
+ 0. PUSH THE LATEST COMMIT -- DONE (cbe3496 pushed, includes the real-agent fixes)
12
+
13
+ 0b. DECIDE WHAT GOES IN 0.5.0
14
+ - 0.5.0 is not on PyPI yet, so the real-agent fixes (CHANGELOG "Unreleased") can ship in it.
15
+ - Tell Claude "fold Unreleased into 0.5.0" before tagging, or keep them for 0.5.1.
16
+
17
+ 1. CHECK THAT CI PASSED ON GITHUB
18
+ - Open https://github.com/kushagra2304/agent-doctor/actions
19
+ - The "tests" workflow for the latest commit on main should be green.
20
+ - If it failed, copy the error to Claude.
21
+
22
+ 2. (OPTIONAL) MAKE THE GITHUB REPO PUBLIC
23
+ - The PyPI page and the demo link to the repo. While it is private, those links
24
+ are broken for everyone else.
25
+ - GitHub repo -> Settings -> General -> Danger Zone -> Change visibility -> Public.
26
+
27
+ 3. SET UP PYPI PUBLISHING (one time, no token needed)
28
+ - Log in at https://pypi.org (create an account if needed, turn on 2FA).
29
+ - Account settings -> Publishing -> "Add a new pending publisher" -> GitHub tab:
30
+ PyPI project name: agent-doctor-cli
31
+ Owner: kushagra2304
32
+ Repository name: agent-doctor
33
+ Workflow name: release.yml
34
+ Environment name: pypi
35
+ - Save.
36
+
37
+ 4. PUBLISH VERSION 0.5.0 TO PYPI
38
+ - Either tell Claude "PyPI is set up, push the tag", or run in the project folder:
39
+ git tag v0.5.0
40
+ git push origin v0.5.0
41
+ - This starts the "release" workflow: it runs the tests, builds the package and
42
+ publishes it. Watch it in the Actions tab.
43
+ - Check it worked: pip install agent-doctor-cli then agent-doctor --version
44
+
45
+ 5. PUBLISH THE HUGGING FACE DEMO (after step 4, the demo installs agent-doctor-cli from PyPI)
46
+ - Create a Hugging Face account at https://huggingface.co if needed.
47
+ - Make a token with WRITE access: Settings -> Access Tokens -> New token.
48
+ - In the project folder run: .venv\Scripts\hf auth login and paste the token.
49
+ - Tell Claude your Hugging Face username. Claude will then run:
50
+ python space/sync.py
51
+ hf upload <username>/agent-doctor space . --repo-type space
52
+ - Open https://huggingface.co/spaces/<username>/agent-doctor and try every tab.
53
+
54
+ 6. AFTER LAUNCH (optional)
55
+ - Add the Space link and "pip install agent-doctor-cli" badge to the top of README.md.
56
+ - Announce it (GitHub release notes can reuse CHANGELOG.md, section 0.5.0).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kushagra Sharma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,378 @@
1
+ Metadata-Version: 2.5
2
+ Name: agent-doctor-cli
3
+ Version: 0.5.0
4
+ Summary: Find out why your AI agent is expensive, slow or unreliable, and how to fix it.
5
+ Project-URL: Homepage, https://github.com/kushagra2304/agent-doctor
6
+ Project-URL: Source, https://github.com/kushagra2304/agent-doctor
7
+ Project-URL: Issues, https://github.com/kushagra2304/agent-doctor/issues
8
+ Project-URL: Changelog, https://github.com/kushagra2304/agent-doctor/blob/main/CHANGELOG.md
9
+ Author: Kushagra Sharma
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,evaluation,langfuse,langsmith,llm,mcp,observability,opentelemetry,tracing
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Debuggers
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: pydantic>=2.6
23
+ Requires-Dist: pyyaml>=6.0
24
+ Requires-Dist: typer>=0.12
25
+ Provides-Extra: dev
26
+ Requires-Dist: mcp<3,>=2.3; extra == 'dev'
27
+ Requires-Dist: pytest>=8.0; extra == 'dev'
28
+ Requires-Dist: ruff>=0.5; extra == 'dev'
29
+ Provides-Extra: hf
30
+ Requires-Dist: huggingface-hub>=0.28; extra == 'hf'
31
+ Provides-Extra: mcp
32
+ Requires-Dist: mcp<3,>=2.3; extra == 'mcp'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Agent Doctor
36
+
37
+ Find out why your AI agent is expensive, slow or unreliable, and how to fix it.
38
+
39
+ Agent Doctor records every step of an agent run (LLM calls, tool calls, retries,
40
+ errors), finds wasted cost and time, and recommends concrete fixes. It exposes
41
+ all of this as MCP tools, so you can ask Claude or Cursor *"why was run_482 so
42
+ expensive?"* and get a real answer. A replay engine lets you test a new prompt
43
+ or model against saved runs before you deploy.
44
+
45
+ > Status: **0.5.0, ready for a first release**. Recording, cost, problem detection, fix plans, the MCP server, replay, evaluation and importers from other tracing tools all work.
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ pip install agent-doctor-cli # the package is "agent-doctor-cli"; the command is agent-doctor
51
+ pip install "agent-doctor-cli[mcp]" # plus the MCP server for Claude, Cursor and other clients
52
+ pip install "agent-doctor-cli[mcp,hf]" # plus Hugging Face InferenceClient support
53
+ ```
54
+
55
+ In Python, import it as `agent_doctor`. Try it in the browser first: the
56
+ [Hugging Face Space](space/README.md) runs the demo with no install.
57
+
58
+ ## Quick start (development)
59
+
60
+ Windows (PowerShell). Needs Python 3.10 or newer; check with `python --version`.
61
+ These commands use the venv's own Python, so no activation step is needed:
62
+
63
+ ```powershell
64
+ python -m venv .venv
65
+ .venv\Scripts\python -m pip install -e ".[dev,hf]"
66
+ .venv\Scripts\python -m pytest
67
+ .venv\Scripts\agent-doctor validate tests/fixtures/sample_run.json
68
+ ```
69
+
70
+ macOS / Linux:
71
+
72
+ ```bash
73
+ python3 -m venv .venv
74
+ source .venv/bin/activate
75
+ pip install -e ".[dev,hf]"
76
+ pytest
77
+ agent-doctor validate tests/fixtures/sample_run.json
78
+ ```
79
+
80
+ ## Record your agent
81
+
82
+ ```python
83
+ from huggingface_hub import InferenceClient
84
+ from agent_doctor import instrument, trace_run, trace_tool
85
+
86
+ client = instrument(InferenceClient(model="Qwen/Qwen2.5-7B-Instruct")) # every LLM call recorded
87
+
88
+ @trace_tool # each call becomes a tool span (args, output, errors, retries)
89
+ def search_orders(order_id: str): ...
90
+
91
+ @trace_tool(side_effects=True) # never called live during replay
92
+ def send_reply(text: str): ...
93
+
94
+ @trace_run(agent="support-bot", prompt_version="v3") # each call becomes one run
95
+ def handle(message: str) -> str: ...
96
+ ```
97
+
98
+ `instrument()` also works with OpenAI-compatible and Anthropic clients, sync or async,
99
+ streaming or not. Runs are saved to `~/.agent-doctor/traces.db`. Recording never breaks
100
+ your agent: if anything goes wrong it warns once and carries on. Set
101
+ `AGENT_DOCTOR_DISABLED=1` to turn it off.
102
+
103
+ Try it without an API key:
104
+
105
+ ```bash
106
+ python examples/offline_demo.py
107
+ agent-doctor runs --prices examples/demo_pricing.yaml
108
+ agent-doctor show last # every step, with retries and errors
109
+ agent-doctor cost last --prices examples/demo_pricing.yaml
110
+ ```
111
+
112
+ Or with a real open model (needs `HF_TOKEN`): `python examples/hf_quickstart.py`.
113
+
114
+ ## Find the problems
115
+
116
+ ```bash
117
+ agent-doctor analyze last # one run: problems, evidence steps, estimated waste, fixes
118
+ agent-doctor scan -n 100 # many runs: which problems are most common and costly
119
+ ```
120
+
121
+ Twelve deterministic detectors (plain code, no LLM calls, so analysis is free and instant):
122
+
123
+ | Detector | Finds |
124
+ | --- | --- |
125
+ | Exact duplicate tool call | The same tool called again with the same arguments |
126
+ | Near-duplicate tool call | The same question reworded, returning the same result |
127
+ | Unused tool output | A tool result that never reaches any later LLM call |
128
+ | Tool retry loop | A failing call retried 2+ times, flagged when there is no backoff |
129
+ | LLM retry without backoff | Rate-limited or failed LLM calls retried immediately |
130
+ | No-progress loop | The agent keeps calling tools that return nothing new |
131
+ | Swallowed failure | A tool never worked, yet the run ended "ok" with an answer |
132
+ | Slow step | One tool taking most of the run |
133
+ | Sequential independent calls | Back-to-back calls that could run in parallel |
134
+ | Context bloat | Prompts growing steadily as history and raw tool output pile up |
135
+ | Expensive model for a simple step | A large model producing a one-word decision |
136
+ | Prompt cache miss | A long shared prompt never served from cache, e.g. a timestamp at the top |
137
+
138
+ Each finding names the steps that prove it (as numbered by `agent-doctor show`) and
139
+ estimates the wasted cost, time or tokens. All thresholds live in
140
+ `agent_doctor.analyzers.Thresholds`.
141
+
142
+ **Graded against an answer key.** On the [bad agent](examples/bad_agent/README.md)'s 32
143
+ runs the detectors find all 36 planted problems with no false alarms on the clean runs:
144
+ `python -m examples.bad_agent.score`.
145
+
146
+ ## Get a fix plan
147
+
148
+ ```bash
149
+ agent-doctor recommend last # one run
150
+ agent-doctor recommend -n 200 # the fixes that matter most across recent runs
151
+ agent-doctor recommend last --llm anthropic # also have Claude write the plan up
152
+ ```
153
+
154
+ Each finding is matched to fix playbooks: why the problem matters, how to fix it with code,
155
+ and how to verify the fix with `replay` or `eval`. Fixes are ranked by severity and by the
156
+ waste they remove. Provider-specific advice (prompt caching for Claude or OpenAI) only shows
157
+ up when the run actually used that provider.
158
+
159
+ Retrieval is deterministic and free: no LLM is needed. With `--llm anthropic` (default model
160
+ `claude-opus-5-5`), `--llm openai:MODEL` or `--llm hf:MODEL`, an LLM also writes a short plan
161
+ from the run's evidence and the retrieved playbooks, citing them by ID. Over MCP, Claude or
162
+ Cursor gets the playbooks from `recommend_fixes` and writes the plan itself.
163
+
164
+ Browse the playbooks with `agent-doctor playbooks [QUERY]` and `agent-doctor playbooks --show ID`.
165
+ Add your team's own as markdown files with front matter and pass `--playbooks DIR`; see
166
+ [the built-in ones](src/agent_doctor/recommender/playbooks/) for the format.
167
+
168
+ ## Bring traces from other tools
169
+
170
+ ```bash
171
+ agent-doctor import otel-export.json # OpenTelemetry (OTLP JSON, GenAI conventions)
172
+ agent-doctor import langfuse-observations.json # Langfuse API or trace export
173
+ agent-doctor import langsmith-runs.json # LangSmith runs (flat or with child_runs)
174
+ agent-doctor import traces.jsonl --redact # JSON lines too; scrub personal data first
175
+ ```
176
+
177
+ The format is detected automatically (`--format` to force one). One trace becomes one run;
178
+ LLM calls, tool calls, errors and token counts are mapped onto Agent Doctor's schema, and
179
+ retries of failed tool calls are linked, so every detector works on imported traces.
180
+
181
+ **Redaction.** `--redact` on import, or `AGENT_DOCTOR_REDACT=1` while recording, replaces
182
+ emails, phone numbers, card numbers (Luhn-checked), API keys, bearer tokens, JWTs, AWS keys and
183
+ IP addresses with placeholders, and masks values under keys like `password` or `api_key`.
184
+ Duplicate-call detection keeps working, because argument hashes are taken before redaction.
185
+ Add your own patterns with `agent_doctor.ingest.Redactor(extra=[("ORDER", r"ORD-\d+")])`.
186
+
187
+ ## Ask Claude or Cursor about your runs (MCP)
188
+
189
+ ```bash
190
+ pip install "agent-doctor-cli[mcp]"
191
+ claude mcp add agent-doctor -- agent-doctor mcp # Claude Code
192
+ ```
193
+
194
+ For Claude Desktop, Cursor or any other MCP client, add this to its MCP config
195
+ (`claude_desktop_config.json`, `.cursor/mcp.json`). If `agent-doctor` is installed in a
196
+ virtualenv, give the full path to it as `command`:
197
+
198
+ ```json
199
+ {
200
+ "mcpServers": {
201
+ "agent-doctor": {"command": "agent-doctor", "args": ["mcp"]}
202
+ }
203
+ }
204
+ ```
205
+
206
+ Add `"--prices", "path/to/pricing.yaml"` after `"mcp"` for extra prices, or `"--db", "path/to/traces.db"`
207
+ before it for another database. Then ask things like *"why was the last run so expensive?"*
208
+ or *"what problems does support-bot have most often?"*.
209
+
210
+ The server has eleven read-only tools. They never change your data or call your agent:
211
+
212
+ | Tool | Answers |
213
+ | --- | --- |
214
+ | `list_runs` | Which runs are there, and what did each cost? |
215
+ | `analyze_run` | What went wrong in this run, which steps prove it, and how do I fix it? |
216
+ | `explain_cost` | Where did the money go: per model, per step, cache savings, cost of 1,000 runs |
217
+ | `show_run` | What happened, step by step? |
218
+ | `get_step` | The full prompt, output, tool arguments and result of one step, and the findings that cite it |
219
+ | `scan_runs` | Which problems are most common and most costly across many runs? |
220
+ | `compare_runs` | Why did this run cost or take more than that one? |
221
+ | `recommend_fixes` | How do I fix it? The playbooks that remove the most waste, with code and how to verify |
222
+ | `search_playbooks` | Find a fix playbook by topic, e.g. "prompt caching with Claude" |
223
+ | `list_evals` | Which evaluations have been run, and what was each verdict? |
224
+ | `get_eval` | Did the new prompt or model break anything? Pass rates, cost, latency, and the broken and fixed cases with both answers |
225
+
226
+ ## Test a change before you deploy
227
+
228
+ ### Replay a run
229
+
230
+ Run your agent again on a saved run's input, with a new prompt, model or code:
231
+
232
+ ```bash
233
+ agent-doctor replay last --agent my_app.bot:handle # handle(task_input)
234
+ agent-doctor replay last --agent my_app.bot:handle -m gpt-4o=gpt-4o-mini
235
+ ```
236
+
237
+ You get the old and new answer side by side, the change in time, calls, tokens and cost,
238
+ and which problems were fixed, which are new, and which are still there.
239
+
240
+ - **Tool calls are answered from the recording.** A call matching a recorded one (same tool,
241
+ same arguments) returns the recorded output, or raises the recorded error again with its
242
+ original exception class, without running the tool. Each one also takes as long as the
243
+ recorded call did, so durations compare fairly (`--no-latency` to skip that).
244
+ - **Side-effect tools never run.** `@trace_tool(side_effects=True)` tools are stubbed, so a
245
+ replay never sends an email or charges a card.
246
+ - **New calls run live**, unless you pass `--strict`. `--live-tools` runs every tool live
247
+ (side-effect tools still never run).
248
+ - **LLM calls are live.** They are what you are testing. `-m OLD=NEW` swaps models without
249
+ touching your code.
250
+
251
+ From Python: `agent_doctor.replay.replay(run, handle, model_map={...})`.
252
+
253
+ ### Evaluate and compare versions
254
+
255
+ An evaluation suite is a Python file with test cases, scorers and the versions to compare.
256
+ The first version is the baseline. `None` means "the runs as they were recorded", so you can
257
+ compare a new prompt with what production actually did:
258
+
259
+ ```python
260
+ # evals/support_bot.py
261
+ from agent_doctor.evals import Suite, Variant, cases_from_runs, load_cases, scorers
262
+ from my_app.bot import handle, handle_v2
263
+
264
+ suite = Suite(
265
+ name="support-bot",
266
+ cases=load_cases("evals/support_bot.yaml"), # or cases_from_runs(saved runs)
267
+ scorers=[scorers.exact_match(), scorers.completed(), scorers.no_problems("high")],
268
+ variants={
269
+ "recorded": None,
270
+ "v2-prompt": handle_v2,
271
+ "mini": Variant(handle, model_map={"gpt-4o": "gpt-4o-mini"}),
272
+ },
273
+ )
274
+ ```
275
+
276
+ ```bash
277
+ agent-doctor eval evals/support_bot.py
278
+ ```
279
+
280
+ Each case is replayed against its recorded run when it has one (`source_run_id`), and run
281
+ live otherwise. Side-effect tools are blocked either way. Every new run also goes through the
282
+ twelve detectors, so the report shows pass rate, cost, latency and problems for each
283
+ version. The comparison pairs results case by case: which cases broke, which got fixed, and
284
+ an exact McNemar test that says whether the difference could be chance. **The command exits
285
+ with code 1 if any case that passed before fails now**, so it can gate a deploy in CI.
286
+
287
+ Every evaluation is saved (`--no-record` to skip): `agent-doctor evals` lists them and
288
+ `agent-doctor evals last` shows one again. Over MCP, ask Claude or Cursor *"did the last
289
+ eval break anything?"* and it reads the result, including both versions' answers for each
290
+ broken case.
291
+
292
+ Built-in scorers: `exact_match`, `contains`, `matches` (regex), `similarity` (word overlap),
293
+ `completed`, `no_problems`, `max_cost`, `max_latency`. Write your own with `@scorer`:
294
+
295
+ ```python
296
+ from agent_doctor.evals import scorer
297
+
298
+ @scorer
299
+ def mentions_order_id(case, attempt):
300
+ return case.kwargs["order_id"] in (attempt.output_text or "")
301
+ ```
302
+
303
+ Try it on the bad agent: `agent-doctor eval examples/bad_agent/eval_suite.py`. Fixing the
304
+ agent's own faults cuts cost by 61% and removes 24 of the 36 problems with no answer getting
305
+ worse. Sending large-model calls to the small model (`model_map`) cuts cost by 94%. The
306
+ replays keep the recorded environment, so the tracking API that was down is still down, and
307
+ those two answers stay wrong.
308
+
309
+ ## Testing your own agent
310
+
311
+ `agent_doctor.testing` gives you simulated time (`simulated_time()`, `sleep()`) and
312
+ repeatable IDs (`deterministic_ids()`), so recorded runs are identical on every machine.
313
+ The [bad agent](examples/bad_agent/README.md) uses them to build the fixtures.
314
+
315
+ ## Commands
316
+
317
+ | Command | What it does |
318
+ | --- | --- |
319
+ | `agent-doctor analyze RUN` | Problems in one run, with evidence, estimated waste and fixes |
320
+ | `agent-doctor scan` | Problems across many runs, most serious and costly first |
321
+ | `agent-doctor replay RUN --agent M:F` | Run your agent again on a saved run, tools answered from the recording |
322
+ | `agent-doctor eval SUITE.py` | Evaluate and compare agent versions; exits 1 if any case regressed |
323
+ | `agent-doctor evals [ID]` | List saved evaluation results, or show one again |
324
+ | `agent-doctor mcp` | Run the MCP server over stdio (needs the `mcp` extra) |
325
+ | `agent-doctor runs` | List recent runs with duration, calls, errors, tokens and cost |
326
+ | `agent-doctor show RUN` | Every step of a run as a tree, with retries, errors and cached tokens |
327
+ | `agent-doctor cost RUN` | Cost per LLM call and per model, cache savings, cost of 1,000 runs |
328
+ | `agent-doctor recommend [RUN]` | Ranked fix plan from the playbooks; `--llm` to have an LLM write it up |
329
+ | `agent-doctor playbooks [QUERY]` | List, search (`QUERY`) or read (`--show ID`) the fix playbooks |
330
+ | `agent-doctor import FILE` | Load runs: Agent Doctor JSON, OTLP JSON, Langfuse or LangSmith; `--redact` |
331
+ | `agent-doctor validate FILE` | Check a trace file against the schema |
332
+ | `agent-doctor pricing [-m MODEL]` | List prices, or show which price a model gets |
333
+
334
+ `RUN` is a run ID from `agent-doctor runs`, a unique prefix of it, or `last` for the most recent run. Add `--json` to `cost` or `analyze` for machine-readable output.
335
+
336
+ ## Pricing
337
+
338
+ Built-in prices (USD per 1M tokens) cover current Claude and OpenAI models, each with
339
+ its source and the date it was checked. Open models routed through Hugging Face
340
+ Inference Providers are billed at each provider's rate, which Hugging Face does not
341
+ publish as a table, so add the rate you pay to `~/.agent-doctor/pricing.yaml`:
342
+
343
+ ```yaml
344
+ models:
345
+ # example numbers: put in the rate your provider charges
346
+ - {match: "Qwen/Qwen2.5-7B-Instruct", provider: together, input: 0.30, output: 0.30}
347
+ ```
348
+
349
+ Your entries win over the built-ins; `*` is a wildcard. Models with no price are
350
+ reported as "unpriced" instead of being counted as free.
351
+
352
+ ## The trace schema
353
+
354
+ Every trace is normalized into three models in `src/agent_doctor/schema.py`:
355
+
356
+ | Model | What it is |
357
+ | --- | --- |
358
+ | `Span` | One step: an LLM call, tool call, retrieval or agent step, with timing, tokens, inputs and outputs |
359
+ | `Run` | One full agent execution for one input; holds its spans and validates that they fit together |
360
+ | `Finding` | One problem an analyzer found, with evidence span IDs and wasted cost or time |
361
+
362
+ Tool arguments are hashed (`args_hash`, key order ignored) so repeated tool calls
363
+ are easy to spot. Tools with `side_effects=True` are never called live during replay.
364
+
365
+ ## Roadmap
366
+
367
+ - [x] Phase 0: setup, schema, tests, CI
368
+ - [x] Phase 1: SDK (`instrument()`, `@trace_run`, `@trace_tool`), SQLite store, pricing, cost CLI
369
+ - [x] Phase 2: bad agent with 12 kinds of planted problems; 32 fixture runs with an answer key ([details](examples/bad_agent/README.md))
370
+ - [x] Phase 3: 12 deterministic detectors, `analyze` and `scan`; 36/36 planted problems found, 0 false alarms
371
+ - [x] Phase 4: MCP server with 7 read-only tools (`agent-doctor mcp`)
372
+ - [x] Phase 5: replay (recorded tools, blocked side effects, model swaps) and evaluation suite (scorers, paired statistics, CI exit code)
373
+ - [x] Phase 6: recommender (15 playbooks, deterministic retrieval, optional LLM write-up), OpenTelemetry / Langfuse / LangSmith importers, redaction, Hugging Face Space demo, release workflow
374
+ - [ ] Launch: publish to PyPI and the Space
375
+
376
+ ## License
377
+
378
+ MIT