meshagent-api 0.54.2__tar.gz → 0.55.1__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 (82) hide show
  1. {meshagent_api-0.54.2/meshagent_api.egg-info → meshagent_api-0.55.1}/PKG-INFO +1 -1
  2. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/__init__.py +2 -0
  3. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/client.py +1 -0
  4. meshagent_api-0.55.1/meshagent/api/managed_agents.py +560 -0
  5. meshagent_api-0.55.1/meshagent/api/managed_agents_test.py +463 -0
  6. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/room_server_client.py +62 -2
  7. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/service_template_test.py +59 -0
  8. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/specs/service.py +12 -11
  9. meshagent_api-0.55.1/meshagent/api/sqlite_replication_test.py +38 -0
  10. meshagent_api-0.55.1/meshagent/api/version.py +1 -0
  11. {meshagent_api-0.54.2 → meshagent_api-0.55.1/meshagent_api.egg-info}/PKG-INFO +1 -1
  12. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent_api.egg-info/SOURCES.txt +1 -0
  13. meshagent_api-0.54.2/meshagent/api/managed_agents.py +0 -182
  14. meshagent_api-0.54.2/meshagent/api/managed_agents_test.py +0 -227
  15. meshagent_api-0.54.2/meshagent/api/version.py +0 -1
  16. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/LICENSE +0 -0
  17. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/MANIFEST.in +0 -0
  18. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/README.md +0 -0
  19. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/agent_content.py +0 -0
  20. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/aiohttp_redaction.py +0 -0
  21. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/chan.py +0 -0
  22. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/client_test.py +0 -0
  23. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/crdt.py +0 -0
  24. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/dataset_schema.py +0 -0
  25. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/entrypoint.js +0 -0
  26. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/error_codes.py +0 -0
  27. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/file_permissions.py +0 -0
  28. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/files.py +0 -0
  29. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/files_test.py +0 -0
  30. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/helpers.py +0 -0
  31. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/http.py +0 -0
  32. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/image_runtime.py +0 -0
  33. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/keys.py +0 -0
  34. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/llm_router_config.py +0 -0
  35. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/messaging.py +0 -0
  36. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/messaging_test.py +0 -0
  37. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/mime_types.py +0 -0
  38. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/mime_types_test.py +0 -0
  39. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/oauth.py +0 -0
  40. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/oauth_branding.py +0 -0
  41. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/oauth_scopes.py +0 -0
  42. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/oauth_scopes_test.py +0 -0
  43. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/participant.py +0 -0
  44. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/participant_token.py +0 -0
  45. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/participant_token_test.py +0 -0
  46. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/port_forward.py +0 -0
  47. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/port_forward_test.py +0 -0
  48. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/protocol.py +0 -0
  49. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/protocol_test.py +0 -0
  50. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/py.typed +0 -0
  51. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/reasoning_schema.py +0 -0
  52. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/registry_auth.py +0 -0
  53. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/room_ports.py +0 -0
  54. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/room_server_client_test.py +0 -0
  55. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/runtime.py +0 -0
  56. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/runtime_test.py +0 -0
  57. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/schema.py +0 -0
  58. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/schema_document.py +0 -0
  59. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/schema_document_test.py +0 -0
  60. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/schema_registry.py +0 -0
  61. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/schema_test.py +0 -0
  62. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/schema_util.py +0 -0
  63. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/service_spec_test.py +0 -0
  64. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/services.py +0 -0
  65. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/services_test.py +0 -0
  66. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/sql.py +0 -0
  67. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/sql_test.py +0 -0
  68. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/sqlite_batch_integration_test.py +0 -0
  69. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/sqlite_transfer.py +0 -0
  70. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/sqlite_transfer_test.py +0 -0
  71. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/storage_policy_test.py +0 -0
  72. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/token_test.py +0 -0
  73. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/urls.py +0 -0
  74. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/webhooks.py +0 -0
  75. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/webhooks_test.py +0 -0
  76. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/websocket_protocol.py +0 -0
  77. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent/api/websocket_protocol_test.py +0 -0
  78. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent_api.egg-info/dependency_links.txt +0 -0
  79. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent_api.egg-info/requires.txt +0 -0
  80. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/meshagent_api.egg-info/top_level.txt +0 -0
  81. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/pyproject.toml +0 -0
  82. {meshagent_api-0.54.2 → meshagent_api-0.55.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meshagent-api
3
- Version: 0.54.2
3
+ Version: 0.55.1
4
4
  Summary: Python Server API for Meshagent
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Documentation, https://docs.meshagent.com
@@ -38,6 +38,7 @@ from .room_server_client import (
38
38
  SqliteClient,
39
39
  SqliteDatabaseClient,
40
40
  SqliteDatabaseDetails,
41
+ SqliteReplicationSettings,
41
42
  SqliteSqlCommand,
42
43
  SqliteSqlExecution,
43
44
  SqliteSqlQuery,
@@ -205,6 +206,7 @@ __all__ = [
205
206
  "SqliteClient",
206
207
  "SqliteDatabaseClient",
207
208
  "SqliteDatabaseDetails",
209
+ "SqliteReplicationSettings",
208
210
  "SqliteSqlCommand",
209
211
  "SqliteSqlExecution",
210
212
  "SqliteSqlQuery",
@@ -132,6 +132,7 @@ class MeshagentDomains(BaseModel):
132
132
 
133
133
  class MeshagentDeploymentConfig(BaseModel):
134
134
  domains: MeshagentDomains
135
+ reserved_route_domains: list[str] = Field(default_factory=list)
135
136
  version: str | None = None
136
137
 
137
138
 
@@ -0,0 +1,560 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ from typing import Annotated, Any, Literal
5
+ from urllib.parse import urlsplit
6
+
7
+ import jsonschema
8
+ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
9
+
10
+
11
+ class AllowedModel(BaseModel):
12
+ provider: str
13
+ model: str
14
+
15
+
16
+ class AllowedOpenAIModel(AllowedModel):
17
+ provider: Literal["openai"] = "openai"
18
+ output_modalities: list[str] | None = None
19
+
20
+
21
+ class AllowedAnthropicModel(AllowedModel):
22
+ provider: Literal["anthropic"] = "anthropic"
23
+
24
+
25
+ class AllowedGrokModel(AllowedModel):
26
+ provider: Literal["grok"] = "grok"
27
+
28
+
29
+ ManagedAllowedModel = Annotated[
30
+ AllowedOpenAIModel | AllowedAnthropicModel | AllowedGrokModel,
31
+ Field(discriminator="provider"),
32
+ ]
33
+
34
+ ManagedAgentThreadIsolation = Literal["global", "participant"]
35
+ ManagedAgentLlmDelegation = Literal["required", "optional"]
36
+
37
+
38
+ class ManagedAgentRunAs(BaseModel):
39
+ model_config = ConfigDict(extra="forbid")
40
+
41
+ email: str = Field(
42
+ ..., description="the service account email this managed agent runs as"
43
+ )
44
+ scopes: list[str] = Field(
45
+ default_factory=lambda: ["secrets:proxy", "llm_proxy"],
46
+ description=(
47
+ "OAuth scopes to grant to the runtime service account token. "
48
+ "The project scope is always added by the server."
49
+ ),
50
+ )
51
+
52
+ @field_validator("email")
53
+ @classmethod
54
+ def validate_email(cls, value: str) -> str:
55
+ normalized = value.strip().lower()
56
+ if normalized == "":
57
+ raise ValueError("run_as.email must not be empty")
58
+ return normalized
59
+
60
+ @field_validator("scopes")
61
+ @classmethod
62
+ def validate_scopes(cls, value: list[str]) -> list[str]:
63
+ normalized_scopes: list[str] = []
64
+ seen: set[str] = set()
65
+ for scope in value:
66
+ normalized_scope = scope.strip()
67
+ if normalized_scope == "":
68
+ continue
69
+ if normalized_scope not in seen:
70
+ normalized_scopes.append(normalized_scope)
71
+ seen.add(normalized_scope)
72
+ return normalized_scopes
73
+
74
+
75
+ class ManagedAgentToolkit(BaseModel):
76
+ model_config = ConfigDict(extra="forbid")
77
+
78
+ type: str
79
+
80
+
81
+ class ManagedAgentWebSearch(ManagedAgentToolkit):
82
+ type: Literal["web_search"] = "web_search"
83
+ allowed_domains: list[str] | None = None
84
+ blocked_domains: list[str] | None = None
85
+
86
+
87
+ class ManagedAgentWebFetch(ManagedAgentToolkit):
88
+ type: Literal["web_fetch"] = "web_fetch"
89
+
90
+
91
+ class ManagedAgentImageGeneration(ManagedAgentToolkit):
92
+ type: Literal["image_generation"] = "image_generation"
93
+ background: Literal["transparent", "opaque", "auto"] | None = None
94
+ input_image_mask_url: str | None = None
95
+ model: str | None = None
96
+ moderation: str | None = None
97
+ output_compression: int | None = None
98
+ output_format: Literal["png", "webp", "jpeg"] | None = None
99
+ partial_images: int | None = 1
100
+ quality: Literal["auto", "low", "medium", "high"] | None = None
101
+ size: Literal["1024x1024", "1024x1536", "1536x1024", "auto"] | None = None
102
+
103
+
104
+ class ManagedAgentMCPHeader(BaseModel):
105
+ model_config = ConfigDict(extra="forbid")
106
+
107
+ name: str
108
+ value: str
109
+
110
+
111
+ class ManagedAgentMCPServer(BaseModel):
112
+ model_config = ConfigDict(extra="forbid")
113
+
114
+ server_label: str
115
+ server_url: str
116
+ allowed_tools: list[str] | None = None
117
+ headers: list[ManagedAgentMCPHeader] | None = None
118
+ require_approval: Literal["always", "never"] | None = None
119
+ always_require_approval: list[str] | None = None
120
+ never_require_approval: list[str] | None = None
121
+ openai_connector_id: str | None = None
122
+ use_proxy_secret: str | None = None
123
+
124
+ @model_validator(mode="before")
125
+ @classmethod
126
+ def drop_legacy_authorization(cls, value: object) -> object:
127
+ if isinstance(value, dict) and "authorization" in value:
128
+ migrated = dict(value)
129
+ migrated.pop("authorization", None)
130
+ return migrated
131
+ return value
132
+
133
+
134
+ class ManagedAgentMCPToolkit(ManagedAgentToolkit):
135
+ type: Literal["mcp"] = "mcp"
136
+ servers: list[ManagedAgentMCPServer]
137
+
138
+
139
+ ManagedToolkit = Annotated[
140
+ ManagedAgentWebSearch
141
+ | ManagedAgentWebFetch
142
+ | ManagedAgentImageGeneration
143
+ | ManagedAgentMCPToolkit,
144
+ Field(discriminator="type"),
145
+ ]
146
+
147
+
148
+ class ManagedAgentMetadata(BaseModel):
149
+ model_config = ConfigDict(extra="forbid")
150
+ name: str
151
+ annotations: dict[str, str] = Field(default_factory=dict)
152
+
153
+ @field_validator("name")
154
+ @classmethod
155
+ def normalize_name(cls, value: str) -> str:
156
+ return value.strip().lower()
157
+
158
+
159
+ def _validate_python_tool_schema(schema: dict[str, Any], path: str = "input_schema"):
160
+ allowed = {
161
+ "type",
162
+ "title",
163
+ "description",
164
+ "properties",
165
+ "required",
166
+ "additionalProperties",
167
+ "items",
168
+ "$defs",
169
+ "$ref",
170
+ "anyOf",
171
+ "enum",
172
+ "const",
173
+ "format",
174
+ "pattern",
175
+ "minimum",
176
+ "maximum",
177
+ "exclusiveMinimum",
178
+ "exclusiveMaximum",
179
+ "multipleOf",
180
+ "minItems",
181
+ "maxItems",
182
+ }
183
+ if not isinstance(schema, dict):
184
+ raise ValueError(f"{path}: expected a schema object")
185
+ if not any(key in schema for key in ("type", "$ref", "anyOf")):
186
+ raise ValueError(f"{path}: schema requires type, $ref, or anyOf")
187
+ for key in schema:
188
+ if key not in allowed:
189
+ raise ValueError(f"{path}.{key}: unsupported strict-schema keyword")
190
+ if "$ref" in schema and (
191
+ not isinstance(schema["$ref"], str) or not schema["$ref"].startswith("#/$defs/")
192
+ ):
193
+ raise ValueError(f"{path}: only local $defs references are supported")
194
+ schema_type = schema.get("type")
195
+ if schema_type == "object" or (
196
+ isinstance(schema_type, list) and "object" in schema_type
197
+ ):
198
+ properties = schema.get("properties")
199
+ required = schema.get("required")
200
+ if schema.get("additionalProperties") is not False:
201
+ raise ValueError(f"{path}.additionalProperties must be false")
202
+ if not isinstance(properties, dict) or not isinstance(required, list):
203
+ raise ValueError(f"{path}: properties and required are required")
204
+ if not all(isinstance(name, str) for name in required) or (
205
+ len(set(required)) != len(required) or set(required) != set(properties)
206
+ ):
207
+ raise ValueError(f"{path}.required must list every property exactly once")
208
+ for key in ("properties", "$defs"):
209
+ children = schema.get(key, {})
210
+ if isinstance(children, dict):
211
+ for name, child in children.items():
212
+ _validate_python_tool_schema(child, f"{path}.{key}.{name}")
213
+ if "items" in schema:
214
+ _validate_python_tool_schema(schema["items"], f"{path}.items")
215
+ for index, child in enumerate(schema.get("anyOf", [])):
216
+ _validate_python_tool_schema(child, f"{path}.anyOf[{index}]")
217
+
218
+
219
+ class ManagedAgentPythonTool(BaseModel):
220
+ model_config = ConfigDict(extra="forbid")
221
+
222
+ type: Literal["python"] = "python"
223
+ name: str = Field(pattern=r"^[A-Za-z_][A-Za-z0-9_]*$", max_length=64)
224
+ description: str = ""
225
+ input_schema: dict[str, Any]
226
+ source: str = Field(min_length=1, max_length=65536)
227
+ entrypoint: str | None = Field(
228
+ default=None, pattern=r"^[A-Za-z_][A-Za-z0-9_]*$", max_length=64
229
+ )
230
+
231
+ @field_validator("source")
232
+ @classmethod
233
+ def validate_source(cls, value: str) -> str:
234
+ if len(value.encode("utf-8")) > 65536:
235
+ raise ValueError("source must contain at most 65536 bytes")
236
+ return value
237
+
238
+ @field_validator("input_schema")
239
+ @classmethod
240
+ def validate_input_schema(cls, value: dict[str, Any]) -> dict[str, Any]:
241
+ if "anyOf" in value:
242
+ raise ValueError("root anyOf is not supported")
243
+ if value.get("type") != "object":
244
+ raise ValueError("input_schema must be an object schema")
245
+ try:
246
+ jsonschema.Draft202012Validator.check_schema(value)
247
+ except jsonschema.SchemaError as error:
248
+ raise ValueError(f"invalid input_schema: {error.message}") from error
249
+ _validate_python_tool_schema(value)
250
+ return value
251
+
252
+
253
+ class ManagedAgentSecretHeader(BaseModel):
254
+ model_config = ConfigDict(extra="forbid")
255
+
256
+ id: str
257
+
258
+ @field_validator("id")
259
+ @classmethod
260
+ def validate_id(cls, value: str) -> str:
261
+ if not value.strip():
262
+ raise ValueError("secret.id must not be empty")
263
+ return value
264
+
265
+
266
+ class ManagedAgentConnectionHeader(BaseModel):
267
+ model_config = ConfigDict(extra="forbid")
268
+
269
+ name: str
270
+ value: str | None = None
271
+ secret: ManagedAgentSecretHeader | None = None
272
+ prefix: str = ""
273
+
274
+ @field_validator("prefix")
275
+ @classmethod
276
+ def validate_prefix(cls, value: str) -> str:
277
+ if any(ord(character) < 32 or ord(character) == 127 for character in value):
278
+ raise ValueError("prefix must not contain control characters")
279
+ return value
280
+
281
+ @model_validator(mode="after")
282
+ def validate_source(self) -> ManagedAgentConnectionHeader:
283
+ if (self.value is None) == (self.secret is None):
284
+ raise ValueError("header requires exactly one of value or secret")
285
+ if self.value is not None and self.prefix:
286
+ raise ValueError("prefix requires secret")
287
+ return self
288
+
289
+
290
+ class ManagedAgentHttpConnection(BaseModel):
291
+ model_config = ConfigDict(extra="forbid")
292
+
293
+ base_url: str
294
+ use_proxy_secret: str | None = None
295
+ headers: list[ManagedAgentConnectionHeader] = Field(default_factory=list)
296
+
297
+ @model_validator(mode="after")
298
+ def validate_headers(self) -> ManagedAgentHttpConnection:
299
+ reserved = {
300
+ "host",
301
+ "content-length",
302
+ "transfer-encoding",
303
+ "connection",
304
+ "proxy-authorization",
305
+ "proxy-authenticate",
306
+ "proxy-connection",
307
+ "keep-alive",
308
+ "upgrade",
309
+ "te",
310
+ "trailer",
311
+ "cookie",
312
+ "set-cookie",
313
+ "sec-websocket-accept",
314
+ "sec-websocket-extensions",
315
+ "sec-websocket-key",
316
+ "sec-websocket-protocol",
317
+ "sec-websocket-version",
318
+ }
319
+ names: set[str] = set()
320
+ secret_count = int(self.use_proxy_secret is not None)
321
+ for header in self.headers:
322
+ name = header.name
323
+ normalized = name.lower()
324
+ if (
325
+ re.fullmatch(r"[!#$%&'*+.^_`|~0-9A-Za-z-]+", name) is None
326
+ or normalized in reserved
327
+ or normalized in names
328
+ ):
329
+ raise ValueError(f"header {name} is not allowed")
330
+ names.add(normalized)
331
+ if header.value is not None:
332
+ if any(
333
+ ord(character) < 32 or ord(character) == 127
334
+ for character in header.value
335
+ ):
336
+ raise ValueError(f"header {name} has an invalid value")
337
+ else:
338
+ secret_count += 1
339
+ if self.use_proxy_secret is not None and "authorization" in names:
340
+ raise ValueError("Authorization conflicts with use_proxy_secret")
341
+ if secret_count > 16:
342
+ raise ValueError("a connection supports at most 16 secret headers")
343
+ if secret_count and any(
344
+ header.name.lower() == "authorization" and header.value is not None
345
+ for header in self.headers
346
+ ):
347
+ raise ValueError(
348
+ "literal Authorization cannot be combined with secret headers"
349
+ )
350
+ return self
351
+
352
+ @field_validator("base_url")
353
+ @classmethod
354
+ def validate_base_url(cls, value: str) -> str:
355
+ parsed = urlsplit(value)
356
+ if (
357
+ parsed.scheme not in ("http", "https")
358
+ or not parsed.hostname
359
+ or parsed.username is not None
360
+ or parsed.password is not None
361
+ or parsed.fragment
362
+ ):
363
+ raise ValueError("URL must be HTTP(S), without credentials or fragment")
364
+ return value
365
+
366
+ @field_validator("use_proxy_secret")
367
+ @classmethod
368
+ def validate_proxy_secret(cls, value: str | None) -> str | None:
369
+ if value is not None and not value.strip():
370
+ raise ValueError("use_proxy_secret must not be empty")
371
+ return value
372
+
373
+
374
+ class ManagedAgentEnvironmentVariable(BaseModel):
375
+ model_config = ConfigDict(extra="forbid")
376
+
377
+ name: str = Field(pattern=r"^[A-Za-z_][A-Za-z0-9_]*$", max_length=128)
378
+ value: str | None = None
379
+ secret: ManagedAgentSecretHeader | None = None
380
+
381
+ @model_validator(mode="after")
382
+ def validate_source(self) -> ManagedAgentEnvironmentVariable:
383
+ if (self.value is None) == (self.secret is None):
384
+ raise ValueError(
385
+ "environment entry requires exactly one of value or secret"
386
+ )
387
+ return self
388
+
389
+
390
+ class ManagedAgentDecisionCheck(BaseModel):
391
+ model_config = ConfigDict(extra="forbid")
392
+ type: Literal["decision"] = "decision"
393
+ model: str = Field(pattern=r"^openai/[^/\s]+$")
394
+ instructions: str = Field(min_length=1, max_length=16384)
395
+ minimum_allow_probability: float = Field(ge=0, le=1, allow_inf_nan=False)
396
+
397
+ @field_validator("instructions")
398
+ @classmethod
399
+ def validate_instructions(cls, value: str) -> str:
400
+ if not value.strip() or len(value.encode("utf-8")) > 16384:
401
+ raise ValueError(
402
+ "guardrail instructions must contain 1 to 16384 UTF-8 bytes"
403
+ )
404
+ return value
405
+
406
+
407
+ class ManagedAgentGuardrailFailure(BaseModel):
408
+ model_config = ConfigDict(extra="forbid")
409
+ action: Literal["block", "deny", "replace", "pass", "fail"] = "block"
410
+ message: str | None = None
411
+
412
+ @model_validator(mode="after")
413
+ def validate_replacement(self):
414
+ if self.action == "replace" and not (self.message or "").strip():
415
+ raise ValueError("replacement guardrails require a message")
416
+ return self
417
+
418
+
419
+ class ManagedAgentGuardrail(BaseModel):
420
+ model_config = ConfigDict(extra="forbid")
421
+ name: str = Field(min_length=1)
422
+ check: ManagedAgentDecisionCheck
423
+ on_reject: ManagedAgentGuardrailFailure = Field(
424
+ default_factory=ManagedAgentGuardrailFailure
425
+ )
426
+ on_error: ManagedAgentGuardrailFailure = Field(
427
+ default_factory=lambda: ManagedAgentGuardrailFailure(action="fail")
428
+ )
429
+ max_retries: int = Field(default=2, ge=0, le=3, strict=True)
430
+
431
+
432
+ class ManagedAgentToolMatch(BaseModel):
433
+ model_config = ConfigDict(extra="forbid")
434
+ names: list[str] = Field(min_length=1)
435
+
436
+
437
+ class ManagedAgentToolGuardrails(BaseModel):
438
+ model_config = ConfigDict(extra="forbid")
439
+ name: str = Field(min_length=1)
440
+ match: ManagedAgentToolMatch
441
+ input: list[ManagedAgentGuardrail] = Field(default_factory=list)
442
+ output: list[ManagedAgentGuardrail] = Field(default_factory=list)
443
+
444
+
445
+ class ManagedAgentOutputGuardrails(BaseModel):
446
+ model_config = ConfigDict(extra="forbid")
447
+ checks: list[ManagedAgentGuardrail] = Field(default_factory=list)
448
+
449
+
450
+ class ManagedAgentGuardrails(BaseModel):
451
+ model_config = ConfigDict(extra="forbid")
452
+ input: list[ManagedAgentGuardrail] = Field(default_factory=list)
453
+ tools: list[ManagedAgentToolGuardrails] = Field(default_factory=list)
454
+ output: ManagedAgentOutputGuardrails = Field(
455
+ default_factory=ManagedAgentOutputGuardrails
456
+ )
457
+
458
+ @model_validator(mode="after")
459
+ def validate_rules(self):
460
+ names: set[str] = set()
461
+ rules = [*self.input, *self.output.checks]
462
+ for tool in self.tools:
463
+ if not tool.name.strip() or any(
464
+ not name.strip() for name in tool.match.names
465
+ ):
466
+ raise ValueError("tool guardrails require nonempty names")
467
+ rules.extend(tool.input)
468
+ rules.extend(tool.output)
469
+ if len(rules) > 32:
470
+ raise ValueError("at most 32 guardrail checks are allowed")
471
+ boundaries = [
472
+ (self.input, {"block"}),
473
+ (self.output.checks, {"block", "replace"}),
474
+ ]
475
+ for tool in self.tools:
476
+ boundaries.extend(
477
+ [
478
+ (tool.input, {"block", "deny"}),
479
+ (tool.output, {"block", "deny", "replace"}),
480
+ ]
481
+ )
482
+ for checks, allowed in boundaries:
483
+ for rule in checks:
484
+ if (
485
+ rule.on_reject.action not in allowed
486
+ or rule.on_error.action not in allowed | {"pass", "fail"}
487
+ ):
488
+ raise ValueError(
489
+ "guardrail action is not supported at this boundary"
490
+ )
491
+ for rule in rules:
492
+ if (
493
+ not rule.name
494
+ or len(rule.name) > 64
495
+ or any(
496
+ not (char.isascii() and (char.isalnum() or char in "_.-"))
497
+ for char in rule.name
498
+ )
499
+ or rule.name in names
500
+ ):
501
+ raise ValueError("guardrail names must be nonempty and unique")
502
+ names.add(rule.name)
503
+ if not rule.check.instructions.strip():
504
+ raise ValueError("guardrail instructions must not be empty")
505
+ return self
506
+
507
+
508
+ class ManagedAgentSpec(BaseModel):
509
+ model_config = ConfigDict(extra="forbid")
510
+ version: Literal["v1"] = "v1"
511
+ kind: Literal["ManagedAgent"] = "ManagedAgent"
512
+ id: str | None = None
513
+ metadata: ManagedAgentMetadata
514
+ allowed_models: list[ManagedAllowedModel]
515
+ guardrails: ManagedAgentGuardrails | None = None
516
+ run_as: ManagedAgentRunAs | None = None
517
+ llm_delegation: ManagedAgentLlmDelegation = "optional"
518
+ thread_isolation: ManagedAgentThreadIsolation = "global"
519
+ instructions: str | None = None
520
+ toolkits: list[ManagedToolkit] | None = None
521
+ tools: list[ManagedAgentPythonTool] = Field(default_factory=list)
522
+ connections: dict[str, ManagedAgentHttpConnection] = Field(default_factory=dict)
523
+ environment: list[ManagedAgentEnvironmentVariable] = Field(default_factory=list)
524
+ output_modalities: list[str] | None = None
525
+ store: bool = True
526
+
527
+ @field_validator("tools")
528
+ @classmethod
529
+ def validate_tool_names(cls, value: list[ManagedAgentPythonTool]):
530
+ names = [tool.name for tool in value]
531
+ if len(set(names)) != len(names):
532
+ raise ValueError("duplicate Python tool name")
533
+ return value
534
+
535
+ @model_validator(mode="after")
536
+ def validate_environment(self) -> ManagedAgentSpec:
537
+ names = [entry.name for entry in self.environment]
538
+ if len(names) != len(set(names)):
539
+ raise ValueError("duplicate environment variable name")
540
+ if len(names) > 64:
541
+ raise ValueError("at most 64 environment variables are supported")
542
+ if any(entry.secret is not None for entry in self.environment):
543
+ if self.run_as is None or "secrets:read" not in self.run_as.scopes:
544
+ raise ValueError(
545
+ "secret environment variables require run_as with secrets:read"
546
+ )
547
+ return self
548
+
549
+ @model_validator(mode="before")
550
+ @classmethod
551
+ def migrate_legacy_name(cls, value: object) -> object:
552
+ if isinstance(value, dict) and "name" in value and "metadata" not in value:
553
+ migrated = dict(value)
554
+ migrated["metadata"] = {"name": migrated.pop("name")}
555
+ return migrated
556
+ return value
557
+
558
+ @property
559
+ def name(self) -> str:
560
+ return self.metadata.name