Skip to content

Commit 0b41d70

Browse files
wall-rljrvb-rl
authored andcommitted
cp
1 parent 6cc8c2f commit 0b41d70

6 files changed

Lines changed: 270 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
@@ -4,6 +4,8 @@
44
from .._types import Body, Query, Headers, Timeout, NotGiven
55
from ..lib.polling import PollingConfig
66
from ..types.devboxes import DiskSnapshotListParams, DiskSnapshotUpdateParams
7+
from ..types.agent_list_params import AgentListParams
8+
from ..types.agent_create_params import AgentCreateParams
79
from ..types.devbox_list_params import DevboxListParams
810
from ..types.object_list_params import ObjectListParams
911
from ..types.devbox_create_params import DevboxCreateParams, DevboxBaseCreateParams
@@ -140,3 +142,11 @@ class SDKObjectCreateParams(ObjectCreateParams, LongRequestOptions):
140142

141143
class SDKObjectDownloadParams(ObjectDownloadParams, BaseRequestOptions):
142144
pass
145+
146+
147+
class SDKAgentCreateParams(AgentCreateParams, LongRequestOptions):
148+
pass
149+
150+
151+
class SDKAgentListParams(AgentListParams, RequestOptions):
152+
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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
from ._types import (
1616
LongRequestOptions,
17+
SDKAgentListParams,
1718
SDKDevboxListParams,
1819
SDKObjectListParams,
20+
SDKAgentCreateParams,
1921
SDKDevboxCreateParams,
2022
SDKObjectCreateParams,
2123
SDKBlueprintListParams,
@@ -26,6 +28,7 @@
2628
from .._types import Timeout, NotGiven, not_given
2729
from .._client import DEFAULT_MAX_RETRIES, AsyncRunloop
2830
from ._helpers import detect_content_type
31+
from .async_agent import AsyncAgent
2932
from .async_devbox import AsyncDevbox
3033
from .async_snapshot import AsyncSnapshot
3134
from .async_blueprint import AsyncBlueprint
@@ -475,6 +478,67 @@ async def upload_from_bytes(
475478
return obj
476479

477480

481+
class AsyncAgentOps:
482+
"""High-level async manager for creating and managing agents.
483+
484+
Accessed via ``runloop.agent`` from :class:`AsyncRunloopSDK`, provides
485+
coroutines to create, retrieve, and list agents.
486+
487+
Example:
488+
>>> runloop = AsyncRunloopSDK()
489+
>>> agent = await runloop.agent.create(name="my-agent")
490+
>>> agents = await runloop.agent.list(limit=10)
491+
"""
492+
493+
def __init__(self, client: AsyncRunloop) -> None:
494+
"""Initialize the manager.
495+
496+
:param client: Generated AsyncRunloop client to wrap
497+
:type client: AsyncRunloop
498+
"""
499+
self._client = client
500+
501+
async def create(
502+
self,
503+
**params: Unpack[SDKAgentCreateParams],
504+
) -> AsyncAgent:
505+
"""Create a new agent.
506+
507+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKAgentCreateParams` for available parameters
508+
:return: Wrapper bound to the newly created agent
509+
:rtype: AsyncAgent
510+
"""
511+
agent_view = await self._client.agents.create(
512+
**params,
513+
)
514+
return AsyncAgent(self._client, agent_view.id)
515+
516+
def from_id(self, agent_id: str) -> AsyncAgent:
517+
"""Attach to an existing agent by ID.
518+
519+
:param agent_id: Existing agent ID
520+
:type agent_id: str
521+
:return: Wrapper bound to the requested agent
522+
:rtype: AsyncAgent
523+
"""
524+
return AsyncAgent(self._client, agent_id)
525+
526+
async def list(
527+
self,
528+
**params: Unpack[SDKAgentListParams],
529+
) -> list[AsyncAgent]:
530+
"""List agents accessible to the caller.
531+
532+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKAgentListParams` for available parameters
533+
:return: Collection of agent wrappers
534+
:rtype: list[AsyncAgent]
535+
"""
536+
page = await self._client.agents.list(
537+
**params,
538+
)
539+
return [AsyncAgent(self._client, item.id) for item in page.agents]
540+
541+
478542
class AsyncRunloopSDK:
479543
"""High-level asynchronous entry point for the Runloop SDK.
480544
@@ -484,6 +548,8 @@ class AsyncRunloopSDK:
484548
485549
:ivar api: Direct access to the generated async REST API client
486550
:vartype api: AsyncRunloop
551+
:ivar agent: High-level async interface for agent management.
552+
:vartype agent: AsyncAgentOps
487553
:ivar devbox: High-level async interface for devbox management
488554
:vartype devbox: AsyncDevboxOps
489555
:ivar blueprint: High-level async interface for blueprint management
@@ -502,6 +568,7 @@ class AsyncRunloopSDK:
502568
"""
503569

504570
api: AsyncRunloop
571+
agent: AsyncAgentOps
505572
devbox: AsyncDevboxOps
506573
blueprint: AsyncBlueprintOps
507574
snapshot: AsyncSnapshotOps
@@ -545,6 +612,7 @@ def __init__(
545612
http_client=http_client,
546613
)
547614

615+
self.agent = AsyncAgentOps(self.api)
548616
self.devbox = AsyncDevboxOps(self.api)
549617
self.blueprint = AsyncBlueprintOps(self.api)
550618
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)