agentkit-sdk-python 0.9.1__py3-none-any.whl → 0.9.3__py3-none-any.whl
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.
- agentkit/__init__.py +5 -5
- agentkit/apps/a2a_app/a2a_app.py +68 -10
- agentkit/apps/agent_server_app/agent_server_app.py +38 -4
- agentkit/client/base_service_client.py +102 -8
- agentkit/frameworks/_agentsentry.py +5 -0
- agentkit/plugins/agentsentry_v3.py +14 -11
- agentkit/sdk/gateway/__init__.py +29 -0
- agentkit/sdk/gateway/client.py +70 -0
- agentkit/sdk/gateway/types.py +45 -0
- agentkit/sdk/organizations/__init__.py +63 -0
- agentkit/sdk/organizations/client.py +175 -0
- agentkit/sdk/organizations/types.py +368 -0
- agentkit/sdk/users/__init__.py +73 -0
- agentkit/sdk/users/client.py +181 -0
- agentkit/sdk/users/types.py +548 -0
- agentkit/sdk/workspaces/__init__.py +91 -0
- agentkit/sdk/workspaces/client.py +272 -0
- agentkit/sdk/workspaces/types.py +539 -0
- agentkit/toolkit/resources/samples/a2a.py +14 -2
- agentkit/version.py +1 -1
- {agentkit_sdk_python-0.9.1.dist-info → agentkit_sdk_python-0.9.3.dist-info}/METADATA +2 -2
- {agentkit_sdk_python-0.9.1.dist-info → agentkit_sdk_python-0.9.3.dist-info}/RECORD +26 -14
- {agentkit_sdk_python-0.9.1.dist-info → agentkit_sdk_python-0.9.3.dist-info}/WHEEL +0 -0
- {agentkit_sdk_python-0.9.1.dist-info → agentkit_sdk_python-0.9.3.dist-info}/entry_points.txt +0 -0
- {agentkit_sdk_python-0.9.1.dist-info → agentkit_sdk_python-0.9.3.dist-info}/licenses/LICENSE +0 -0
- {agentkit_sdk_python-0.9.1.dist-info → agentkit_sdk_python-0.9.3.dist-info}/top_level.txt +0 -0
agentkit/__init__.py
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
|
|
15
15
|
# Note: BaseAgentkitClient and ApiConfig are internal infrastructure classes.
|
|
16
16
|
# Users should use the high-level service clients instead:
|
|
17
|
-
# - from agentkit.memory import
|
|
18
|
-
# - from agentkit.knowledge import
|
|
19
|
-
# - from agentkit.mcp import
|
|
20
|
-
# - from agentkit.runtime import
|
|
21
|
-
# - from agentkit.tools import
|
|
17
|
+
# - from agentkit.sdk.memory import AgentkitMemoryClient
|
|
18
|
+
# - from agentkit.sdk.knowledge import AgentkitKnowledgeClient
|
|
19
|
+
# - from agentkit.sdk.mcp import AgentkitMCPClient
|
|
20
|
+
# - from agentkit.sdk.runtime import AgentkitRuntimeClient
|
|
21
|
+
# - from agentkit.sdk.tools import AgentkitToolsClient
|
|
22
22
|
|
|
23
23
|
__all__ = []
|
agentkit/apps/a2a_app/a2a_app.py
CHANGED
|
@@ -21,7 +21,6 @@ from typing import Callable
|
|
|
21
21
|
from typing_extensions import override
|
|
22
22
|
from a2a.server.agent_execution import AgentExecutor
|
|
23
23
|
from a2a.server.agent_execution.context import RequestContext
|
|
24
|
-
from a2a.server.apps import A2AStarletteApplication
|
|
25
24
|
from a2a.server.events.event_queue import EventQueue
|
|
26
25
|
from a2a.server.request_handlers import DefaultRequestHandler
|
|
27
26
|
from a2a.server.tasks import InMemoryTaskStore
|
|
@@ -37,6 +36,16 @@ from agentkit.apps.base_app import BaseAgentkitApp
|
|
|
37
36
|
|
|
38
37
|
logger = logging.getLogger(__name__)
|
|
39
38
|
|
|
39
|
+
try:
|
|
40
|
+
# a2a-sdk 1.x
|
|
41
|
+
from a2a.server.routes import create_agent_card_routes, create_jsonrpc_routes
|
|
42
|
+
|
|
43
|
+
_A2A_1X = True
|
|
44
|
+
except ImportError: # a2a-sdk 0.3.x
|
|
45
|
+
from a2a.server.apps import A2AStarletteApplication
|
|
46
|
+
|
|
47
|
+
_A2A_1X = False
|
|
48
|
+
|
|
40
49
|
|
|
41
50
|
def _wrap_agent_executor_execute_func(execute_func: Callable) -> Callable:
|
|
42
51
|
async def wrapper(*args, **kwargs):
|
|
@@ -183,24 +192,73 @@ class AgentkitA2aApp(BaseAgentkitApp):
|
|
|
183
192
|
def add_ping_route(self, app: Starlette):
|
|
184
193
|
app.add_route("/ping", self.ping_endpoint, methods=["GET"])
|
|
185
194
|
|
|
186
|
-
|
|
187
|
-
|
|
195
|
+
def _build_a2a_app(self, agent_card: AgentCard) -> Starlette:
|
|
196
|
+
"""Build the A2A Starlette application without binding a socket.
|
|
197
|
+
|
|
198
|
+
a2a-sdk 1.x removed ``A2AStarletteApplication``; use the route factory
|
|
199
|
+
there. a2a-sdk 0.3.x still provides ``A2AStarletteApplication`` and has
|
|
200
|
+
no ``a2a.server.routes`` module, so fall back to it. Both branches
|
|
201
|
+
serve the historical ``/.well-known/agent.json`` path alongside the
|
|
202
|
+
standard card path so existing discovery code keeps working.
|
|
203
|
+
"""
|
|
188
204
|
if not self._agent_executor:
|
|
189
205
|
raise RuntimeError(
|
|
190
206
|
"At least one executor should be provided via `@agent_executor(...)`."
|
|
191
207
|
)
|
|
192
|
-
|
|
208
|
+
task_store = self._task_store
|
|
209
|
+
if task_store is None:
|
|
193
210
|
logger.warning(
|
|
194
211
|
"No task store provided. You can provide a task store via `@task_store(...)`. Using in-memory task store instead."
|
|
195
212
|
)
|
|
196
|
-
|
|
213
|
+
task_store = InMemoryTaskStore()
|
|
214
|
+
|
|
215
|
+
if not _A2A_1X:
|
|
216
|
+
# a2a-sdk 0.3.x's DefaultRequestHandler does not accept agent_card;
|
|
217
|
+
# the application owns the card route instead.
|
|
218
|
+
handler = DefaultRequestHandler(
|
|
219
|
+
agent_executor=self._agent_executor,
|
|
220
|
+
task_store=task_store,
|
|
221
|
+
)
|
|
222
|
+
app = A2AStarletteApplication(
|
|
223
|
+
agent_card=agent_card,
|
|
224
|
+
http_handler=handler,
|
|
225
|
+
).build()
|
|
226
|
+
# A2AStarletteApplication only serves the standard card path. Add
|
|
227
|
+
# the historical path for parity with the a2a 1.x branch.
|
|
228
|
+
app.routes.append(
|
|
229
|
+
Route(
|
|
230
|
+
"/.well-known/agent.json",
|
|
231
|
+
endpoint=lambda request: JSONResponse(
|
|
232
|
+
agent_card.model_dump(mode="json")
|
|
233
|
+
),
|
|
234
|
+
methods=["GET"],
|
|
235
|
+
name="legacy_agent_card",
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
return app
|
|
197
239
|
|
|
198
|
-
|
|
240
|
+
handler = DefaultRequestHandler(
|
|
241
|
+
agent_executor=self._agent_executor,
|
|
242
|
+
task_store=task_store,
|
|
199
243
|
agent_card=agent_card,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
244
|
+
)
|
|
245
|
+
return Starlette(
|
|
246
|
+
routes=[
|
|
247
|
+
*create_agent_card_routes(agent_card),
|
|
248
|
+
*create_agent_card_routes(
|
|
249
|
+
agent_card, card_url="/.well-known/agent.json"
|
|
250
|
+
),
|
|
251
|
+
*create_jsonrpc_routes(
|
|
252
|
+
handler,
|
|
253
|
+
rpc_url="/",
|
|
254
|
+
enable_v0_3_compat=True,
|
|
255
|
+
),
|
|
256
|
+
]
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
@override
|
|
260
|
+
def run(self, agent_card: AgentCard, host: str, port: int = 8000):
|
|
261
|
+
a2a_app = self._build_a2a_app(agent_card)
|
|
204
262
|
|
|
205
263
|
# Register routes in the same style
|
|
206
264
|
self.add_ping_route(a2a_app)
|
|
@@ -59,9 +59,6 @@ except ImportError: # pragma: no cover - default migration path avoids veadk.
|
|
|
59
59
|
ShortTermMemory = None # type: ignore[assignment,misc]
|
|
60
60
|
VeadkRunner = None # type: ignore[assignment]
|
|
61
61
|
|
|
62
|
-
from agentkit.apps.agent_server_app.middleware import (
|
|
63
|
-
AgentkitTelemetryHTTPMiddleware,
|
|
64
|
-
)
|
|
65
62
|
from agentkit.apps.agent_server_app.credential_service import (
|
|
66
63
|
AgentkitCredentialService,
|
|
67
64
|
)
|
|
@@ -70,7 +67,9 @@ from agentkit.apps.agent_server_app.inbound_auth_adapter import (
|
|
|
70
67
|
build_a2a_inbound_auth_executor_factory,
|
|
71
68
|
save_inbound_auth,
|
|
72
69
|
)
|
|
73
|
-
from agentkit.apps.
|
|
70
|
+
from agentkit.apps.agent_server_app.middleware import (
|
|
71
|
+
AgentkitTelemetryHTTPMiddleware,
|
|
72
|
+
)
|
|
74
73
|
from agentkit.apps.agent_server_app.origin import (
|
|
75
74
|
add_cors_compat_middleware,
|
|
76
75
|
adk_supports_regex_origins,
|
|
@@ -79,6 +78,7 @@ from agentkit.apps.agent_server_app.origin import (
|
|
|
79
78
|
supports_get_fast_api_kwarg,
|
|
80
79
|
)
|
|
81
80
|
from agentkit.apps.agent_server_app.telemetry import telemetry
|
|
81
|
+
from agentkit.apps.auth.inbound import redact_inbound_auth_headers
|
|
82
82
|
from agentkit.apps.base_app import BaseAgentkitApp
|
|
83
83
|
|
|
84
84
|
if TYPE_CHECKING:
|
|
@@ -124,6 +124,34 @@ def _resolve_memory_service(root_agent: BaseAgent) -> Any:
|
|
|
124
124
|
return InMemoryMemoryService()
|
|
125
125
|
|
|
126
126
|
|
|
127
|
+
class _SsePayloadEventIdRewriter:
|
|
128
|
+
def __init__(self) -> None:
|
|
129
|
+
self._emitted_ids: set[str] = set()
|
|
130
|
+
self._next_id = 0
|
|
131
|
+
|
|
132
|
+
def prepare(self, event: Any) -> Any:
|
|
133
|
+
event_id = str(getattr(event, "id", "") or "")
|
|
134
|
+
should_rewrite = (
|
|
135
|
+
bool(getattr(event, "partial", False))
|
|
136
|
+
or not event_id
|
|
137
|
+
or event_id in self._emitted_ids
|
|
138
|
+
)
|
|
139
|
+
if should_rewrite:
|
|
140
|
+
event = event.model_copy(deep=True)
|
|
141
|
+
unique_id = (
|
|
142
|
+
f"{event_id}:veid:{self._next_id}"
|
|
143
|
+
if event_id
|
|
144
|
+
else f"veid:{self._next_id}"
|
|
145
|
+
)
|
|
146
|
+
self._next_id += 1
|
|
147
|
+
event.id = unique_id
|
|
148
|
+
|
|
149
|
+
emitted_id = str(getattr(event, "id", "") or "")
|
|
150
|
+
if emitted_id:
|
|
151
|
+
self._emitted_ids.add(emitted_id)
|
|
152
|
+
return event
|
|
153
|
+
|
|
154
|
+
|
|
127
155
|
def _create_a2a_runner(
|
|
128
156
|
*,
|
|
129
157
|
entry: BaseAgent | App,
|
|
@@ -425,6 +453,7 @@ class AgentkitAgentServerApp(BaseAgentkitApp):
|
|
|
425
453
|
# Convert the events to properly formatted SSE
|
|
426
454
|
async def event_generator():
|
|
427
455
|
error_payload = None
|
|
456
|
+
event_id_rewriter = _SsePayloadEventIdRewriter()
|
|
428
457
|
try:
|
|
429
458
|
stream_mode = (
|
|
430
459
|
StreamingMode.SSE if req.streaming else StreamingMode.NONE
|
|
@@ -460,6 +489,9 @@ class AgentkitAgentServerApp(BaseAgentkitApp):
|
|
|
460
489
|
artifact_event,
|
|
461
490
|
]
|
|
462
491
|
for event_to_stream in events_to_stream:
|
|
492
|
+
event_to_stream = event_id_rewriter.prepare(
|
|
493
|
+
event_to_stream
|
|
494
|
+
)
|
|
463
495
|
sse_event = event_to_stream.model_dump_json(
|
|
464
496
|
exclude_none=True,
|
|
465
497
|
by_alias=True,
|
|
@@ -596,6 +628,7 @@ class AgentkitAgentServerApp(BaseAgentkitApp):
|
|
|
596
628
|
|
|
597
629
|
async def event_generator():
|
|
598
630
|
error_payload = None
|
|
631
|
+
event_id_rewriter = _SsePayloadEventIdRewriter()
|
|
599
632
|
try:
|
|
600
633
|
runner = await self.server.get_runner_async(app_name)
|
|
601
634
|
async with Aclosing(
|
|
@@ -607,6 +640,7 @@ class AgentkitAgentServerApp(BaseAgentkitApp):
|
|
|
607
640
|
)
|
|
608
641
|
) as agen:
|
|
609
642
|
async for event in agen:
|
|
643
|
+
event = event_id_rewriter.prepare(event)
|
|
610
644
|
yield (
|
|
611
645
|
"data: "
|
|
612
646
|
+ event.model_dump_json(
|
|
@@ -25,6 +25,7 @@ import requests
|
|
|
25
25
|
from requests.adapters import HTTPAdapter
|
|
26
26
|
from urllib3.util.retry import Retry
|
|
27
27
|
from volcengine.ApiInfo import ApiInfo
|
|
28
|
+
from volcengine.auth.SignerV4 import SignerV4
|
|
28
29
|
from volcengine.base.Service import Service
|
|
29
30
|
from volcengine.Credentials import Credentials as VolcCredentials
|
|
30
31
|
from volcengine.ServiceInfo import ServiceInfo
|
|
@@ -316,7 +317,11 @@ class BaseServiceClient(Service):
|
|
|
316
317
|
params: Dict[str, Any] = None,
|
|
317
318
|
) -> T:
|
|
318
319
|
"""
|
|
319
|
-
Unified API invocation with error handling.
|
|
320
|
+
Unified POST API invocation with error handling.
|
|
321
|
+
|
|
322
|
+
Sends the request as a JSON body (``Action``/``Version`` travel in
|
|
323
|
+
the query string); endpoints declared as HTTP GET in the OpenAPI
|
|
324
|
+
definition must use :meth:`_invoke_get_api` instead.
|
|
320
325
|
|
|
321
326
|
Args:
|
|
322
327
|
api_action: The API action name (e.g., 'GetUser', 'ListRuntimes')
|
|
@@ -331,6 +336,56 @@ class BaseServiceClient(Service):
|
|
|
331
336
|
ApiError: If the API call fails or returns an error response.
|
|
332
337
|
NetworkError: If a transport-level failure occurs.
|
|
333
338
|
"""
|
|
339
|
+
body = json.dumps(request.model_dump(by_alias=True, exclude_none=True))
|
|
340
|
+
return self._invoke_action(
|
|
341
|
+
api_action, response_type, params=params, body=body
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
def _invoke_get_api(
|
|
345
|
+
self,
|
|
346
|
+
api_action: str,
|
|
347
|
+
params: Dict[str, Any],
|
|
348
|
+
response_type: Type[T],
|
|
349
|
+
) -> T:
|
|
350
|
+
"""
|
|
351
|
+
Unified GET API invocation with error handling.
|
|
352
|
+
|
|
353
|
+
For endpoints declared as HTTP GET in the OpenAPI definition
|
|
354
|
+
(``google.api.http get``): business params travel in the query
|
|
355
|
+
string with their PascalCase keys, next to ``Action``/``Version``,
|
|
356
|
+
and no JSON body is sent.
|
|
357
|
+
|
|
358
|
+
Args:
|
|
359
|
+
api_action: The API action name (e.g., 'ListUsers')
|
|
360
|
+
params: Business query parameters (PascalCase keys; int/bool
|
|
361
|
+
values are stringified by ``Service.prepare_request``)
|
|
362
|
+
response_type: The response type to parse into
|
|
363
|
+
|
|
364
|
+
Returns:
|
|
365
|
+
Typed response object
|
|
366
|
+
|
|
367
|
+
Raises:
|
|
368
|
+
ApiError: If the API call fails or returns an error response.
|
|
369
|
+
NetworkError: If a transport-level failure occurs.
|
|
370
|
+
"""
|
|
371
|
+
return self._invoke_action(
|
|
372
|
+
api_action, response_type, params=params, body=None
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
def _invoke_action(
|
|
376
|
+
self,
|
|
377
|
+
api_action: str,
|
|
378
|
+
response_type: Type[T],
|
|
379
|
+
*,
|
|
380
|
+
params: Dict[str, Any] = None,
|
|
381
|
+
body: Optional[str],
|
|
382
|
+
) -> T:
|
|
383
|
+
"""
|
|
384
|
+
Shared invocation skeleton for :meth:`_invoke_api` (POST, JSON
|
|
385
|
+
body) and :meth:`_invoke_get_api` (GET, query-string params):
|
|
386
|
+
credential auto-refresh, the two-attempt credential-error retry,
|
|
387
|
+
typed error wrapping and response parsing.
|
|
388
|
+
"""
|
|
334
389
|
# Imported lazily: ``agentkit.toolkit`` pulls in ``sdk`` which imports
|
|
335
390
|
# back into ``agentkit.client``, so a module-level import would cycle.
|
|
336
391
|
from agentkit.toolkit.errors import ApiError
|
|
@@ -344,13 +399,14 @@ class BaseServiceClient(Service):
|
|
|
344
399
|
self._refresh_credentials_if_needed(force=True)
|
|
345
400
|
|
|
346
401
|
try:
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
402
|
+
if body is None:
|
|
403
|
+
res = self._send_get(api_action, params or {})
|
|
404
|
+
else:
|
|
405
|
+
res = self.json(
|
|
406
|
+
api=api_action,
|
|
407
|
+
params=params or {},
|
|
408
|
+
body=body,
|
|
409
|
+
)
|
|
354
410
|
except (
|
|
355
411
|
requests.exceptions.ConnectionError,
|
|
356
412
|
requests.exceptions.Timeout,
|
|
@@ -406,3 +462,41 @@ class BaseServiceClient(Service):
|
|
|
406
462
|
f"Failed to {api_action}: {str(last_error)}"
|
|
407
463
|
) from last_error
|
|
408
464
|
raise ApiError(f"Failed to {api_action}: Unknown error")
|
|
465
|
+
|
|
466
|
+
def _send_get(self, api_action: str, params: Dict[str, Any]) -> str:
|
|
467
|
+
"""Send one GET-style OpenAPI request and return the raw response
|
|
468
|
+
text.
|
|
469
|
+
|
|
470
|
+
Mirrors ``Service.json`` (which signs POSTs directly) for GETs:
|
|
471
|
+
``prepare_request`` merges business ``params`` into the query
|
|
472
|
+
string next to ``Action``/``Version``, the request is signed with
|
|
473
|
+
an empty-string body (``sha256("")`` — what the server expects for
|
|
474
|
+
bodyless GETs, matching the agentkit-cli signer), and no body is
|
|
475
|
+
sent on the wire.
|
|
476
|
+
|
|
477
|
+
``Service.request`` cannot be used here: its ``VolcAuth`` hook
|
|
478
|
+
copies the PreparedRequest body into the signed request, and
|
|
479
|
+
requests drops an empty-string body to ``None``
|
|
480
|
+
(``PreparedRequest.prepare_body``: ``if not data: body = None``),
|
|
481
|
+
so ``Util.sha256(None)`` crashes with "object supporting the
|
|
482
|
+
buffer API required".
|
|
483
|
+
"""
|
|
484
|
+
api_info = self.api_info[api_action]
|
|
485
|
+
# Pass a copy: prepare_request mutates the dict while
|
|
486
|
+
# stringifying values.
|
|
487
|
+
r = self.prepare_request(api_info, dict(params or {}))
|
|
488
|
+
r.body = ""
|
|
489
|
+
SignerV4.sign(r, self.service_info.credentials)
|
|
490
|
+
url = r.build()
|
|
491
|
+
resp = self.session.request(
|
|
492
|
+
api_info.method,
|
|
493
|
+
url,
|
|
494
|
+
headers=r.headers,
|
|
495
|
+
timeout=(
|
|
496
|
+
self.service_info.connection_timeout,
|
|
497
|
+
self.service_info.socket_timeout,
|
|
498
|
+
),
|
|
499
|
+
)
|
|
500
|
+
if resp.status_code == 200:
|
|
501
|
+
return resp.text
|
|
502
|
+
raise Exception(resp.text)
|
|
@@ -141,6 +141,7 @@ def protect_migrated_tools(method):
|
|
|
141
141
|
return
|
|
142
142
|
guard = _make_guard(plugin, ctx)
|
|
143
143
|
events = method(self, ctx)
|
|
144
|
+
streamed_text = False
|
|
144
145
|
try:
|
|
145
146
|
while True:
|
|
146
147
|
token = _active_guard.set(guard)
|
|
@@ -156,8 +157,12 @@ def protect_migrated_tools(method):
|
|
|
156
157
|
_active_guard.reset(token)
|
|
157
158
|
if guard.blocked:
|
|
158
159
|
break
|
|
160
|
+
streamed_text = streamed_text or getattr(event, "partial", False) is True
|
|
159
161
|
yield event
|
|
160
162
|
if guard.blocked:
|
|
163
|
+
if streamed_text:
|
|
164
|
+
# Live clients may drop complete text after an earlier delta.
|
|
165
|
+
yield adk_event(ctx, self.name, f"\n\n{guard.blocked}", partial=True)
|
|
161
166
|
yield adk_event(ctx, self.name, guard.blocked, partial=False)
|
|
162
167
|
finally:
|
|
163
168
|
token = _active_guard.set(guard)
|
|
@@ -152,24 +152,27 @@ class AgentSentryV3:
|
|
|
152
152
|
return UNAVAILABLE
|
|
153
153
|
data = response.json()
|
|
154
154
|
result = data.get("Result") or {}
|
|
155
|
+
metadata = data.get("ResponseMetadata") or {}
|
|
156
|
+
request_id = metadata.get("RequestId")
|
|
157
|
+
if metadata.get("Error"):
|
|
158
|
+
logger.warning("AgentSentry V3 API error request_id=%s", request_id)
|
|
159
|
+
return UNAVAILABLE
|
|
160
|
+
decision = (result.get("Decision") or {}).get("DecisionType")
|
|
155
161
|
logger.info(
|
|
156
162
|
"AgentSentry V3 hook=%s request_id=%s decision=%s degraded=%s",
|
|
157
163
|
hook_name,
|
|
158
|
-
|
|
159
|
-
|
|
164
|
+
request_id,
|
|
165
|
+
decision,
|
|
160
166
|
result.get("Degraded"),
|
|
161
167
|
)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return UNAVAILABLE
|
|
166
|
-
decision = (result.get("Decision") or {}).get("DecisionType")
|
|
167
|
-
if type(decision) is int and decision == 1:
|
|
168
|
+
try:
|
|
169
|
+
decision = int(decision)
|
|
170
|
+
except (ValueError, TypeError, OverflowError):
|
|
168
171
|
return None
|
|
169
|
-
if
|
|
172
|
+
if decision == 2:
|
|
170
173
|
return BLOCK
|
|
171
|
-
#
|
|
172
|
-
return
|
|
174
|
+
# Only an explicit BLOCK decision stops a successful moderation response.
|
|
175
|
+
return None
|
|
173
176
|
except (requests.RequestException, ValueError, TypeError, AttributeError):
|
|
174
177
|
logger.warning("AgentSentry V3 transport or response error")
|
|
175
178
|
return UNAVAILABLE
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from .client import AgentkitGatewayClient
|
|
16
|
+
from .types import (
|
|
17
|
+
CreateGatewayPluginBindingRequest,
|
|
18
|
+
CreateGatewayPluginBindingResponse,
|
|
19
|
+
CreateGatewayPluginRequest,
|
|
20
|
+
CreateGatewayPluginResponse,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"AgentkitGatewayClient",
|
|
25
|
+
"CreateGatewayPluginBindingRequest",
|
|
26
|
+
"CreateGatewayPluginBindingResponse",
|
|
27
|
+
"CreateGatewayPluginRequest",
|
|
28
|
+
"CreateGatewayPluginResponse",
|
|
29
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import ClassVar
|
|
18
|
+
|
|
19
|
+
from agentkit.client import BaseAgentkitClient
|
|
20
|
+
|
|
21
|
+
from .types import (
|
|
22
|
+
CreateGatewayPluginBindingRequest,
|
|
23
|
+
CreateGatewayPluginBindingResponse,
|
|
24
|
+
CreateGatewayPluginRequest,
|
|
25
|
+
CreateGatewayPluginResponse,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AgentkitGatewayClient(BaseAgentkitClient):
|
|
30
|
+
"""Manage plugins on dedicated AgentKit gateways and bind them to MCP services."""
|
|
31
|
+
|
|
32
|
+
API_ACTIONS: ClassVar[dict[str, str]] = {
|
|
33
|
+
"CreateGatewayPlugin": "CreateGatewayPlugin",
|
|
34
|
+
"CreateGatewayPluginBinding": "CreateGatewayPluginBinding",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
access_key: str = "",
|
|
40
|
+
secret_key: str = "",
|
|
41
|
+
region: str = "",
|
|
42
|
+
session_token: str = "",
|
|
43
|
+
) -> None:
|
|
44
|
+
super().__init__(
|
|
45
|
+
access_key=access_key,
|
|
46
|
+
secret_key=secret_key,
|
|
47
|
+
region=region,
|
|
48
|
+
session_token=session_token,
|
|
49
|
+
service_name="gateway",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def create_gateway_plugin(
|
|
53
|
+
self, request: CreateGatewayPluginRequest
|
|
54
|
+
) -> CreateGatewayPluginResponse:
|
|
55
|
+
"""Install a plugin; create a binding separately to apply it to requests."""
|
|
56
|
+
return self._invoke_api(
|
|
57
|
+
api_action="CreateGatewayPlugin",
|
|
58
|
+
request=request,
|
|
59
|
+
response_type=CreateGatewayPluginResponse,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def create_gateway_plugin_binding(
|
|
63
|
+
self, request: CreateGatewayPluginBindingRequest
|
|
64
|
+
) -> CreateGatewayPluginBindingResponse:
|
|
65
|
+
"""Bind an installed gateway plugin to a target MCP service."""
|
|
66
|
+
return self._invoke_api(
|
|
67
|
+
api_action="CreateGatewayPluginBinding",
|
|
68
|
+
request=request,
|
|
69
|
+
response_type=CreateGatewayPluginBindingResponse,
|
|
70
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from pydantic import BaseModel, Field
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class GatewayBaseModel(BaseModel):
|
|
21
|
+
model_config = {"populate_by_name": True}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CreateGatewayPluginRequest(GatewayBaseModel):
|
|
25
|
+
gateway_instance_id: str = Field(..., alias="GatewayInstanceId")
|
|
26
|
+
gateway_plugin_name: str = Field(..., alias="GatewayPluginName")
|
|
27
|
+
gateway_plugin_config: str = Field(..., alias="GatewayPluginConfig")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class CreateGatewayPluginResponse(GatewayBaseModel):
|
|
31
|
+
gateway_plugin_id: str | None = Field(default=None, alias="GatewayPluginId")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class CreateGatewayPluginBindingRequest(GatewayBaseModel):
|
|
35
|
+
gateway_plugin_id: str = Field(..., alias="GatewayPluginId")
|
|
36
|
+
target_id: str = Field(..., alias="TargetId")
|
|
37
|
+
gateway_plugin_binding_config: str = Field(..., alias="GatewayPluginBindingConfig")
|
|
38
|
+
enable: bool | None = Field(default=None, alias="Enable")
|
|
39
|
+
comments: str | None = Field(default=None, alias="Comments")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class CreateGatewayPluginBindingResponse(GatewayBaseModel):
|
|
43
|
+
gateway_plugin_binding_id: str | None = Field(
|
|
44
|
+
default=None, alias="GatewayPluginBindingId"
|
|
45
|
+
)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from .client import AgentkitOrganizationClient
|
|
16
|
+
from .types import (
|
|
17
|
+
MAX_LIST_ORGANIZATION_MEMBERS_RESULTS,
|
|
18
|
+
ORGANIZATION_ADMIN_ROLE,
|
|
19
|
+
AddOrganizationMemberRequest,
|
|
20
|
+
AddOrganizationMemberResponse,
|
|
21
|
+
CreateOrganizationRequest,
|
|
22
|
+
CreateOrganizationResponse,
|
|
23
|
+
DeleteOrganizationRequest,
|
|
24
|
+
DeleteOrganizationResponse,
|
|
25
|
+
GetOrganizationRequest,
|
|
26
|
+
GetOrganizationResponse,
|
|
27
|
+
ListOrganizationMembersRequest,
|
|
28
|
+
ListOrganizationMembersResponse,
|
|
29
|
+
OrganizationData,
|
|
30
|
+
OrganizationEndpointData,
|
|
31
|
+
OrganizationMemberData,
|
|
32
|
+
OrganizationsBaseModel,
|
|
33
|
+
RemoveOrganizationMemberRequest,
|
|
34
|
+
RemoveOrganizationMemberResponse,
|
|
35
|
+
UpdateOrganizationEndpointData,
|
|
36
|
+
UpdateOrganizationRequest,
|
|
37
|
+
UpdateOrganizationResponse,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"AgentkitOrganizationClient",
|
|
42
|
+
"MAX_LIST_ORGANIZATION_MEMBERS_RESULTS",
|
|
43
|
+
"ORGANIZATION_ADMIN_ROLE",
|
|
44
|
+
"AddOrganizationMemberRequest",
|
|
45
|
+
"AddOrganizationMemberResponse",
|
|
46
|
+
"CreateOrganizationRequest",
|
|
47
|
+
"CreateOrganizationResponse",
|
|
48
|
+
"DeleteOrganizationRequest",
|
|
49
|
+
"DeleteOrganizationResponse",
|
|
50
|
+
"GetOrganizationRequest",
|
|
51
|
+
"GetOrganizationResponse",
|
|
52
|
+
"ListOrganizationMembersRequest",
|
|
53
|
+
"ListOrganizationMembersResponse",
|
|
54
|
+
"OrganizationData",
|
|
55
|
+
"OrganizationEndpointData",
|
|
56
|
+
"OrganizationMemberData",
|
|
57
|
+
"OrganizationsBaseModel",
|
|
58
|
+
"RemoveOrganizationMemberRequest",
|
|
59
|
+
"RemoveOrganizationMemberResponse",
|
|
60
|
+
"UpdateOrganizationEndpointData",
|
|
61
|
+
"UpdateOrganizationRequest",
|
|
62
|
+
"UpdateOrganizationResponse",
|
|
63
|
+
]
|