agentkeeper-runtime-sdk 0.1.0b1__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.
- agentkeeper_runtime_sdk-0.1.0b1/.gitignore +35 -0
- agentkeeper_runtime_sdk-0.1.0b1/PKG-INFO +289 -0
- agentkeeper_runtime_sdk-0.1.0b1/README.md +272 -0
- agentkeeper_runtime_sdk-0.1.0b1/pyproject.toml +30 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/__init__.py +45 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/anthropic.py +441 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/azure_openai.py +314 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/bedrock.py +187 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/claude_managed_agents.py +387 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/client.py +359 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/langchain.py +410 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/openai_agents.py +296 -0
- agentkeeper_runtime_sdk-0.1.0b1/src/agentkeeper_runtime_sdk/py.typed +1 -0
- agentkeeper_runtime_sdk-0.1.0b1/tests/test_runtime_sdk.py +583 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.claude/*
|
|
2
|
+
!.claude/skills/
|
|
3
|
+
!.claude/skills/**
|
|
4
|
+
.DS_Store
|
|
5
|
+
node_modules/
|
|
6
|
+
dist/
|
|
7
|
+
!packages/runtime-sdk/dist/
|
|
8
|
+
!packages/runtime-sdk/dist/index.js
|
|
9
|
+
!packages/runtime-sdk/dist/index.d.ts
|
|
10
|
+
__pycache__/
|
|
11
|
+
*.py[cod]
|
|
12
|
+
*.egg-info/
|
|
13
|
+
build/
|
|
14
|
+
|
|
15
|
+
# Desktop app
|
|
16
|
+
desktop/node_modules/
|
|
17
|
+
desktop/dist/
|
|
18
|
+
desktop/src-tauri/target/
|
|
19
|
+
.vercel
|
|
20
|
+
.env*
|
|
21
|
+
.env*.local
|
|
22
|
+
.secrets/
|
|
23
|
+
deploy/secrets/**/plaintext/
|
|
24
|
+
web/supabase/.temp/
|
|
25
|
+
supabase/.temp/
|
|
26
|
+
*.pem
|
|
27
|
+
|
|
28
|
+
# Local development worktrees
|
|
29
|
+
.worktrees/
|
|
30
|
+
|
|
31
|
+
# Browser extension local/generated artifacts
|
|
32
|
+
extension/.output/
|
|
33
|
+
extension/.wxt/
|
|
34
|
+
temp/*
|
|
35
|
+
.vibemaker.json
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentkeeper-runtime-sdk
|
|
3
|
+
Version: 0.1.0b1
|
|
4
|
+
Summary: AgentKeeper AI Agents SDK Beta for app-embedded Python agents.
|
|
5
|
+
Project-URL: Homepage, https://app.agentkeeper.dev
|
|
6
|
+
Project-URL: Repository, https://github.com/rad-security/agentkeeper-web
|
|
7
|
+
Author: AgentKeeper
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Keywords: agentkeeper,ai-agent,monitoring,runtime,security
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# AgentKeeper AI Agents SDK Beta for Python
|
|
19
|
+
|
|
20
|
+
Beta Python package for sending promptless AI agent runtime events to AgentKeeper.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install agentkeeper-runtime-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The Python package supports custom agents, LangChain, LangGraph, AWS Bedrock Runtime through boto3-style clients, OpenAI Agents SDK, Azure OpenAI, Claude Managed Agents, and Anthropic SDK message/tool surfaces. Vercel AI SDK remains TypeScript-only.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import os
|
|
32
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
33
|
+
|
|
34
|
+
ak = create_agentkeeper_runtime_client(
|
|
35
|
+
endpoint="https://app.agentkeeper.dev",
|
|
36
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
37
|
+
runtime_service="support-agent",
|
|
38
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
39
|
+
runtime_integration="custom",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
ak.track({
|
|
43
|
+
"event_kind": "runtime_heartbeat",
|
|
44
|
+
"capability": "observe",
|
|
45
|
+
"evidence_summary": "AI agent runtime connected",
|
|
46
|
+
})
|
|
47
|
+
ak.flush()
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Guarded Tools
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
def lookup_customer(args):
|
|
54
|
+
return {"customer_id": args["customer_id"], "tier": "enterprise"}
|
|
55
|
+
|
|
56
|
+
guarded_lookup = ak.wrap_tool(
|
|
57
|
+
"lookup_customer",
|
|
58
|
+
lookup_customer,
|
|
59
|
+
evaluate=lambda args: {"verdict": "passed", "reason": "allowed"},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
guarded_lookup({"customer_id": "cus_123"})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## OpenAI Agents SDK
|
|
66
|
+
|
|
67
|
+
Wrap Python functions before passing them to `function_tool` so the OpenAI Agents SDK can still infer the function signature.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import asyncio
|
|
71
|
+
import os
|
|
72
|
+
from agents import Agent, Runner, function_tool
|
|
73
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
74
|
+
from agentkeeper_runtime_sdk.openai_agents import (
|
|
75
|
+
wrap_openai_agents_run,
|
|
76
|
+
wrap_openai_agents_tool,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
ak = create_agentkeeper_runtime_client(
|
|
80
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
81
|
+
runtime_service="support-agent",
|
|
82
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
83
|
+
runtime_integration="openai_agents",
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
def lookup_customer(customer_id: str) -> dict:
|
|
87
|
+
return {"customer_id": customer_id, "tier": "enterprise"}
|
|
88
|
+
|
|
89
|
+
guarded_lookup_customer = function_tool(
|
|
90
|
+
wrap_openai_agents_tool(
|
|
91
|
+
lookup_customer,
|
|
92
|
+
ak,
|
|
93
|
+
tool_name="lookup_customer",
|
|
94
|
+
evaluate=lambda args: {"verdict": "passed"},
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
async def main():
|
|
99
|
+
guarded_run = wrap_openai_agents_run(Runner.run, ak)
|
|
100
|
+
agent = Agent(name="Support triage", tools=[guarded_lookup_customer])
|
|
101
|
+
await guarded_run(agent, "Check customer risk without exposing raw payloads.")
|
|
102
|
+
ak.flush()
|
|
103
|
+
|
|
104
|
+
asyncio.run(main())
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Anthropic SDK
|
|
108
|
+
|
|
109
|
+
Anthropic message calls are model-only observation. Wrap local tool handlers or runnable `run(input)` functions for blocking.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import os
|
|
113
|
+
from anthropic import Anthropic
|
|
114
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
115
|
+
from agentkeeper_runtime_sdk.anthropic import (
|
|
116
|
+
wrap_anthropic_client,
|
|
117
|
+
wrap_anthropic_tool,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
ak = create_agentkeeper_runtime_client(
|
|
121
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
122
|
+
runtime_service="support-agent",
|
|
123
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
124
|
+
runtime_integration="anthropic_sdk",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
anthropic = wrap_anthropic_client(Anthropic(), ak)
|
|
128
|
+
lookup_customer = wrap_anthropic_tool(
|
|
129
|
+
"lookup_customer",
|
|
130
|
+
lambda args: {"customer_id": args["customer_id"], "tier": "enterprise"},
|
|
131
|
+
ak,
|
|
132
|
+
evaluate=lambda args: {"verdict": "passed"},
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
message = anthropic.messages.create(
|
|
136
|
+
model=os.environ.get("ANTHROPIC_MODEL", "claude-sonnet-4-6"),
|
|
137
|
+
max_tokens=1024,
|
|
138
|
+
tools=[{
|
|
139
|
+
"name": "lookup_customer",
|
|
140
|
+
"description": "Look up a customer before support actions.",
|
|
141
|
+
"input_schema": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"properties": {"customer_id": {"type": "string"}},
|
|
144
|
+
"required": ["customer_id"],
|
|
145
|
+
},
|
|
146
|
+
}],
|
|
147
|
+
messages=[{"role": "user", "content": "Check customer risk."}],
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
for block in getattr(message, "content", []):
|
|
151
|
+
if getattr(block, "type", None) == "tool_use" and getattr(block, "name", None) == "lookup_customer":
|
|
152
|
+
lookup_customer(getattr(block, "input", {}))
|
|
153
|
+
|
|
154
|
+
ak.flush()
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Azure OpenAI
|
|
158
|
+
|
|
159
|
+
Azure OpenAI is model-only observation. The wrapper records safe metadata for `chat.completions.create()`, `responses.create()`, and `embeddings.create()` without storing prompts, messages, inputs, outputs, or provider request/response bodies.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import os
|
|
163
|
+
from openai import AzureOpenAI
|
|
164
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
165
|
+
from agentkeeper_runtime_sdk.azure_openai import wrap_azure_openai_client
|
|
166
|
+
|
|
167
|
+
ak = create_agentkeeper_runtime_client(
|
|
168
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
169
|
+
runtime_service="support-agent",
|
|
170
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
171
|
+
runtime_integration="azure_openai",
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT", "gpt-4o-mini")
|
|
175
|
+
azure_openai = wrap_azure_openai_client(
|
|
176
|
+
AzureOpenAI(
|
|
177
|
+
api_key=os.environ["AZURE_OPENAI_API_KEY"],
|
|
178
|
+
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
179
|
+
api_version=os.environ.get("AZURE_OPENAI_API_VERSION", "2024-10-21"),
|
|
180
|
+
),
|
|
181
|
+
ak,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
azure_openai.chat.completions.create(
|
|
185
|
+
model=deployment,
|
|
186
|
+
messages=[{"role": "user", "content": "Check customer risk."}],
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
ak.flush()
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Claude Managed Agents
|
|
193
|
+
|
|
194
|
+
Claude Managed Agents are hosted-session observation. The wrapper records safe agent, environment, session, event, stream, token, tool-name, and stop-reason metadata around Anthropic `client.beta.*` calls. It does not claim local pre-tool blocking for Anthropic-hosted sandbox/tool execution.
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
import os
|
|
198
|
+
from anthropic import Anthropic
|
|
199
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
200
|
+
from agentkeeper_runtime_sdk.claude_managed_agents import wrap_claude_managed_agents_client
|
|
201
|
+
|
|
202
|
+
ak = create_agentkeeper_runtime_client(
|
|
203
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
204
|
+
runtime_service="support-agent",
|
|
205
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
206
|
+
runtime_integration="claude_managed_agents",
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
client = wrap_claude_managed_agents_client(Anthropic(), ak)
|
|
210
|
+
agent = client.beta.agents.create(
|
|
211
|
+
name="Support triage",
|
|
212
|
+
model=os.environ.get("ANTHROPIC_MANAGED_AGENT_MODEL", "claude-sonnet-4-6"),
|
|
213
|
+
system="Help support engineers without exposing raw payloads.",
|
|
214
|
+
tools=[{"type": "agent_toolset_20260401"}],
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
session = client.beta.sessions.create(
|
|
218
|
+
agent=agent.id,
|
|
219
|
+
environment_id=os.environ["ANTHROPIC_ENVIRONMENT_ID"],
|
|
220
|
+
title="Support triage",
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
with client.beta.sessions.events.stream(session.id) as stream:
|
|
224
|
+
client.beta.sessions.events.send(
|
|
225
|
+
session.id,
|
|
226
|
+
events=[{
|
|
227
|
+
"type": "user.message",
|
|
228
|
+
"content": [{"type": "text", "text": "Check customer risk."}],
|
|
229
|
+
}],
|
|
230
|
+
)
|
|
231
|
+
for event in stream:
|
|
232
|
+
if getattr(event, "type", None) == "session.status_idle":
|
|
233
|
+
break
|
|
234
|
+
|
|
235
|
+
ak.flush()
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## LangChain and LangGraph
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
242
|
+
from agentkeeper_runtime_sdk.langchain import (
|
|
243
|
+
create_langchain_callback_handler,
|
|
244
|
+
wrap_langchain_tool,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
ak = create_agentkeeper_runtime_client(
|
|
248
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
249
|
+
runtime_service="support-agent",
|
|
250
|
+
runtime_integration="langchain",
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
callbacks = [create_langchain_callback_handler(ak)]
|
|
254
|
+
guarded_lookup = wrap_langchain_tool(customer_lookup_tool, ak)
|
|
255
|
+
|
|
256
|
+
chain.invoke({"input": "Check customer risk."}, {"callbacks": callbacks})
|
|
257
|
+
ak.flush()
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Use `create_langgraph_callback_handler()` and `wrap_langgraph_tool()` for LangGraph.
|
|
261
|
+
|
|
262
|
+
## AWS Bedrock Runtime
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
import boto3
|
|
266
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
267
|
+
from agentkeeper_runtime_sdk.bedrock import wrap_bedrock_runtime_client
|
|
268
|
+
|
|
269
|
+
ak = create_agentkeeper_runtime_client(
|
|
270
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
271
|
+
runtime_service="support-agent",
|
|
272
|
+
runtime_integration="bedrock",
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
bedrock = wrap_bedrock_runtime_client(
|
|
276
|
+
boto3.client("bedrock-runtime", region_name="us-east-1"),
|
|
277
|
+
ak,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
bedrock.converse(
|
|
281
|
+
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
|
|
282
|
+
messages=[{"role": "user", "content": [{"text": "Hello"}]}],
|
|
283
|
+
)
|
|
284
|
+
ak.flush()
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Privacy
|
|
288
|
+
|
|
289
|
+
Raw prompts, assistant output, tool arguments, provider request bodies, provider response bodies, and file contents are rejected by default. Send redacted summaries, hashes, model names, tool names, token counts, domains, and structured detector evidence instead.
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# AgentKeeper AI Agents SDK Beta for Python
|
|
2
|
+
|
|
3
|
+
Beta Python package for sending promptless AI agent runtime events to AgentKeeper.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install agentkeeper-runtime-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The Python package supports custom agents, LangChain, LangGraph, AWS Bedrock Runtime through boto3-style clients, OpenAI Agents SDK, Azure OpenAI, Claude Managed Agents, and Anthropic SDK message/tool surfaces. Vercel AI SDK remains TypeScript-only.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import os
|
|
15
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
16
|
+
|
|
17
|
+
ak = create_agentkeeper_runtime_client(
|
|
18
|
+
endpoint="https://app.agentkeeper.dev",
|
|
19
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
20
|
+
runtime_service="support-agent",
|
|
21
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
22
|
+
runtime_integration="custom",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
ak.track({
|
|
26
|
+
"event_kind": "runtime_heartbeat",
|
|
27
|
+
"capability": "observe",
|
|
28
|
+
"evidence_summary": "AI agent runtime connected",
|
|
29
|
+
})
|
|
30
|
+
ak.flush()
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Guarded Tools
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
def lookup_customer(args):
|
|
37
|
+
return {"customer_id": args["customer_id"], "tier": "enterprise"}
|
|
38
|
+
|
|
39
|
+
guarded_lookup = ak.wrap_tool(
|
|
40
|
+
"lookup_customer",
|
|
41
|
+
lookup_customer,
|
|
42
|
+
evaluate=lambda args: {"verdict": "passed", "reason": "allowed"},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
guarded_lookup({"customer_id": "cus_123"})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## OpenAI Agents SDK
|
|
49
|
+
|
|
50
|
+
Wrap Python functions before passing them to `function_tool` so the OpenAI Agents SDK can still infer the function signature.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
import os
|
|
55
|
+
from agents import Agent, Runner, function_tool
|
|
56
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
57
|
+
from agentkeeper_runtime_sdk.openai_agents import (
|
|
58
|
+
wrap_openai_agents_run,
|
|
59
|
+
wrap_openai_agents_tool,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
ak = create_agentkeeper_runtime_client(
|
|
63
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
64
|
+
runtime_service="support-agent",
|
|
65
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
66
|
+
runtime_integration="openai_agents",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def lookup_customer(customer_id: str) -> dict:
|
|
70
|
+
return {"customer_id": customer_id, "tier": "enterprise"}
|
|
71
|
+
|
|
72
|
+
guarded_lookup_customer = function_tool(
|
|
73
|
+
wrap_openai_agents_tool(
|
|
74
|
+
lookup_customer,
|
|
75
|
+
ak,
|
|
76
|
+
tool_name="lookup_customer",
|
|
77
|
+
evaluate=lambda args: {"verdict": "passed"},
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
async def main():
|
|
82
|
+
guarded_run = wrap_openai_agents_run(Runner.run, ak)
|
|
83
|
+
agent = Agent(name="Support triage", tools=[guarded_lookup_customer])
|
|
84
|
+
await guarded_run(agent, "Check customer risk without exposing raw payloads.")
|
|
85
|
+
ak.flush()
|
|
86
|
+
|
|
87
|
+
asyncio.run(main())
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Anthropic SDK
|
|
91
|
+
|
|
92
|
+
Anthropic message calls are model-only observation. Wrap local tool handlers or runnable `run(input)` functions for blocking.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import os
|
|
96
|
+
from anthropic import Anthropic
|
|
97
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
98
|
+
from agentkeeper_runtime_sdk.anthropic import (
|
|
99
|
+
wrap_anthropic_client,
|
|
100
|
+
wrap_anthropic_tool,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
ak = create_agentkeeper_runtime_client(
|
|
104
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
105
|
+
runtime_service="support-agent",
|
|
106
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
107
|
+
runtime_integration="anthropic_sdk",
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
anthropic = wrap_anthropic_client(Anthropic(), ak)
|
|
111
|
+
lookup_customer = wrap_anthropic_tool(
|
|
112
|
+
"lookup_customer",
|
|
113
|
+
lambda args: {"customer_id": args["customer_id"], "tier": "enterprise"},
|
|
114
|
+
ak,
|
|
115
|
+
evaluate=lambda args: {"verdict": "passed"},
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
message = anthropic.messages.create(
|
|
119
|
+
model=os.environ.get("ANTHROPIC_MODEL", "claude-sonnet-4-6"),
|
|
120
|
+
max_tokens=1024,
|
|
121
|
+
tools=[{
|
|
122
|
+
"name": "lookup_customer",
|
|
123
|
+
"description": "Look up a customer before support actions.",
|
|
124
|
+
"input_schema": {
|
|
125
|
+
"type": "object",
|
|
126
|
+
"properties": {"customer_id": {"type": "string"}},
|
|
127
|
+
"required": ["customer_id"],
|
|
128
|
+
},
|
|
129
|
+
}],
|
|
130
|
+
messages=[{"role": "user", "content": "Check customer risk."}],
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
for block in getattr(message, "content", []):
|
|
134
|
+
if getattr(block, "type", None) == "tool_use" and getattr(block, "name", None) == "lookup_customer":
|
|
135
|
+
lookup_customer(getattr(block, "input", {}))
|
|
136
|
+
|
|
137
|
+
ak.flush()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Azure OpenAI
|
|
141
|
+
|
|
142
|
+
Azure OpenAI is model-only observation. The wrapper records safe metadata for `chat.completions.create()`, `responses.create()`, and `embeddings.create()` without storing prompts, messages, inputs, outputs, or provider request/response bodies.
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
import os
|
|
146
|
+
from openai import AzureOpenAI
|
|
147
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
148
|
+
from agentkeeper_runtime_sdk.azure_openai import wrap_azure_openai_client
|
|
149
|
+
|
|
150
|
+
ak = create_agentkeeper_runtime_client(
|
|
151
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
152
|
+
runtime_service="support-agent",
|
|
153
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
154
|
+
runtime_integration="azure_openai",
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT", "gpt-4o-mini")
|
|
158
|
+
azure_openai = wrap_azure_openai_client(
|
|
159
|
+
AzureOpenAI(
|
|
160
|
+
api_key=os.environ["AZURE_OPENAI_API_KEY"],
|
|
161
|
+
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
162
|
+
api_version=os.environ.get("AZURE_OPENAI_API_VERSION", "2024-10-21"),
|
|
163
|
+
),
|
|
164
|
+
ak,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
azure_openai.chat.completions.create(
|
|
168
|
+
model=deployment,
|
|
169
|
+
messages=[{"role": "user", "content": "Check customer risk."}],
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
ak.flush()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Claude Managed Agents
|
|
176
|
+
|
|
177
|
+
Claude Managed Agents are hosted-session observation. The wrapper records safe agent, environment, session, event, stream, token, tool-name, and stop-reason metadata around Anthropic `client.beta.*` calls. It does not claim local pre-tool blocking for Anthropic-hosted sandbox/tool execution.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
import os
|
|
181
|
+
from anthropic import Anthropic
|
|
182
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
183
|
+
from agentkeeper_runtime_sdk.claude_managed_agents import wrap_claude_managed_agents_client
|
|
184
|
+
|
|
185
|
+
ak = create_agentkeeper_runtime_client(
|
|
186
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
187
|
+
runtime_service="support-agent",
|
|
188
|
+
runtime_environment=os.environ.get("APP_ENV", "local"),
|
|
189
|
+
runtime_integration="claude_managed_agents",
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
client = wrap_claude_managed_agents_client(Anthropic(), ak)
|
|
193
|
+
agent = client.beta.agents.create(
|
|
194
|
+
name="Support triage",
|
|
195
|
+
model=os.environ.get("ANTHROPIC_MANAGED_AGENT_MODEL", "claude-sonnet-4-6"),
|
|
196
|
+
system="Help support engineers without exposing raw payloads.",
|
|
197
|
+
tools=[{"type": "agent_toolset_20260401"}],
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
session = client.beta.sessions.create(
|
|
201
|
+
agent=agent.id,
|
|
202
|
+
environment_id=os.environ["ANTHROPIC_ENVIRONMENT_ID"],
|
|
203
|
+
title="Support triage",
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
with client.beta.sessions.events.stream(session.id) as stream:
|
|
207
|
+
client.beta.sessions.events.send(
|
|
208
|
+
session.id,
|
|
209
|
+
events=[{
|
|
210
|
+
"type": "user.message",
|
|
211
|
+
"content": [{"type": "text", "text": "Check customer risk."}],
|
|
212
|
+
}],
|
|
213
|
+
)
|
|
214
|
+
for event in stream:
|
|
215
|
+
if getattr(event, "type", None) == "session.status_idle":
|
|
216
|
+
break
|
|
217
|
+
|
|
218
|
+
ak.flush()
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## LangChain and LangGraph
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
225
|
+
from agentkeeper_runtime_sdk.langchain import (
|
|
226
|
+
create_langchain_callback_handler,
|
|
227
|
+
wrap_langchain_tool,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
ak = create_agentkeeper_runtime_client(
|
|
231
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
232
|
+
runtime_service="support-agent",
|
|
233
|
+
runtime_integration="langchain",
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
callbacks = [create_langchain_callback_handler(ak)]
|
|
237
|
+
guarded_lookup = wrap_langchain_tool(customer_lookup_tool, ak)
|
|
238
|
+
|
|
239
|
+
chain.invoke({"input": "Check customer risk."}, {"callbacks": callbacks})
|
|
240
|
+
ak.flush()
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Use `create_langgraph_callback_handler()` and `wrap_langgraph_tool()` for LangGraph.
|
|
244
|
+
|
|
245
|
+
## AWS Bedrock Runtime
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
import boto3
|
|
249
|
+
from agentkeeper_runtime_sdk import create_agentkeeper_runtime_client
|
|
250
|
+
from agentkeeper_runtime_sdk.bedrock import wrap_bedrock_runtime_client
|
|
251
|
+
|
|
252
|
+
ak = create_agentkeeper_runtime_client(
|
|
253
|
+
api_key=os.environ.get("AGENTKEEPER_RUNTIME_SDK_KEY"),
|
|
254
|
+
runtime_service="support-agent",
|
|
255
|
+
runtime_integration="bedrock",
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
bedrock = wrap_bedrock_runtime_client(
|
|
259
|
+
boto3.client("bedrock-runtime", region_name="us-east-1"),
|
|
260
|
+
ak,
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
bedrock.converse(
|
|
264
|
+
modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
|
|
265
|
+
messages=[{"role": "user", "content": [{"text": "Hello"}]}],
|
|
266
|
+
)
|
|
267
|
+
ak.flush()
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Privacy
|
|
271
|
+
|
|
272
|
+
Raw prompts, assistant output, tool arguments, provider request bodies, provider response bodies, and file contents are rejected by default. Send redacted summaries, hashes, model names, tool names, token counts, domains, and structured detector evidence instead.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "agentkeeper-runtime-sdk"
|
|
7
|
+
version = "0.1.0b1"
|
|
8
|
+
description = "AgentKeeper AI Agents SDK Beta for app-embedded Python agents."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "AgentKeeper" }
|
|
14
|
+
]
|
|
15
|
+
keywords = ["agentkeeper", "ai-agent", "runtime", "security", "monitoring"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://app.agentkeeper.dev"
|
|
26
|
+
Repository = "https://github.com/rad-security/agentkeeper-web"
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["src/agentkeeper_runtime_sdk"]
|
|
30
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from .anthropic import (
|
|
2
|
+
wrap_anthropic_client,
|
|
3
|
+
wrap_anthropic_runnable_tool,
|
|
4
|
+
wrap_anthropic_tool,
|
|
5
|
+
)
|
|
6
|
+
from .bedrock import wrap_bedrock_runtime_client
|
|
7
|
+
from .azure_openai import wrap_azure_openai_client
|
|
8
|
+
from .claude_managed_agents import wrap_claude_managed_agents_client
|
|
9
|
+
from .client import (
|
|
10
|
+
AgentKeeperRuntimeClient,
|
|
11
|
+
TrackResult,
|
|
12
|
+
create_agentkeeper_runtime_client,
|
|
13
|
+
find_raw_payload_keys,
|
|
14
|
+
)
|
|
15
|
+
from .langchain import (
|
|
16
|
+
create_langchain_callback_handler,
|
|
17
|
+
create_langgraph_callback_handler,
|
|
18
|
+
wrap_langchain_tool,
|
|
19
|
+
wrap_langgraph_tool,
|
|
20
|
+
)
|
|
21
|
+
from .openai_agents import (
|
|
22
|
+
wrap_openai_agents_run,
|
|
23
|
+
wrap_openai_agents_sdk,
|
|
24
|
+
wrap_openai_agents_tool,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"AgentKeeperRuntimeClient",
|
|
29
|
+
"TrackResult",
|
|
30
|
+
"create_agentkeeper_runtime_client",
|
|
31
|
+
"find_raw_payload_keys",
|
|
32
|
+
"create_langchain_callback_handler",
|
|
33
|
+
"create_langgraph_callback_handler",
|
|
34
|
+
"wrap_langchain_tool",
|
|
35
|
+
"wrap_langgraph_tool",
|
|
36
|
+
"wrap_bedrock_runtime_client",
|
|
37
|
+
"wrap_azure_openai_client",
|
|
38
|
+
"wrap_claude_managed_agents_client",
|
|
39
|
+
"wrap_openai_agents_run",
|
|
40
|
+
"wrap_openai_agents_sdk",
|
|
41
|
+
"wrap_openai_agents_tool",
|
|
42
|
+
"wrap_anthropic_client",
|
|
43
|
+
"wrap_anthropic_runnable_tool",
|
|
44
|
+
"wrap_anthropic_tool",
|
|
45
|
+
]
|