Skip to content

Commit d37ad2a

Browse files
committed
cp
1 parent 1febe28 commit d37ad2a

6 files changed

Lines changed: 268 additions & 1 deletion

File tree

src/runloop_api_client/sdk/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55

66
from __future__ import annotations
77

8-
from .sync import DevboxOps, RunloopSDK, SnapshotOps, BlueprintOps, StorageObjectOps
8+
from .sync import DevboxOps, RunloopSDK, SnapshotOps, BlueprintOps, StorageObjectOps, AgentOps
99
from .async_ import (
1010
AsyncDevboxOps,
1111
AsyncRunloopSDK,
1212
AsyncSnapshotOps,
1313
AsyncBlueprintOps,
1414
AsyncStorageObjectOps,
15+
AsyncAgentOps,
1516
)
17+
from .agent import Agent
1618
from .devbox import Devbox
1719
from .snapshot import Snapshot
1820
from .blueprint import Blueprint
1921
from .execution import Execution
22+
from .async_agent import AsyncAgent
2023
from .async_devbox import AsyncDevbox
2124
from .async_snapshot import AsyncSnapshot
2225
from .storage_object import StorageObject
@@ -31,6 +34,8 @@
3134
"RunloopSDK",
3235
"AsyncRunloopSDK",
3336
# Management interfaces
37+
"AgentOps",
38+
"AsyncAgentOps",
3439
"DevboxOps",
3540
"AsyncDevboxOps",
3641
"BlueprintOps",
@@ -40,6 +45,8 @@
4045
"StorageObjectOps",
4146
"AsyncStorageObjectOps",
4247
# Resource classes
48+
"Agent",
49+
"AsyncAgent",
4350
"Devbox",
4451
"AsyncDevbox",
4552
"Execution",

src/runloop_api_client/sdk/_types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from .._types import Body, Query, Headers, Timeout, NotGiven
77
from ..lib.polling import PollingConfig
8+
from ..types.agent_list_params import AgentListParams
9+
from ..types.agent_create_params import AgentCreateParams
810
from ..types.devbox_list_params import DevboxListParams
911
from ..types.object_list_params import ObjectListParams
1012
from ..types.devbox_create_params import DevboxCreateParams, DevboxBaseCreateParams
@@ -142,3 +144,11 @@ class SDKObjectCreateParams(ObjectCreateParams, LongRequestOptions):
142144

