Debian Codegraph @

src/anthropic/resources/beta/agents/agents.py

raw
1 from __future__ import annotations
2
3 from typing import Dict, List, Union, Iterable, Optional
4 from datetime import datetime
5 from itertools import chain
6
7 import httpx2
8
9 from .versions import (
10 Versions,
11 AsyncVersions,
12 VersionsWithRawResponse,
13 AsyncVersionsWithRawResponse,
14 VersionsWithStreamingResponse,
15 AsyncVersionsWithStreamingResponse,
16 )
17 from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
18 from ...._utils import is_given, path_template, strip_not_given
19 from ...._compat import cached_property
20 from ...._resource import SyncAPIResource, AsyncAPIResource
21 from ...._response import (
22 to_raw_response_wrapper,
23 to_streamed_response_wrapper,
24 async_to_raw_response_wrapper,
25 async_to_streamed_response_wrapper,
26 )
27 from ....pagination import SyncPageCursor, AsyncPageCursor
28 from ....types.beta import (
29 BetaManagedAgentsMultiagentParams,
30 agent_create_params,
31 agent_update_params,
32 )
33 from ...._base_client import AsyncPaginator, make_request_options
34 from ....types.anthropic_beta_param import AnthropicBetaParam
35 from ....types.beta.beta_managed_agents_agent import BetaManagedAgentsAgent
36 from ....types.beta.beta_managed_agents_skill_params import BetaManagedAgentsSkillParams
37 from ....types.beta.beta_managed_agents_multiagent_params import BetaManagedAgentsMultiagentParams
38 from ....types.beta.beta_managed_agents_url_mcp_server_params import BetaManagedAgentsURLMCPServerParams
39
40 __all__ = ["Agents", "AsyncAgents"]
41
42
43 class Agents(SyncAPIResource):
44 @cached_property
45 def versions(self) -> Versions:
46 return Versions(self._client)
47
48 @cached_property
49 def with_raw_response(self) -> AgentsWithRawResponse:
50 """
51 This property can be used as a prefix for any HTTP method call to return
52 the raw response object instead of the parsed content.
53
54 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
55 """
56 return AgentsWithRawResponse(self)
57
58 @cached_property
59 def with_streaming_response(self) -> AgentsWithStreamingResponse:
60 """
61 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
62
63 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
64 """
65 return AgentsWithStreamingResponse(self)
66
67 def create(
68 self,
69 *,
70 model: agent_create_params.Model,
71 name: str,
72 description: Optional[str] | Omit = omit,
73 mcp_servers: Iterable[BetaManagedAgentsURLMCPServerParams] | Omit = omit,
74 metadata: Dict[str, str] | Omit = omit,
75 multiagent: Optional[BetaManagedAgentsMultiagentParams] | Omit = omit,
76 skills: Iterable[BetaManagedAgentsSkillParams] | Omit = omit,
77 system: Optional[str] | Omit = omit,
78 tools: Iterable[agent_create_params.Tool] | Omit = omit,
79 betas: List[AnthropicBetaParam] | Omit = omit,
80 workspace_id: str | Omit = omit,
81 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
82 # The extra values given here take precedence over values defined on the client or passed to this method.
83 extra_headers: Headers | None = None,
84 extra_query: Query | None = None,
85 extra_body: Body | None = None,
86 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
87 ) -> BetaManagedAgentsAgent:
88 """Create Agent
89
90 Args:
91 model: Model identifier.
92
93 Accepts the
94 [model string](https://platform.claude.com/docs/en/about-claude/models/overview#latest-models-comparison),
95 e.g. `claude-opus-5`, or a `model_config` object for additional configuration
96 control
97
98 name: Human-readable name for the agent.
99
100 description: Description of what the agent does.
101
102 mcp_servers: MCP servers this agent connects to. Maximum 20. Names must be unique within the
103 array. Every server must be referenced by an `mcp_toolset` in `tools`;
104 unreferenced servers are rejected. See the
105 [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
106
107 metadata: Arbitrary key-value metadata. Maximum 16 pairs, keys up to 64 chars, values up
108 to 512 chars.
109
110 multiagent: A coordinator topology: the session's primary thread orchestrates work by
111 spawning session threads, each running an agent drawn from the `agents` roster.
112
113 skills: Skills available to the agent.
114
115 system: System prompt for the agent.
116
117 tools: Tool configurations available to the agent. Maximum of 128 tools across all
118 toolsets allowed.
119
120 betas: Optional header to specify the beta version(s) you want to use.
121
122 workspace_id: Optional header to select the Workspace for this request. The value is a
123 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
124
125 Only needed for credentials that can act on more than one Workspace. A
126 credential that belongs to a specific Workspace may omit it; if sent, it must
127 match that Workspace.
128
129 extra_headers: Send extra headers
130
131 extra_query: Add additional query parameters to the request
132
133 extra_body: Add additional JSON properties to the request
134
135 timeout: Override the client-level default timeout for this request, in seconds
136 """
137 extra_headers = {
138 **strip_not_given(
139 {
140 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
141 if is_given(betas)
142 else not_given,
143 "anthropic-workspace-id": workspace_id,
144 }
145 ),
146 **(extra_headers or {}),
147 }
148 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
149 return self._post(
150 "/v1/agents?beta=true",
151 body={
152 "model": model,
153 "name": name,
154 "description": description,
155 "mcp_servers": mcp_servers,
156 "metadata": metadata,
157 "multiagent": multiagent,
158 "skills": skills,
159 "system": system,
160 "tools": tools,
161 },
162 options=make_request_options(
163 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
164 ),
165 cast_to=BetaManagedAgentsAgent,
166 )
167
168 def retrieve(
169 self,
170 agent_id: str,
171 *,
172 version: int | Omit = omit,
173 betas: List[AnthropicBetaParam] | Omit = omit,
174 workspace_id: str | Omit = omit,
175 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
176 # The extra values given here take precedence over values defined on the client or passed to this method.
177 extra_headers: Headers | None = None,
178 extra_query: Query | None = None,
179 extra_body: Body | None = None,
180 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
181 ) -> BetaManagedAgentsAgent:
182 """
183 Get Agent
184
185 Args:
186 agent_id: Unique identifier of the agent to retrieve.
187
188 version: Agent version. Omit for the most recent version. Must be at least 1 if
189 specified.
190
191 betas: Optional header to specify the beta version(s) you want to use.
192
193 workspace_id: Optional header to select the Workspace for this request. The value is a
194 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
195
196 Only needed for credentials that can act on more than one Workspace. A
197 credential that belongs to a specific Workspace may omit it; if sent, it must
198 match that Workspace.
199
200 extra_headers: Send extra headers
201
202 extra_query: Add additional query parameters to the request
203
204 extra_body: Add additional JSON properties to the request
205
206 timeout: Override the client-level default timeout for this request, in seconds
207 """
208 if not agent_id:
209 raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
210 extra_headers = {
211 **strip_not_given(
212 {
213 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
214 if is_given(betas)
215 else not_given,
216 "anthropic-workspace-id": workspace_id,
217 }
218 ),
219 **(extra_headers or {}),
220 }
221 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
222 return self._get(
223 path_template("/v1/agents/{agent_id}?beta=true", agent_id=agent_id),
224 options=make_request_options(
225 extra_headers=extra_headers,
226 extra_query=extra_query,
227 extra_body=extra_body,
228 timeout=timeout,
229 query={"version": version},
230 ),
231 cast_to=BetaManagedAgentsAgent,
232 )
233
234 def update(
235 self,
236 agent_id: str,
237 *,
238 description: Optional[str] | Omit = omit,
239 mcp_servers: Optional[Iterable[BetaManagedAgentsURLMCPServerParams]] | Omit = omit,
240 metadata: Optional[Dict[str, Optional[str]]] | Omit = omit,
241 model: agent_update_params.Model | Omit = omit,
242 multiagent: Optional[BetaManagedAgentsMultiagentParams] | Omit = omit,
243 name: str | Omit = omit,
244 skills: Optional[Iterable[BetaManagedAgentsSkillParams]] | Omit = omit,
245 system: Optional[str] | Omit = omit,
246 tools: Optional[Iterable[agent_update_params.Tool]] | Omit = omit,
247 version: int | Omit = omit,
248 betas: List[AnthropicBetaParam] | Omit = omit,
249 workspace_id: str | Omit = omit,
250 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
251 # The extra values given here take precedence over values defined on the client or passed to this method.
252 extra_headers: Headers | None = None,
253 extra_query: Query | None = None,
254 extra_body: Body | None = None,
255 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
256 ) -> BetaManagedAgentsAgent:
257 """
258 Update Agent
259
260 Args:
261 agent_id: Unique identifier of the agent to update.
262
263 description: Description. Omit to preserve; send empty string or null to clear.
264
265 mcp_servers: MCP servers. Full replacement. Omit to preserve; send empty array or `null` to
266 clear. Names must be unique. Maximum 20. Every server must be referenced by an
267 `mcp_toolset` in the agent's resulting `tools`; unreferenced servers are
268 rejected. See the
269 [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
270
271 metadata: Metadata patch. Set a key to a string to upsert it, or to null to delete it.
272 Omit the field to preserve. The stored bag is limited to 16 keys (up to 64 chars
273 each) with values up to 512 chars.
274
275 model: Model identifier. Accepts the
276 [model string](https://platform.claude.com/docs/en/about-claude/models/overview#latest-models-comparison),
277 e.g. `claude-opus-5`, or a `model_config` object for additional configuration
278 control. Omit to preserve. Cannot be cleared.
279
280 multiagent: A coordinator topology: the session's primary thread orchestrates work by
281 spawning session threads, each running an agent drawn from the `agents` roster.
282
283 name: Human-readable name. Must be non-empty. Omit to preserve. Cannot be cleared.
284
285 skills: Skills. Full replacement. Omit to preserve; send empty array or null to clear.
286
287 system: System prompt. Omit to preserve; send empty string or null to clear.
288
289 tools: Tool configurations available to the agent. Full replacement. Omit to preserve;
290 send empty array or null to clear. Maximum of 128 tools across all toolsets
291 allowed.
292
293 version: The agent's current version, used to prevent concurrent overwrites. Obtain this
294 value from a create or retrieve response. Must be at least 1 if specified. When
295 supplied, the request fails if it does not match the server's current version;
296 omit to apply the update unconditionally.
297
298 betas: Optional header to specify the beta version(s) you want to use.
299
300 workspace_id: Optional header to select the Workspace for this request. The value is a
301 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
302
303 Only needed for credentials that can act on more than one Workspace. A
304 credential that belongs to a specific Workspace may omit it; if sent, it must
305 match that Workspace.
306
307 extra_headers: Send extra headers
308
309 extra_query: Add additional query parameters to the request
310
311 extra_body: Add additional JSON properties to the request
312
313 timeout: Override the client-level default timeout for this request, in seconds
314 """
315 if not agent_id:
316 raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
317 extra_headers = {
318 **strip_not_given(
319 {
320 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
321 if is_given(betas)
322 else not_given,
323 "anthropic-workspace-id": workspace_id,
324 }
325 ),
326 **(extra_headers or {}),
327 }
328 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
329 return self._post(
330 path_template("/v1/agents/{agent_id}?beta=true", agent_id=agent_id),
331 body={
332 "description": description,
333 "mcp_servers": mcp_servers,
334 "metadata": metadata,
335 "model": model,
336 "multiagent": multiagent,
337 "name": name,
338 "skills": skills,
339 "system": system,
340 "tools": tools,
341 "version": version,
342 },
343 options=make_request_options(
344 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
345 ),
346 cast_to=BetaManagedAgentsAgent,
347 )
348
349 def list(
350 self,
351 *,
352 created_at_gte: Union[str, datetime] | Omit = omit,
353 created_at_lte: Union[str, datetime] | Omit = omit,
354 include_archived: bool | Omit = omit,
355 limit: int | Omit = omit,
356 page: str | Omit = omit,
357 betas: List[AnthropicBetaParam] | Omit = omit,
358 workspace_id: str | Omit = omit,
359 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
360 # The extra values given here take precedence over values defined on the client or passed to this method.
361 extra_headers: Headers | None = None,
362 extra_query: Query | None = None,
363 extra_body: Body | None = None,
364 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
365 ) -> SyncPageCursor[BetaManagedAgentsAgent]:
366 """
367 List Agents
368
369 Args:
370 created_at_gte: Return agents created at or after this time (inclusive).
371
372 created_at_lte: Return agents created at or before this time (inclusive).
373
374 include_archived: Include archived agents in results. Defaults to false.
375
376 limit: Maximum results per page. Default 20, maximum 100.
377
378 page: Opaque pagination cursor from a previous response.
379
380 betas: Optional header to specify the beta version(s) you want to use.
381
382 workspace_id: Optional header to select the Workspace for this request. The value is a
383 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
384
385 Only needed for credentials that can act on more than one Workspace. A
386 credential that belongs to a specific Workspace may omit it; if sent, it must
387 match that Workspace.
388
389 extra_headers: Send extra headers
390
391 extra_query: Add additional query parameters to the request
392
393 extra_body: Add additional JSON properties to the request
394
395 timeout: Override the client-level default timeout for this request, in seconds
396 """
397 extra_headers = {
398 **strip_not_given(
399 {
400 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
401 if is_given(betas)
402 else not_given,
403 "anthropic-workspace-id": workspace_id,
404 }
405 ),
406 **(extra_headers or {}),
407 }
408 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
409 return self._get_api_list(
410 "/v1/agents?beta=true",
411 page=SyncPageCursor[BetaManagedAgentsAgent],
412 options=make_request_options(
413 extra_headers=extra_headers,
414 extra_query=extra_query,
415 extra_body=extra_body,
416 timeout=timeout,
417 query={
418 "created_at[gte]": created_at_gte,
419 "created_at[lte]": created_at_lte,
420 "include_archived": include_archived,
421 "limit": limit,
422 "page": page,
423 },
424 ),
425 model=BetaManagedAgentsAgent,
426 )
427
428 def archive(
429 self,
430 agent_id: str,
431 *,
432 betas: List[AnthropicBetaParam] | Omit = omit,
433 workspace_id: str | Omit = omit,
434 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
435 # The extra values given here take precedence over values defined on the client or passed to this method.
436 extra_headers: Headers | None = None,
437 extra_query: Query | None = None,
438 extra_body: Body | None = None,
439 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
440 ) -> BetaManagedAgentsAgent:
441 """
442 Archive Agent
443
444 Args:
445 agent_id: Unique identifier of the agent to archive.
446
447 betas: Optional header to specify the beta version(s) you want to use.
448
449 workspace_id: Optional header to select the Workspace for this request. The value is a
450 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
451
452 Only needed for credentials that can act on more than one Workspace. A
453 credential that belongs to a specific Workspace may omit it; if sent, it must
454 match that Workspace.
455
456 extra_headers: Send extra headers
457
458 extra_query: Add additional query parameters to the request
459
460 extra_body: Add additional JSON properties to the request
461
462 timeout: Override the client-level default timeout for this request, in seconds
463 """
464 if not agent_id:
465 raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
466 extra_headers = {
467 **strip_not_given(
468 {
469 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
470 if is_given(betas)
471 else not_given,
472 "anthropic-workspace-id": workspace_id,
473 }
474 ),
475 **(extra_headers or {}),
476 }
477 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
478 return self._post(
479 path_template("/v1/agents/{agent_id}/archive?beta=true", agent_id=agent_id),
480 options=make_request_options(
481 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
482 ),
483 cast_to=BetaManagedAgentsAgent,
484 )
485
486
487 class AsyncAgents(AsyncAPIResource):
488 @cached_property
489 def versions(self) -> AsyncVersions:
490 return AsyncVersions(self._client)
491
492 @cached_property
493 def with_raw_response(self) -> AsyncAgentsWithRawResponse:
494 """
495 This property can be used as a prefix for any HTTP method call to return
496 the raw response object instead of the parsed content.
497
498 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
499 """
500 return AsyncAgentsWithRawResponse(self)
501
502 @cached_property
503 def with_streaming_response(self) -> AsyncAgentsWithStreamingResponse:
504 """
505 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
506
507 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
508 """
509 return AsyncAgentsWithStreamingResponse(self)
510
511 async def create(
512 self,
513 *,
514 model: agent_create_params.Model,
515 name: str,
516 description: Optional[str] | Omit = omit,
517 mcp_servers: Iterable[BetaManagedAgentsURLMCPServerParams] | Omit = omit,
518 metadata: Dict[str, str] | Omit = omit,
519 multiagent: Optional[BetaManagedAgentsMultiagentParams] | Omit = omit,
520 skills: Iterable[BetaManagedAgentsSkillParams] | Omit = omit,
521 system: Optional[str] | Omit = omit,
522 tools: Iterable[agent_create_params.Tool] | Omit = omit,
523 betas: List[AnthropicBetaParam] | Omit = omit,
524 workspace_id: str | Omit = omit,
525 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
526 # The extra values given here take precedence over values defined on the client or passed to this method.
527 extra_headers: Headers | None = None,
528 extra_query: Query | None = None,
529 extra_body: Body | None = None,
530 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
531 ) -> BetaManagedAgentsAgent:
532 """Create Agent
533
534 Args:
535 model: Model identifier.
536
537 Accepts the
538 [model string](https://platform.claude.com/docs/en/about-claude/models/overview#latest-models-comparison),
539 e.g. `claude-opus-5`, or a `model_config` object for additional configuration
540 control
541
542 name: Human-readable name for the agent.
543
544 description: Description of what the agent does.
545
546 mcp_servers: MCP servers this agent connects to. Maximum 20. Names must be unique within the
547 array. Every server must be referenced by an `mcp_toolset` in `tools`;
548 unreferenced servers are rejected. See the
549 [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
550
551 metadata: Arbitrary key-value metadata. Maximum 16 pairs, keys up to 64 chars, values up
552 to 512 chars.
553
554 multiagent: A coordinator topology: the session's primary thread orchestrates work by
555 spawning session threads, each running an agent drawn from the `agents` roster.
556
557 skills: Skills available to the agent.
558
559 system: System prompt for the agent.
560
561 tools: Tool configurations available to the agent. Maximum of 128 tools across all
562 toolsets allowed.
563
564 betas: Optional header to specify the beta version(s) you want to use.
565
566 workspace_id: Optional header to select the Workspace for this request. The value is a
567 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
568
569 Only needed for credentials that can act on more than one Workspace. A
570 credential that belongs to a specific Workspace may omit it; if sent, it must
571 match that Workspace.
572
573 extra_headers: Send extra headers
574
575 extra_query: Add additional query parameters to the request
576
577 extra_body: Add additional JSON properties to the request
578
579 timeout: Override the client-level default timeout for this request, in seconds
580 """
581 extra_headers = {
582 **strip_not_given(
583 {
584 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
585 if is_given(betas)
586 else not_given,
587 "anthropic-workspace-id": workspace_id,
588 }
589 ),
590 **(extra_headers or {}),
591 }
592 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
593 return await self._post(
594 "/v1/agents?beta=true",
595 body={
596 "model": model,
597 "name": name,
598 "description": description,
599 "mcp_servers": mcp_servers,
600 "metadata": metadata,
601 "multiagent": multiagent,
602 "skills": skills,
603 "system": system,
604 "tools": tools,
605 },
606 options=make_request_options(
607 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
608 ),
609 cast_to=BetaManagedAgentsAgent,
610 )
611
612 async def retrieve(
613 self,
614 agent_id: str,
615 *,
616 version: int | Omit = omit,
617 betas: List[AnthropicBetaParam] | Omit = omit,
618 workspace_id: str | Omit = omit,
619 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
620 # The extra values given here take precedence over values defined on the client or passed to this method.
621 extra_headers: Headers | None = None,
622 extra_query: Query | None = None,
623 extra_body: Body | None = None,
624 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
625 ) -> BetaManagedAgentsAgent:
626 """
627 Get Agent
628
629 Args:
630 agent_id: Unique identifier of the agent to retrieve.
631
632 version: Agent version. Omit for the most recent version. Must be at least 1 if
633 specified.
634
635 betas: Optional header to specify the beta version(s) you want to use.
636
637 workspace_id: Optional header to select the Workspace for this request. The value is a
638 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
639
640 Only needed for credentials that can act on more than one Workspace. A
641 credential that belongs to a specific Workspace may omit it; if sent, it must
642 match that Workspace.
643
644 extra_headers: Send extra headers
645
646 extra_query: Add additional query parameters to the request
647
648 extra_body: Add additional JSON properties to the request
649
650 timeout: Override the client-level default timeout for this request, in seconds
651 """
652 if not agent_id:
653 raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
654 extra_headers = {
655 **strip_not_given(
656 {
657 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
658 if is_given(betas)
659 else not_given,
660 "anthropic-workspace-id": workspace_id,
661 }
662 ),
663 **(extra_headers or {}),
664 }
665 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
666 return await self._get(
667 path_template("/v1/agents/{agent_id}?beta=true", agent_id=agent_id),
668 options=make_request_options(
669 extra_headers=extra_headers,
670 extra_query=extra_query,
671 extra_body=extra_body,
672 timeout=timeout,
673 query={"version": version},
674 ),
675 cast_to=BetaManagedAgentsAgent,
676 )
677
678 async def update(
679 self,
680 agent_id: str,
681 *,
682 description: Optional[str] | Omit = omit,
683 mcp_servers: Optional[Iterable[BetaManagedAgentsURLMCPServerParams]] | Omit = omit,
684 metadata: Optional[Dict[str, Optional[str]]] | Omit = omit,
685 model: agent_update_params.Model | Omit = omit,
686 multiagent: Optional[BetaManagedAgentsMultiagentParams] | Omit = omit,
687 name: str | Omit = omit,
688 skills: Optional[Iterable[BetaManagedAgentsSkillParams]] | Omit = omit,
689 system: Optional[str] | Omit = omit,
690 tools: Optional[Iterable[agent_update_params.Tool]] | Omit = omit,
691 version: int | Omit = omit,
692 betas: List[AnthropicBetaParam] | Omit = omit,
693 workspace_id: str | Omit = omit,
694 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
695 # The extra values given here take precedence over values defined on the client or passed to this method.
696 extra_headers: Headers | None = None,
697 extra_query: Query | None = None,
698 extra_body: Body | None = None,
699 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
700 ) -> BetaManagedAgentsAgent:
701 """
702 Update Agent
703
704 Args:
705 agent_id: Unique identifier of the agent to update.
706
707 description: Description. Omit to preserve; send empty string or null to clear.
708
709 mcp_servers: MCP servers. Full replacement. Omit to preserve; send empty array or `null` to
710 clear. Names must be unique. Maximum 20. Every server must be referenced by an
711 `mcp_toolset` in the agent's resulting `tools`; unreferenced servers are
712 rejected. See the
713 [MCP connector guide](https://platform.claude.com/docs/en/managed-agents/mcp-connector).
714
715 metadata: Metadata patch. Set a key to a string to upsert it, or to null to delete it.
716 Omit the field to preserve. The stored bag is limited to 16 keys (up to 64 chars
717 each) with values up to 512 chars.
718
719 model: Model identifier. Accepts the
720 [model string](https://platform.claude.com/docs/en/about-claude/models/overview#latest-models-comparison),
721 e.g. `claude-opus-5`, or a `model_config` object for additional configuration
722 control. Omit to preserve. Cannot be cleared.
723
724 multiagent: A coordinator topology: the session's primary thread orchestrates work by
725 spawning session threads, each running an agent drawn from the `agents` roster.
726
727 name: Human-readable name. Must be non-empty. Omit to preserve. Cannot be cleared.
728
729 skills: Skills. Full replacement. Omit to preserve; send empty array or null to clear.
730
731 system: System prompt. Omit to preserve; send empty string or null to clear.
732
733 tools: Tool configurations available to the agent. Full replacement. Omit to preserve;
734 send empty array or null to clear. Maximum of 128 tools across all toolsets
735 allowed.
736
737 version: The agent's current version, used to prevent concurrent overwrites. Obtain this
738 value from a create or retrieve response. Must be at least 1 if specified. When
739 supplied, the request fails if it does not match the server's current version;
740 omit to apply the update unconditionally.
741
742 betas: Optional header to specify the beta version(s) you want to use.
743
744 workspace_id: Optional header to select the Workspace for this request. The value is a
745 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
746
747 Only needed for credentials that can act on more than one Workspace. A
748 credential that belongs to a specific Workspace may omit it; if sent, it must
749 match that Workspace.
750
751 extra_headers: Send extra headers
752
753 extra_query: Add additional query parameters to the request
754
755 extra_body: Add additional JSON properties to the request
756
757 timeout: Override the client-level default timeout for this request, in seconds
758 """
759 if not agent_id:
760 raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
761 extra_headers = {
762 **strip_not_given(
763 {
764 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
765 if is_given(betas)
766 else not_given,
767 "anthropic-workspace-id": workspace_id,
768 }
769 ),
770 **(extra_headers or {}),
771 }
772 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
773 return await self._post(
774 path_template("/v1/agents/{agent_id}?beta=true", agent_id=agent_id),
775 body={
776 "description": description,
777 "mcp_servers": mcp_servers,
778 "metadata": metadata,
779 "model": model,
780 "multiagent": multiagent,
781 "name": name,
782 "skills": skills,
783 "system": system,
784 "tools": tools,
785 "version": version,
786 },
787 options=make_request_options(
788 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
789 ),
790 cast_to=BetaManagedAgentsAgent,
791 )
792
793 def list(
794 self,
795 *,
796 created_at_gte: Union[str, datetime] | Omit = omit,
797 created_at_lte: Union[str, datetime] | Omit = omit,
798 include_archived: bool | Omit = omit,
799 limit: int | Omit = omit,
800 page: str | Omit = omit,
801 betas: List[AnthropicBetaParam] | Omit = omit,
802 workspace_id: str | Omit = omit,
803 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
804 # The extra values given here take precedence over values defined on the client or passed to this method.
805 extra_headers: Headers | None = None,
806 extra_query: Query | None = None,
807 extra_body: Body | None = None,
808 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
809 ) -> AsyncPaginator[BetaManagedAgentsAgent, AsyncPageCursor[BetaManagedAgentsAgent]]:
810 """
811 List Agents
812
813 Args:
814 created_at_gte: Return agents created at or after this time (inclusive).
815
816 created_at_lte: Return agents created at or before this time (inclusive).
817
818 include_archived: Include archived agents in results. Defaults to false.
819
820 limit: Maximum results per page. Default 20, maximum 100.
821
822 page: Opaque pagination cursor from a previous response.
823
824 betas: Optional header to specify the beta version(s) you want to use.
825
826 workspace_id: Optional header to select the Workspace for this request. The value is a
827 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
828
829 Only needed for credentials that can act on more than one Workspace. A
830 credential that belongs to a specific Workspace may omit it; if sent, it must
831 match that Workspace.
832
833 extra_headers: Send extra headers
834
835 extra_query: Add additional query parameters to the request
836
837 extra_body: Add additional JSON properties to the request
838
839 timeout: Override the client-level default timeout for this request, in seconds
840 """
841 extra_headers = {
842 **strip_not_given(
843 {
844 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
845 if is_given(betas)
846 else not_given,
847 "anthropic-workspace-id": workspace_id,
848 }
849 ),
850 **(extra_headers or {}),
851 }
852 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
853 return self._get_api_list(
854 "/v1/agents?beta=true",
855 page=AsyncPageCursor[BetaManagedAgentsAgent],
856 options=make_request_options(
857 extra_headers=extra_headers,
858 extra_query=extra_query,
859 extra_body=extra_body,
860 timeout=timeout,
861 query={
862 "created_at[gte]": created_at_gte,
863 "created_at[lte]": created_at_lte,
864 "include_archived": include_archived,
865 "limit": limit,
866 "page": page,
867 },
868 ),
869 model=BetaManagedAgentsAgent,
870 )
871
872 async def archive(
873 self,
874 agent_id: str,
875 *,
876 betas: List[AnthropicBetaParam] | Omit = omit,
877 workspace_id: str | Omit = omit,
878 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
879 # The extra values given here take precedence over values defined on the client or passed to this method.
880 extra_headers: Headers | None = None,
881 extra_query: Query | None = None,
882 extra_body: Body | None = None,
883 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
884 ) -> BetaManagedAgentsAgent:
885 """
886 Archive Agent
887
888 Args:
889 agent_id: Unique identifier of the agent to archive.
890
891 betas: Optional header to specify the beta version(s) you want to use.
892
893 workspace_id: Optional header to select the Workspace for this request. The value is a
894 Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
895
896 Only needed for credentials that can act on more than one Workspace. A
897 credential that belongs to a specific Workspace may omit it; if sent, it must
898 match that Workspace.
899
900 extra_headers: Send extra headers
901
902 extra_query: Add additional query parameters to the request
903
904 extra_body: Add additional JSON properties to the request
905
906 timeout: Override the client-level default timeout for this request, in seconds
907 """
908 if not agent_id:
909 raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
910 extra_headers = {
911 **strip_not_given(
912 {
913 "anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"]))
914 if is_given(betas)
915 else not_given,
916 "anthropic-workspace-id": workspace_id,
917 }
918 ),
919 **(extra_headers or {}),
920 }
921 extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})}
922 return await self._post(
923 path_template("/v1/agents/{agent_id}/archive?beta=true", agent_id=agent_id),
924 options=make_request_options(
925 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
926 ),
927 cast_to=BetaManagedAgentsAgent,
928 )
929
930
931 class AgentsWithRawResponse:
932 def __init__(self, agents: Agents) -> None:
933 self._agents = agents
934
935 self.create = to_raw_response_wrapper(
936 agents.create,
937 )
938 self.retrieve = to_raw_response_wrapper(
939 agents.retrieve,
940 )
941 self.update = to_raw_response_wrapper(
942 agents.update,
943 )
944 self.list = to_raw_response_wrapper(
945 agents.list,
946 )
947 self.archive = to_raw_response_wrapper(
948 agents.archive,
949 )
950
951 @cached_property
952 def versions(self) -> VersionsWithRawResponse:
953 return VersionsWithRawResponse(self._agents.versions)
954
955
956 class AsyncAgentsWithRawResponse:
957 def __init__(self, agents: AsyncAgents) -> None:
958 self._agents = agents
959
960 self.create = async_to_raw_response_wrapper(
961 agents.create,
962 )
963 self.retrieve = async_to_raw_response_wrapper(
964 agents.retrieve,
965 )
966 self.update = async_to_raw_response_wrapper(
967 agents.update,
968 )
969 self.list = async_to_raw_response_wrapper(
970 agents.list,
971 )
972 self.archive = async_to_raw_response_wrapper(
973 agents.archive,
974 )
975
976 @cached_property
977 def versions(self) -> AsyncVersionsWithRawResponse:
978 return AsyncVersionsWithRawResponse(self._agents.versions)
979
980
981 class AgentsWithStreamingResponse:
982 def __init__(self, agents: Agents) -> None:
983 self._agents = agents
984
985 self.create = to_streamed_response_wrapper(
986 agents.create,
987 )
988 self.retrieve = to_streamed_response_wrapper(
989 agents.retrieve,
990 )
991 self.update = to_streamed_response_wrapper(
992 agents.update,
993 )
994 self.list = to_streamed_response_wrapper(
995 agents.list,
996 )
997 self.archive = to_streamed_response_wrapper(
998 agents.archive,
999 )
1000
1001 @cached_property
1002 def versions(self) -> VersionsWithStreamingResponse:
1003 return VersionsWithStreamingResponse(self._agents.versions)
1004
1005
1006 class AsyncAgentsWithStreamingResponse:
1007 def __init__(self, agents: AsyncAgents) -> None:
1008 self._agents = agents
1009
1010 self.create = async_to_streamed_response_wrapper(
1011 agents.create,
1012 )
1013 self.retrieve = async_to_streamed_response_wrapper(
1014 agents.retrieve,
1015 )
1016 self.update = async_to_streamed_response_wrapper(
1017 agents.update,
1018 )
1019 self.list = async_to_streamed_response_wrapper(
1020 agents.list,
1021 )
1022 self.archive = async_to_streamed_response_wrapper(
1023 agents.archive,
1024 )
1025
1026 @cached_property
1027 def versions(self) -> AsyncVersionsWithStreamingResponse:
1028 return AsyncVersionsWithStreamingResponse(self._agents.versions)