dapplepot-sdk 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.
- dapplepot_sdk-0.1.0/LICENSE +201 -0
- dapplepot_sdk-0.1.0/NOTICE +4 -0
- dapplepot_sdk-0.1.0/PKG-INFO +308 -0
- dapplepot_sdk-0.1.0/README.md +271 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/__init__.py +243 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/_adapter.py +168 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/_buffer.py +115 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/_interceptor.py +306 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/_langchain.py +254 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/_node_context.py +43 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/anthropic.py +209 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/openai.py +173 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/scrubbers.py +45 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk/session.py +65 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk.egg-info/PKG-INFO +308 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk.egg-info/SOURCES.txt +19 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk.egg-info/dependency_links.txt +1 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk.egg-info/requires.txt +21 -0
- dapplepot_sdk-0.1.0/dapplepot_sdk.egg-info/top_level.txt +1 -0
- dapplepot_sdk-0.1.0/pyproject.toml +53 -0
- dapplepot_sdk-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
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 accept and charge a
|
|
167
|
+
fee for acceptance of support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However, in
|
|
169
|
+
accepting such obligations, You may act only on Your own behalf and on
|
|
170
|
+
Your sole responsibility, not on behalf of any other Contributor, and
|
|
171
|
+
only if You agree to indemnify, defend, and hold each Contributor
|
|
172
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
173
|
+
such Contributor by reason of your accepting any such warranty or
|
|
174
|
+
additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 DapplePot
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dapplepot-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DapplePot Python SDK for AI agent security observability — instruments LangChain/LangGraph, OpenAI, and Anthropic
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://dapplepot.com
|
|
7
|
+
Keywords: llm,security,observability,ai-agents,langchain,openai,anthropic,langgraph
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
License-File: NOTICE
|
|
19
|
+
Requires-Dist: requests>=2.31.0
|
|
20
|
+
Provides-Extra: langchain
|
|
21
|
+
Requires-Dist: langchain>=0.2.0; extra == "langchain"
|
|
22
|
+
Requires-Dist: langchain-core>=0.2.0; extra == "langchain"
|
|
23
|
+
Requires-Dist: langchain-openai>=0.1.0; extra == "langchain"
|
|
24
|
+
Requires-Dist: langgraph>=0.1.0; extra == "langchain"
|
|
25
|
+
Provides-Extra: openai
|
|
26
|
+
Requires-Dist: openai>=1.30.0; extra == "openai"
|
|
27
|
+
Provides-Extra: anthropic
|
|
28
|
+
Requires-Dist: anthropic>=0.28.0; extra == "anthropic"
|
|
29
|
+
Provides-Extra: all
|
|
30
|
+
Requires-Dist: langchain>=0.2.0; extra == "all"
|
|
31
|
+
Requires-Dist: langchain-core>=0.2.0; extra == "all"
|
|
32
|
+
Requires-Dist: langchain-openai>=0.1.0; extra == "all"
|
|
33
|
+
Requires-Dist: langgraph>=0.1.0; extra == "all"
|
|
34
|
+
Requires-Dist: openai>=1.30.0; extra == "all"
|
|
35
|
+
Requires-Dist: anthropic>=0.28.0; extra == "all"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# DapplePot Python SDK
|
|
39
|
+
|
|
40
|
+
Python SDK for instrumenting LLM agents with DapplePot security observability. Drop-in integrations for **LangChain/LangGraph**, **OpenAI**, and **Anthropic** — sends structured events to the DapplePot ingest API and runs real-time threat detection in the hot path.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
Ensure you have Python 3.10+ installed, then:
|
|
44
|
+
```bash
|
|
45
|
+
pip install dapplepot-sdk
|
|
46
|
+
|
|
47
|
+
# Framework-specific extras:
|
|
48
|
+
pip install "dapplepot-sdk[langchain]" # LangChain / LangGraph
|
|
49
|
+
pip install "dapplepot-sdk[openai]" # OpenAI
|
|
50
|
+
pip install "dapplepot-sdk[anthropic]" # Anthropic
|
|
51
|
+
pip install "dapplepot-sdk[all]" # Everything
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
Get your `sdk_key`, `tenant_id`, `agent_id`, and `ingest_url` from the DapplePot dashboard.
|
|
57
|
+
|
|
58
|
+
### Anthropic
|
|
59
|
+
|
|
60
|
+
The standard `anthropic` package is patched in-place — upgrade it freely without coordinating with DapplePot releases.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import anthropic
|
|
64
|
+
from dapplepot_sdk import DapplePot
|
|
65
|
+
|
|
66
|
+
dp = DapplePot(
|
|
67
|
+
sdk_key = "dp_sk_...",
|
|
68
|
+
tenant_id = "your-tenant-id",
|
|
69
|
+
agent_id = "your-agent-id",
|
|
70
|
+
ingest_url = "https://ingest.dapplepot.com",
|
|
71
|
+
)
|
|
72
|
+
dp.instrument_anthropic()
|
|
73
|
+
|
|
74
|
+
client = anthropic.Anthropic(api_key="...")
|
|
75
|
+
|
|
76
|
+
with dp.session(user_context_id="user_123", user_tenant_id="acme_corp"):
|
|
77
|
+
response = client.messages.create(
|
|
78
|
+
model="claude-opus-4-7",
|
|
79
|
+
max_tokens=1024,
|
|
80
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
81
|
+
)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
All LLM, tool, and session events are captured automatically. See [Tool Tracking](#tool-tracking) for how multi-turn tool-use loops are traced with zero extra code.
|
|
85
|
+
|
|
86
|
+
### OpenAI
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import openai
|
|
90
|
+
from dapplepot_sdk import DapplePot
|
|
91
|
+
|
|
92
|
+
dp = DapplePot(
|
|
93
|
+
sdk_key = "dp_sk_...",
|
|
94
|
+
tenant_id = "...",
|
|
95
|
+
agent_id = "...",
|
|
96
|
+
ingest_url = "https://ingest.dapplepot.com",
|
|
97
|
+
)
|
|
98
|
+
dp.instrument_openai()
|
|
99
|
+
|
|
100
|
+
with dp.session(user_context_id="user_123"):
|
|
101
|
+
response = openai.chat.completions.create(
|
|
102
|
+
model="gpt-4o",
|
|
103
|
+
messages=[{"role": "user", "content": "Hello!"}],
|
|
104
|
+
)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### LangChain / LangGraph
|
|
108
|
+
|
|
109
|
+
LangChain fires its own callbacks during chain or graph execution — pass `dp.callback_handler()` and DapplePot listens.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from dapplepot_sdk import DapplePot
|
|
113
|
+
|
|
114
|
+
dp = DapplePot(
|
|
115
|
+
sdk_key = "dp_sk_...",
|
|
116
|
+
tenant_id = "...",
|
|
117
|
+
agent_id = "...",
|
|
118
|
+
ingest_url = "https://ingest.dapplepot.com",
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
handler = dp.callback_handler(
|
|
122
|
+
user_context_id="user_123",
|
|
123
|
+
user_tenant_id="acme_corp",
|
|
124
|
+
)
|
|
125
|
+
result = graph.invoke(
|
|
126
|
+
{"messages": [...]},
|
|
127
|
+
config={"callbacks": [handler]},
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
For LangGraph: each named graph node automatically becomes a `node_start` / `node_end` event. Tool calls handled via `ToolNode` emit `tool_start` / `tool_end` automatically.
|
|
132
|
+
|
|
133
|
+
## Core API
|
|
134
|
+
|
|
135
|
+
### `dp.session(*, user_context_id=None, user_tenant_id=None)`
|
|
136
|
+
|
|
137
|
+
Context manager that opens a DapplePot session for a multi-call conversation. The session ID is generated automatically.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
with dp.session(user_context_id="u_42", user_tenant_id="acme") as sess:
|
|
141
|
+
# All LLM calls inside this block belong to the same session
|
|
142
|
+
response = client.messages.create(...)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
| Parameter | Description |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `user_context_id` | Identifies the end-user within the session (optional) |
|
|
148
|
+
| `user_tenant_id` | For multi-tenant agents, identifies the customer tenant (optional) |
|
|
149
|
+
|
|
150
|
+
Outside `dp.session()`, every patched LLM call becomes its own one-event session.
|
|
151
|
+
|
|
152
|
+
### `dp.node(name, *, input=None)`
|
|
153
|
+
|
|
154
|
+
Optional context manager that adds named structure to your agent code. Emits `node_start` on entry, `node_end` on success, or `node_error` if an exception escapes.
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
with dp.session():
|
|
158
|
+
with dp.node("retrieve_context", input=query):
|
|
159
|
+
docs = vector_store.search(query)
|
|
160
|
+
|
|
161
|
+
with dp.node("generate_response"):
|
|
162
|
+
response = client.messages.create(...)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Use this when you want named steps in the trace UI — it is entirely optional. LangChain and LangGraph emit node events automatically from their own callbacks.
|
|
166
|
+
|
|
167
|
+
### `dp.callback_handler(*, user_context_id=None, user_tenant_id=None)`
|
|
168
|
+
|
|
169
|
+
Returns a fresh `DapplePotCallbackHandler` for one invocation of a LangChain chain or LangGraph run.
|
|
170
|
+
|
|
171
|
+
## Tool Tracking
|
|
172
|
+
|
|
173
|
+
For the Anthropic and OpenAI integrations, tool calls are detected automatically — no client-side instrumentation is required.
|
|
174
|
+
|
|
175
|
+
**Anthropic**: when the model returns `tool_use` content blocks, `tool_start` is emitted. When the next `messages.create()` call carries matching `tool_result` blocks, `tool_end` is emitted with the real tool output and latency. Set `is_error=True` on the `tool_result` block to emit `tool_error` instead.
|
|
176
|
+
|
|
177
|
+
**OpenAI**: when the model returns `tool_calls`, `tool_start` is emitted. When the next `chat.completions.create()` carries the corresponding `role="tool"` message, `tool_end` is emitted. Add `is_error=True` to the tool message to emit `tool_error` instead (a DapplePot convention — OpenAI ignores extra fields).
|
|
178
|
+
|
|
179
|
+
**LangChain / LangGraph**: tool callbacks are wired automatically by the framework's own `BaseTool` and `ToolNode`.
|
|
180
|
+
|
|
181
|
+
## Constructor
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
DapplePot(
|
|
185
|
+
sdk_key, # required — your SDK key from the DapplePot dashboard
|
|
186
|
+
tenant_id, # required — your tenant ID
|
|
187
|
+
agent_id, # required — the agent being instrumented
|
|
188
|
+
ingest_url, # required — your DapplePot ingest endpoint
|
|
189
|
+
*,
|
|
190
|
+
sample_rate = 1.0, # 0.0–1.0; fraction of sessions traced
|
|
191
|
+
pii_scrubber = None, # custom scrubber object (must implement .scrub_value())
|
|
192
|
+
redact_keys = None, # list[str] of payload keys to replace with [REDACTED]
|
|
193
|
+
flush_interval_ms = 500, # background flush cadence
|
|
194
|
+
flush_batch_size = 100, # max events per flush batch
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
All events are posted to `{ingest_url}/v1/ingest/events` with `Authorization: Bearer {sdk_key}`.
|
|
199
|
+
|
|
200
|
+
Call `dp.shutdown()` on exit to flush buffered events.
|
|
201
|
+
|
|
202
|
+
## Online Security Checks
|
|
203
|
+
|
|
204
|
+
The SDK runs **12 sub-checks** synchronously on every event. When a check fires it emits a finding immediately (without waiting for session end). Which checks are active and what action they take is configured per-agent in the DapplePot dashboard and fetched automatically at SDK startup.
|
|
205
|
+
|
|
206
|
+
| Sub-check | Category | Phase | Severity |
|
|
207
|
+
|-----------|----------|-------|----------|
|
|
208
|
+
| `PI-01a` | prompt_injection | input | high |
|
|
209
|
+
| `PI-01b` | prompt_injection | input | critical |
|
|
210
|
+
| `PI-01c` | prompt_injection | input | high |
|
|
211
|
+
| `PI-02a` | prompt_injection | tool_end | high |
|
|
212
|
+
| `PI-05a` | prompt_injection | input | high |
|
|
213
|
+
| `PI-08a` | prompt_injection | llm_start | high |
|
|
214
|
+
| `SID-01a` | data_disclosure | output | critical |
|
|
215
|
+
| `SID-01c` | data_disclosure | output | critical |
|
|
216
|
+
| `SID-02a` | data_disclosure | output | high |
|
|
217
|
+
| `IOH-01a` | output_handling | output | critical |
|
|
218
|
+
| `EA-01a` | excessive_agency | tool_start | high |
|
|
219
|
+
| `EA-02b` | excessive_agency | tool_start | high |
|
|
220
|
+
|
|
221
|
+
Check configuration and the tool manifest are fetched from the DapplePot API at startup. Update checks in the dashboard and restart your agent — no code changes needed.
|
|
222
|
+
|
|
223
|
+
### Actions
|
|
224
|
+
|
|
225
|
+
When a check fires, it takes one of four actions (configured per sub-check in the dashboard):
|
|
226
|
+
|
|
227
|
+
| Action | Effect |
|
|
228
|
+
|--------|--------|
|
|
229
|
+
| `alert` | Logs a warning; execution continues |
|
|
230
|
+
| `sanitize` | Redacts matched content from the event payload; execution continues |
|
|
231
|
+
| `block_call` | Raises `DapplePotBlockedError` |
|
|
232
|
+
| `terminate_session` | Raises `DapplePotSessionTerminatedError` |
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from dapplepot_sdk import DapplePot, DapplePotBlockedError, DapplePotSessionTerminatedError
|
|
236
|
+
|
|
237
|
+
try:
|
|
238
|
+
result = graph.invoke(...)
|
|
239
|
+
except DapplePotBlockedError as e:
|
|
240
|
+
print(e.signal, e.reason, e.session_id)
|
|
241
|
+
except DapplePotSessionTerminatedError:
|
|
242
|
+
print("Session terminated by security policy")
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## PII Scrubbing
|
|
246
|
+
|
|
247
|
+
Use the built-in `RegexScrubber` or implement your own:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from dapplepot_sdk import DapplePot
|
|
251
|
+
from dapplepot_sdk.scrubbers import RegexScrubber
|
|
252
|
+
|
|
253
|
+
scrubber = RegexScrubber(patterns=["email", "ssn", "aws_key", "jwt", "phone"])
|
|
254
|
+
|
|
255
|
+
dp = DapplePot(
|
|
256
|
+
sdk_key = "dp_sk_...",
|
|
257
|
+
tenant_id = "...",
|
|
258
|
+
agent_id = "...",
|
|
259
|
+
ingest_url = "https://ingest.dapplepot.com",
|
|
260
|
+
pii_scrubber = scrubber,
|
|
261
|
+
)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Built-in pattern names: `email`, `phone`, `ssn`, `credit_card`, `uk_nino`, `iban`, `ip_address`, `aws_key`, `jwt`.
|
|
265
|
+
|
|
266
|
+
To implement a custom scrubber, subclass `BaseScrubber` and implement `scrub(text: str) -> str`:
|
|
267
|
+
|
|
268
|
+
```python
|
|
269
|
+
from dapplepot_sdk.scrubbers import BaseScrubber
|
|
270
|
+
|
|
271
|
+
class MyScrubber(BaseScrubber):
|
|
272
|
+
def scrub(self, text: str) -> str:
|
|
273
|
+
return text.replace("sensitive", "[REDACTED]")
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
You can also redact known keys without touching values:
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
dp = DapplePot(..., redact_keys=["api_key", "password", "ssn"])
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
**Impact on detection:** Scrubbing runs after real-time online checks, so live session checks marked for online detection (e.g. `SID-02a`) still operate on the original content and fire correctly. However, events stored for post-session analysis contain the scrubbed values — PII is replaced with tokens like `[EMAIL]` or `[SANITIZED]` before storage, so any offline detection pass on those events will find nothing to flag.
|
|
283
|
+
|
|
284
|
+
## Event Reference
|
|
285
|
+
|
|
286
|
+
All events flow through `POST {ingest_url}/v1/ingest/events`.
|
|
287
|
+
|
|
288
|
+
| Event | When |
|
|
289
|
+
|---|---|
|
|
290
|
+
| `session_start` | `dp.session()` enter, or first patched call in standalone mode |
|
|
291
|
+
| `session_end` | `dp.session()` exit (normal close), or last patched call in standalone mode |
|
|
292
|
+
| `session_error` | Exception escapes `dp.session()` uncaught |
|
|
293
|
+
| `node_start` | `dp.node()` enter, or LangGraph/LangChain child chain start |
|
|
294
|
+
| `node_end` | `dp.node()` clean exit, or LangGraph/LangChain child chain end |
|
|
295
|
+
| `node_error` | `dp.node()` raises, or LangGraph/LangChain child chain fails |
|
|
296
|
+
| `llm_start` | Patched LLM call begins |
|
|
297
|
+
| `llm_end` | Patched LLM call returns (tokens, latency, model, finish reason) |
|
|
298
|
+
| `llm_error` | Patched LLM call raises |
|
|
299
|
+
| `tool_start` | Tool invoked by the model (auto-detected from response) |
|
|
300
|
+
| `tool_end` | Tool result fed back into the model (auto-detected from next call) |
|
|
301
|
+
| `tool_error` | Tool result marked `is_error=True`, or framework tool callback fails |
|
|
302
|
+
| `security_finding` | Online security check fired (out-of-band) |
|
|
303
|
+
|
|
304
|
+
Errors propagate upward only as far as the exception actually travels. Catch an exception inside `dp.node()` and the session keeps going. Catch it inside `dp.session()` and you only see `node_error` and `llm_error`, never `session_error`.
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
Licensed under the **Apache License, Version 2.0**. See [LICENSE](LICENSE) and [NOTICE](NOTICE) for details.
|