143145
class SDKObjectDownloadParams(ObjectDownloadParams, RequestOptions):
144146
pass
147+
148+
149+
class SDKAgentCreateParams(AgentCreateParams, LongRequestOptions):
150+
pass
151+
152+
153+
class SDKAgentListParams(AgentListParams, RequestOptions):
154+
pass
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Agent resource class for synchronous operations."""
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Unpack, override
6+
7+
from ._types import (
8+
RequestOptions,
9+
)
10+
from .._client import Runloop
11+
from ..types.agent_view import AgentView
12+
13+
14+
class Agent:
15+
"""Wrapper around synchronous agent operations."""
16+
17+
def __init__(
18+
self,
19+
client: Runloop,
20+
agent_id: str,
21+
) -> None:
22+
"""Initialize the wrapper.
23+
24+
:param client: Generated Runloop client
25+
:type client: Runloop
26+
:param agent_id: Agent identifier returned by the API
27+
:type agent_id: str
28+
"""
29+
self._client = client
30+
self._id = agent_id
31+
32+
@override
33+
def __repr__(self) -> str:
34+
return f"<Agent id={self._id!r}>"
35+
36+
@property
37+
def id(self) -> str:
38+
"""Return the agent identifier.
39+
40+
:return: Unique agent ID
41+
:rtype: str
42+
"""
43+
return self._id
44+
45+
def get_info(
46+
self,
47+
**options: Unpack[RequestOptions],
48+
) -> AgentView:
49+
"""Retrieve the latest agent information.
50+
51+
:param options: Optional request configuration
52+
:return: Agent details
53+
:rtype: AgentView
54+
"""
55+
return self._client.agents.retrieve(
56+
self._id,
57+
**options,
58+
)

src/runloop_api_client/sdk/async_.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
from ._types import (
1212
LongRequestOptions,
13+
SDKAgentListParams,
1314
SDKDevboxListParams,
1415
SDKObjectListParams,
16+
SDKAgentCreateParams,
1517
SDKDevboxCreateParams,
1618
SDKObjectCreateParams,
1719
SDKBlueprintListParams,
@@ -22,6 +24,7 @@
2224
from .._types import Timeout, NotGiven, not_given
2325
from .._client import DEFAULT_MAX_RETRIES, AsyncRunloop
2426
from ._helpers import detect_content_type
27+
from .async_agent import AsyncAgent
2528
from .async_devbox import AsyncDevbox
2629
from .async_snapshot import AsyncSnapshot
2730
from .async_blueprint import AsyncBlueprint
@@ -415,6 +418,67 @@ async def upload_from_bytes(
415418
return obj
416419

417420

421+
class AsyncAgentOps:
422+
"""High-level async manager for creating and managing agents.
423+
424+
Accessed via ``runloop.agent`` from :class:`AsyncRunloopSDK`, provides
425+
coroutines to create, retrieve, and list agents.
426+
427+
Example:
428+
>>> runloop = AsyncRunloopSDK()
429+
>>> agent = await runloop.agent.create(name="my-agent")
430+
>>> agents = await runloop.agent.list(limit=10)
431+
"""
432+
433+
def __init__(self, client: AsyncRunloop) -> None:
434+
"""Initialize the manager.
435+
436+
:param client: Generated AsyncRunloop client to wrap
437+
:type client: AsyncRunloop
438+
"""
439+
self._client = client
440+
441+
async def create(
442+
self,
443+
**params: Unpack[SDKAgentCreateParams],
444+
) -> AsyncAgent:
445+
"""Create a new agent.
446+
447+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKAgentCreateParams` for available parameters
448+
:return: Wrapper bound to the newly created agent
449+
:rtype: AsyncAgent
450+
"""
451+
agent_view = await self._client.agents.create(
452+
**params,
453+
)
454+
return AsyncAgent(self._client, agent_view.id)
455+
456+
def from_id(self, agent_id: str) -> AsyncAgent:
457+
"""Attach to an existing agent by ID.
458+
459+
:param agent_id: Existing agent ID
460+
:type agent_id: str
461+
:return: Wrapper bound to the requested agent
462+
:rtype: AsyncAgent
463+
"""
464+
return AsyncAgent(self._client, agent_id)
465+
466+
async def list(
467+
self,
468+
**params: Unpack[SDKAgentListParams],
469+
) -> list[AsyncAgent]:
470+
"""List agents accessible to the caller.
471+
472+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKAgentListParams` for available parameters
473+
:return: Collection of agent wrappers
474+
:rtype: list[AsyncAgent]
475+
"""
476+
page = await self._client.agents.list(
477+
**params,
478+
)
479+
return [AsyncAgent(self._client, item.id) for item in page.agents]
480+
481+
418482
class AsyncRunloopSDK:
419483
"""High-level asynchronous entry point for the Runloop SDK.
420484
@@ -424,6 +488,7 @@ class AsyncRunloopSDK:
424488
425489
Attributes:
426490
api: Direct access to the generated async REST API client.
491+
agent: High-level async interface for agent management.
427492
devbox: High-level async interface for devbox management.
428493
blueprint: High-level async interface for blueprint management.
429494
snapshot: High-level async interface for snapshot management.
@@ -438,6 +503,7 @@ class AsyncRunloopSDK:
438503
"""
439504

440505
api: AsyncRunloop
506+
agent: AsyncAgentOps
441507
devbox: AsyncDevboxOps
442508
blueprint: AsyncBlueprintOps
443509
snapshot: AsyncSnapshotOps
@@ -481,6 +547,7 @@ def __init__(
481547
http_client=http_client,
482548
)
483549

550+
self.agent = AsyncAgentOps(self.api)
484551
self.devbox = AsyncDevboxOps(self.api)
485552
self.blueprint = AsyncBlueprintOps(self.api)
486553
self.snapshot = AsyncSnapshotOps(self.api)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Agent resource class for asynchronous operations."""
2+
3+
from __future__ import annotations
4+
5+
from typing_extensions import Unpack, override
6+
7+
from ._types import (
8+
RequestOptions,
9+
)
10+
from .._client import AsyncRunloop
11+
from ..types.agent_view import AgentView
12+
13+
14+
class AsyncAgent:
15+
"""Async wrapper around agent operations."""
16+
17+
def __init__(
18+
self,
19+
client: AsyncRunloop,
20+
agent_id: str,
21+
) -> None:
22+
"""Initialize the wrapper.
23+
24+
:param client: Generated AsyncRunloop client
25+
:type client: AsyncRunloop
26+
:param agent_id: Agent identifier returned by the API
27+
:type agent_id: str
28+
"""
29+
self._client = client
30+
self._id = agent_id
31+
32+
@override
33+
def __repr__(self) -> str:
34+
return f"<AsyncAgent id={self._id!r}>"
35+
36+
@property
37+
def id(self) -> str:
38+
"""Return the agent identifier.
39+
40+
:return: Unique agent ID
41+
:rtype: str
42+
"""
43+
return self._id
44+
45+
async def get_info(
46+
self,
47+
**options: Unpack[RequestOptions],
48+
) -> AgentView:
49+
"""Retrieve the latest agent information.
50+
51+
:param options: Optional request configuration
52+
:return: Agent details
53+
:rtype: AgentView
54+
"""
55+
return await self._client.agents.retrieve(
56+
self._id,
57+
**options,
58+
)

0 commit comments

Comments
 (0)