diplomat-agent 0.2.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 (70) hide show
  1. diplomat_agent-0.2.0/.github/ISSUE_TEMPLATE/bug_report.md +21 -0
  2. diplomat_agent-0.2.0/.github/ISSUE_TEMPLATE/check_not_seen.md +25 -0
  3. diplomat_agent-0.2.0/.github/ISSUE_TEMPLATE/false_positive.md +25 -0
  4. diplomat_agent-0.2.0/.github/ISSUE_TEMPLATE/missing_detection.md +25 -0
  5. diplomat_agent-0.2.0/.github/PULL_REQUEST_TEMPLATE.md +11 -0
  6. diplomat_agent-0.2.0/.github/workflows/ci.yml +20 -0
  7. diplomat_agent-0.2.0/.gitignore +27 -0
  8. diplomat_agent-0.2.0/AGENTS.md +36 -0
  9. diplomat_agent-0.2.0/CHANGELOG.md +22 -0
  10. diplomat_agent-0.2.0/CONTRIBUTING.md +37 -0
  11. diplomat_agent-0.2.0/LICENSE +190 -0
  12. diplomat_agent-0.2.0/PKG-INFO +184 -0
  13. diplomat_agent-0.2.0/README.md +162 -0
  14. diplomat_agent-0.2.0/REALITY_CHECK_RESULTS.md +254 -0
  15. diplomat_agent-0.2.0/SECURITY.md +22 -0
  16. diplomat_agent-0.2.0/docs/ANALYSIS.md +96 -0
  17. diplomat_agent-0.2.0/docs/LAUNCH.md +133 -0
  18. diplomat_agent-0.2.0/docs/METHODOLOGY.md +43 -0
  19. diplomat_agent-0.2.0/docs/REPO_STRUCTURE.md +96 -0
  20. diplomat_agent-0.2.0/examples/demo_agent/__init__.py +0 -0
  21. diplomat_agent-0.2.0/examples/demo_agent/tools.py +53 -0
  22. diplomat_agent-0.2.0/examples/diplomat-agent.yml +171 -0
  23. diplomat_agent-0.2.0/examples/toolcalls.skyvern.yaml +46 -0
  24. diplomat_agent-0.2.0/pyproject.toml +46 -0
  25. diplomat_agent-0.2.0/src/diplomat_agent/__init__.py +3 -0
  26. diplomat_agent-0.2.0/src/diplomat_agent/__main__.py +7 -0
  27. diplomat_agent-0.2.0/src/diplomat_agent/analyzer/__init__.py +1 -0
  28. diplomat_agent-0.2.0/src/diplomat_agent/analyzer/checks.py +89 -0
  29. diplomat_agent-0.2.0/src/diplomat_agent/analyzer/guards.py +79 -0
  30. diplomat_agent-0.2.0/src/diplomat_agent/analyzer/scenarios.py +210 -0
  31. diplomat_agent-0.2.0/src/diplomat_agent/cli.py +260 -0
  32. diplomat_agent-0.2.0/src/diplomat_agent/models.py +63 -0
  33. diplomat_agent-0.2.0/src/diplomat_agent/reporter/__init__.py +1 -0
  34. diplomat_agent-0.2.0/src/diplomat_agent/reporter/json_report.py +34 -0
  35. diplomat_agent-0.2.0/src/diplomat_agent/reporter/markdown.py +134 -0
  36. diplomat_agent-0.2.0/src/diplomat_agent/reporter/registry.py +241 -0
  37. diplomat_agent-0.2.0/src/diplomat_agent/reporter/terminal.py +343 -0
  38. diplomat_agent-0.2.0/src/diplomat_agent/scanner/__init__.py +1 -0
  39. diplomat_agent-0.2.0/src/diplomat_agent/scanner/ast_scanner.py +690 -0
  40. diplomat_agent-0.2.0/src/diplomat_agent/scanner/patterns.py +703 -0
  41. diplomat_agent-0.2.0/src/diplomat_agent/scanner/yaml_scanner.py +200 -0
  42. diplomat_agent-0.2.0/tests/__init__.py +1 -0
  43. diplomat_agent-0.2.0/tests/fixtures/agent_calls.py +41 -0
  44. diplomat_agent-0.2.0/tests/fixtures/checked_ok_agent/tools.py +34 -0
  45. diplomat_agent-0.2.0/tests/fixtures/crewai_agent/__init__.py +1 -0
  46. diplomat_agent-0.2.0/tests/fixtures/crewai_agent/agent.py +51 -0
  47. diplomat_agent-0.2.0/tests/fixtures/crewai_agent/support_tools.py +62 -0
  48. diplomat_agent-0.2.0/tests/fixtures/dynamic_code.py +26 -0
  49. diplomat_agent-0.2.0/tests/fixtures/false_positives.py +28 -0
  50. diplomat_agent-0.2.0/tests/fixtures/false_positives_drop.py +19 -0
  51. diplomat_agent-0.2.0/tests/fixtures/false_positives_short_substring.py +25 -0
  52. diplomat_agent-0.2.0/tests/fixtures/fastapi_depends.py +56 -0
  53. diplomat_agent-0.2.0/tests/fixtures/langgraph_agent/__init__.py +1 -0
  54. diplomat_agent-0.2.0/tests/fixtures/langgraph_agent/tools.py +86 -0
  55. diplomat_agent-0.2.0/tests/fixtures/langgraph_agent/workflows.py +26 -0
  56. diplomat_agent-0.2.0/tests/fixtures/llm_calls.py +36 -0
  57. diplomat_agent-0.2.0/tests/fixtures/nested_test_dir/tests/utils/helpers.py +7 -0
  58. diplomat_agent-0.2.0/tests/fixtures/openai_agents_sdk.py +9 -0
  59. diplomat_agent-0.2.0/tests/fixtures/production_like/editor.py +12 -0
  60. diplomat_agent-0.2.0/tests/fixtures/production_like/tasks.py +19 -0
  61. diplomat_agent-0.2.0/tests/fixtures/raw_python_agent/__init__.py +1 -0
  62. diplomat_agent-0.2.0/tests/fixtures/raw_python_agent/agent_tools.py +121 -0
  63. diplomat_agent-0.2.0/tests/fixtures/raw_python_agent/services.py +60 -0
  64. diplomat_agent-0.2.0/tests/fixtures/real_world_patterns.py +85 -0
  65. diplomat_agent-0.2.0/tests/test_analyzer.py +283 -0
  66. diplomat_agent-0.2.0/tests/test_cli.py +108 -0
  67. diplomat_agent-0.2.0/tests/test_false_positives.py +1064 -0
  68. diplomat_agent-0.2.0/tests/test_registry.py +212 -0
  69. diplomat_agent-0.2.0/tests/test_reporter.py +213 -0
  70. diplomat_agent-0.2.0/tests/test_scanner.py +798 -0
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: Bug report
3
+ about: Something isn't working correctly
4
+ labels: bug
5
+ ---
6
+
7
+ ## Describe the bug
8
+
9
+ ## To reproduce
10
+
11
+ ```bash
12
+ diplomat-agent [command you ran]
13
+ ```
14
+
15
+ ## Expected behavior
16
+
17
+ ## Environment
18
+
19
+ * diplomat-agent version:
20
+ * Python version:
21
+ * OS:
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: Check not recognized
3
+ about: A protection exists but diplomat-agent doesn't see it
4
+ labels: check-not-seen
5
+ ---
6
+
7
+ ## Function flagged as "no checks" or "partial checks"
8
+
9
+ **Function name**:
10
+ **File**:
11
+ **Line**:
12
+
13
+ ## The check that exists
14
+
15
+ (describe where the protection is: in the same function, in a decorator, in function parameters, in a middleware, in an API gateway, etc.)
16
+
17
+ ## Code snippet
18
+
19
+ ```python
20
+ (paste the function code AND the check code, even if in different files)
21
+ ```
22
+
23
+ ## Notes
24
+
25
+ If the check is in a different file (middleware, gateway), the correct resolution is `# checked:ok — protected by [where]` in your source code. This issue template is for checks that ARE in the same function scope but diplomat-agent doesn't detect them.
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: False positive
3
+ about: A function flagged that shouldn't be
4
+ labels: false-positive
5
+ ---
6
+
7
+ ## Function flagged
8
+
9
+ **Function name**:
10
+ **File**:
11
+ **Line**:
12
+
13
+ ## What diplomat-agent detected
14
+
15
+ (paste the terminal output for this function)
16
+
17
+ ## Why it's a false positive
18
+
19
+ (explain why this function doesn't actually change the real world, or why the detected "effect" is not a real side effect)
20
+
21
+ ## Code snippet
22
+
23
+ ```python
24
+ (paste the function code)
25
+ ```
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: Missing detection
3
+ about: A tool call that should be detected but isn't
4
+ labels: missing-detection
5
+ ---
6
+
7
+ ## Function missed
8
+
9
+ **Function name**:
10
+ **File**:
11
+ **Line**:
12
+
13
+ ## What it does
14
+
15
+ (describe the real-world effect: DB write, payment, email, etc.)
16
+
17
+ ## Code snippet
18
+
19
+ ```python
20
+ (paste the function code)
21
+ ```
22
+
23
+ ## Expected detection
24
+
25
+ (what category should it be: database_write, payment, http_write, etc.)
@@ -0,0 +1,11 @@
1
+ ## What this PR does
2
+
3
+ ## Related issue
4
+
5
+ Fixes #
6
+
7
+ ## Checklist
8
+
9
+ - [ ] Tests added for new patterns/features
10
+ - [ ] All tests pass (`python -m pytest tests/`)
11
+ - [ ] No new external dependencies added to core
@@ -0,0 +1,20 @@
1
+ name: CI # diplomat-agent v0.2.0
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ branches: [main]
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - run: pip install -e ".[dev]"
20
+ - run: python -m pytest tests/ -v
@@ -0,0 +1,27 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .pytest_cache/
10
+ .mypy_cache/
11
+ .venv/
12
+ venv/
13
+ env/
14
+ .env
15
+ *.so
16
+ .coverage
17
+ htmlcov/
18
+
19
+ # Internal research data
20
+ data/
21
+ *report*.json
22
+
23
+ # Claude Code session
24
+ .claude/
25
+
26
+ # OS
27
+ .DS_Store
@@ -0,0 +1,36 @@
1
+ # AGENTS.md — for AI coding assistants (v0.2.0)
2
+
3
+ ## What this repo is
4
+
5
+ diplomat-agent is a static analysis tool that scans Python codebases for tool calls (functions that change the real world: payments, database writes, HTTP calls, emails) and checks whether safety checks exist around them.
6
+
7
+ ## Architecture
8
+
9
+ - `src/diplomat_agent/scanner/` — AST visitor that detects effects and checks
10
+ - `src/diplomat_agent/scanner/patterns.py` — catalogue of all known patterns (data, not logic)
11
+ - `src/diplomat_agent/analyzer/` — computes verdict (UNGUARDED / PARTIALLY_GUARDED / GUARDED / LOW_RISK) and missing check hints
12
+ - `src/diplomat_agent/reporter/` — terminal, markdown, JSON, YAML registry outputs
13
+ - `src/diplomat_agent/models.py` — dataclasses: SideEffect, Guard, Tool, Scenario, ScanResult
14
+ - `src/diplomat_agent/cli.py` — argparse CLI entry point
15
+
16
+ ## Key design decisions
17
+
18
+ - **AST, not regex.** We parse Python source with the stdlib `ast` module. Regex would miss nested calls and produce false positives on strings/comments.
19
+ - **stdlib only.** Zero required dependencies. `rich` is optional for terminal color, `pyyaml` for YAML output.
20
+ - **No inter-procedural analysis.** Each function is analyzed in isolation. This limits depth but keeps the scanner fast and predictable.
21
+ - **Effects and checks, not risk scores.** The scanner reports what it sees. It does not assign severity or suggest fixes.
22
+
23
+ ## Running tests
24
+
25
+ ```bash
26
+ PYTHONPATH=src python -m pytest tests/ -v
27
+ ```
28
+
29
+ 201 tests. All must pass before merge.
30
+
31
+ ## Conventions
32
+
33
+ - Python 3.10+
34
+ - `from __future__ import annotations` in all source files
35
+ - No external dependencies in core scanner
36
+ - Patterns are data in `patterns.py`, not logic scattered across the codebase
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 — 2026-03-25
4
+
5
+ Scanner improvements based on reality check audit across 16 real agent repos.
6
+
7
+ - Fix duplicate guard labels in terminal output (Rate limit, Confirmation step)
8
+ - Contextual hints: `no rate limit` / `no auth check` only shown for relevant effect categories
9
+ - New patterns: CrewAI `crew.kickoff()`, AutoGen `initiate_chat()`, LangGraph `app.invoke()`
10
+ - Extended excluded directories: evaluation, samples, playground, notebooks, tutorial
11
+ - New fixtures: publish (S3/GCS), destructive (subprocess/os.system), file_delete, MongoDB
12
+ - 264 tests (was 220), 0 regressions
13
+
14
+ ## 0.1.0 — 2026-03-23
15
+
16
+ Initial release.
17
+
18
+ - AST scanner detecting 11 effect categories and 7 check types in Python agents
19
+ - Terminal, Markdown, JSON, and YAML registry output formats
20
+ - `--fail-on-unchecked` CI gate (alias: `--fail-on-unguarded`) with baseline support
21
+ - `# checked:ok` inline annotation for acknowledged tool calls
22
+ - Benchmarked on Skyvern (382 findings), SurfSense (319), FinRobot (27)
@@ -0,0 +1,37 @@
1
+ # Contributing to diplomat-agent (v0.2.0)
2
+
3
+ ## Quick start
4
+
5
+ ```bash
6
+ git clone https://github.com/Diplomat-ai/diplomat-agent.git
7
+ cd diplomat-agent
8
+ pip install -e ".[dev]"
9
+ python -m pytest tests/
10
+ ```
11
+
12
+ ## How to contribute
13
+
14
+ ### Report a false positive
15
+
16
+ The most valuable contribution. Open an issue using the "False positive" template with the function code and the incorrect detection.
17
+
18
+ ### Report a missing tool call
19
+
20
+ If diplomat-agent misses a function that changes the real world, open an issue with the "Missing detection" template.
21
+
22
+ ### Add a pattern
23
+
24
+ Patterns are in `src/diplomat_agent/scanner/patterns.py`. Each pattern needs a test fixture in `tests/fixtures/` and a test in `tests/`.
25
+
26
+ ## Code style
27
+
28
+ * No external dependencies in core (stdlib only)
29
+ * `rich` and `pyyaml` are optional
30
+ * Run `python -m pytest tests/` before submitting
31
+
32
+ ## Pull request process
33
+
34
+ 1. Fork and create a branch from `main`
35
+ 2. Add tests for new patterns
36
+ 3. Ensure all tests pass
37
+ 4. Open a PR with a clear description
@@ -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 Diplomat Services SAS
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,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: diplomat-agent
3
+ Version: 0.2.0
4
+ Summary: Scan your agentic codebase for unguarded tool calls with real-world side effects
5
+ Project-URL: Homepage, https://diplomat.run
6
+ Project-URL: Repository, https://github.com/diplomat-ai/diplomat-agent
7
+ License: Apache-2.0
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.9
10
+ Provides-Extra: all
11
+ Requires-Dist: pyyaml>=6.0; extra == 'all'
12
+ Requires-Dist: rich>=13.0; extra == 'all'
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest>=8.0; extra == 'dev'
15
+ Requires-Dist: pyyaml>=6.0; extra == 'dev'
16
+ Requires-Dist: ruff>=0.4; extra == 'dev'
17
+ Provides-Extra: rich
18
+ Requires-Dist: rich>=13.0; extra == 'rich'
19
+ Provides-Extra: yaml
20
+ Requires-Dist: pyyaml>=6.0; extra == 'yaml'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # diplomat-agent
24
+
25
+ > v0.2.0 — 264 tests, 48+ detection patterns, 11 effect categories
26
+
27
+ Find every tool call in your AI agent that can change the real world.
28
+
29
+ `diplomat-agent` is a static scanner for Python AI agents. It maps every function that writes to a database, calls an external API, sends an email, invokes another agent, or deletes data — and tells you which ones have no checks.
30
+
31
+ ## What it finds
32
+
33
+ We scanned 16 open-source agent repos. Here's what we found:
34
+
35
+ | | Unguarded |
36
+ |---|---|
37
+ | Database writes | 3,260 |
38
+ | Database deletes | 1,305 |
39
+ | HTTP writes (POST/PUT/PATCH) | 968 |
40
+ | Subprocess / exec / eval | 697 |
41
+ | LLM calls | 464 |
42
+ | Emails | 250 |
43
+
44
+ **76% of tool calls had zero checks.**
45
+
46
+ One example: [Khoj](https://github.com/khoj-ai/khoj)'s `ai_update_memories` lets an LLM delete user memories with no human confirmation.
47
+
48
+ ## Quick start
49
+
50
+ ```bash
51
+ pip install diplomat-agent
52
+ diplomat-agent .
53
+ ```
54
+
55
+ Output:
56
+
57
+ ```
58
+ diplomat-agent — governance scan
59
+
60
+ Scanned: ./my-agent
61
+ Tool calls with side effects: 12
62
+
63
+ ⚠ research_and_save(query, db_path)
64
+ Write protection: NONE
65
+ Rate limit: NONE
66
+ → no rate limit · no auth check
67
+ Governance: ❌ UNGUARDED
68
+
69
+ ⚠ send_notification(user_id, message)
70
+ Write protection: NONE
71
+ → no confirmation before send
72
+ Governance: ❌ UNGUARDED
73
+
74
+ ✓ process_order(order_id) — # checked:ok — protected by API gateway
75
+ Governance: ✅ CONFIRMED
76
+
77
+ ────────────────────────────────────────────
78
+ RESULT: 8 with no checks · 3 partial · 1 confirmed (12 total)
79
+
80
+ Fix → add validation in code, the next scan picks it up
81
+ Acknowledge → add # checked:ok in your source code
82
+ Protected elsewhere → add # checked:ok — protected by [where]
83
+ CI enforcement → --fail-on-unchecked blocks PRs with new unreviewed tool calls
84
+ ```
85
+
86
+ ## What counts as a tool call
87
+
88
+ Any function that can change state outside the process:
89
+
90
+ - **Database writes** — `session.commit()`, `.save()`, `.create()`, `.update()`
91
+ - **Database deletes** — `session.delete()`, `.remove()`, `DELETE FROM`
92
+ - **HTTP writes** — `requests.post()`, `httpx.put()`, `client.patch()`
93
+ - **LLM calls** — `openai.chat.completions.create()`, `anthropic.messages.create()`
94
+ - **Agent invocations** — `graph.ainvoke()`, `agent.execute()`, `Runner.run_sync()`
95
+ - **Email** — `smtp.sendmail()`, `ses_client.send_email()`
96
+ - **Destructive** — `subprocess.run()`, `exec()`, `eval()`
97
+ - **Publish** — `s3.put_object()`, `client.publish()`
98
+
99
+ ## What counts as a check
100
+
101
+ - **Input validation** — `Field(le=10000)`, `@validator`, `if ... raise`
102
+ - **Rate limit** — `@rate_limit`, `@throttle`
103
+ - **Auth** — `Depends()`, `Security()` (FastAPI)
104
+ - **Confirmation** — `confirm`, `approve`, `review` in function body
105
+ - **Idempotency** — `idempotency_key`, `get_or_create`, `ON CONFLICT`
106
+ - **Retry bound** — `max_retries=`, `@retry(stop=stop_after_attempt())`
107
+
108
+ ## CI integration
109
+
110
+ Add to your CI pipeline:
111
+
112
+ ```yaml
113
+ - name: Diplomat governance scan
114
+ run: |
115
+ pip install diplomat-agent
116
+ diplomat-agent . --fail-on-unchecked
117
+ ```
118
+
119
+ `--fail-on-unchecked` blocks the PR if there are new unreviewed tool calls.
120
+
121
+ If `toolcalls.yaml` exists in the repo, it's used as baseline: only new findings block the build.
122
+
123
+ ### Generate the registry
124
+
125
+ ```bash
126
+ diplomat-agent . --format registry --output-registry toolcalls.yaml
127
+ ```
128
+
129
+ Commit `toolcalls.yaml` to your repo. Review changes in PRs. The file is a mirror of what your agent can do — it updates on every scan.
130
+
131
+ ## Acknowledge a tool call
132
+
133
+ If a tool call is intentionally unguarded or protected elsewhere:
134
+
135
+ ```python
136
+ def send_alert(message): # checked:ok — protected by API gateway
137
+ requests.post(ALERT_URL, json={"msg": message})
138
+ ```
139
+
140
+ `# diplomat:ok`, `# checked:ok`, and `# canary:ok` all work.
141
+
142
+ ## Frameworks tested
143
+
144
+ | Framework | Coverage |
145
+ |---|---|
146
+ | LangGraph | `graph.ainvoke()`, StateGraph patterns |
147
+ | CrewAI | `agent.execute()`, tool patterns |
148
+ | OpenAI SDK | `client.chat.completions.create()` |
149
+ | OpenAI Agents SDK | `Runner.run_sync()` |
150
+ | LangChain | `chain.invoke()`, AgentExecutor |
151
+ | Direct API calls | OpenAI, Anthropic, any HTTP client |
152
+
153
+ ## Requirements
154
+
155
+ - Python 3.10+
156
+ - Zero dependencies (stdlib `ast` module only)
157
+ - Optional: `rich` for colored terminal output, `pyyaml` for registry
158
+
159
+ ## Benchmarks
160
+
161
+ | Repo | Tool calls | Unguarded | Time |
162
+ |---|---|---|---|
163
+ | Skyvern (595 files) | 452 | 345 (76%) | ~2s |
164
+ | Dify (1000+ files) | 1,009 | 759 (75%) | ~3s |
165
+ | PraisonAI | 1,028 | 911 (89%) | ~2s |
166
+ | CrewAI | 348 | 273 (78%) | ~1s |
167
+
168
+ ## Known limitations
169
+
170
+ - Static analysis only — cannot detect runtime-generated tool calls
171
+ - `name_contains` patterns (e.g. "refund", "charge") may match internal business methods that aren't actual payment operations (~22% FP rate on payment patterns)
172
+ - No inter-procedural analysis (doesn't follow calls across files)
173
+ - No import alias resolution
174
+
175
+ ## Roadmap
176
+
177
+ - [ ] TypeScript support
178
+ - [ ] MCP server scanning
179
+ - [ ] PR comment integration
180
+ - [ ] Runtime enforcement (Diplomat runtime)
181
+
182
+ ## License
183
+
184
+ Apache 2.0 — Copyright 2026 Diplomat Services SAS