Skip to content

Commit e2160da

Browse files
wall-rljrvb-rl
authored andcommitted
cp
1 parent 1bd9450 commit e2160da

6 files changed

Lines changed: 269 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,20 +5,23 @@
55

66
from __future__ import annotations
77

8-
from .sync import DevboxOps, ScorerOps, RunloopSDK, SnapshotOps, BlueprintOps, StorageObjectOps
8+
from .sync import AgentOps, DevboxOps, ScorerOps, RunloopSDK, SnapshotOps, BlueprintOps, StorageObjectOps
99
from .async_ import (
1010
AsyncDevboxOps,
1111
AsyncScorerOps,
1212
AsyncRunloopSDK,
1313
AsyncSnapshotOps,
1414
AsyncBlueprintOps,
1515
AsyncStorageObjectOps,
16+
AsyncAgentOps,
1617
)
18+
from .agent import Agent
1719
from .devbox import Devbox, NamedShell
1820
from .scorer import Scorer
1921
from .snapshot import Snapshot
2022
from .blueprint import Blueprint
2123
from .execution import Execution
24+
from .async_agent import AsyncAgent
2225
from .async_devbox import AsyncDevbox, AsyncNamedShell
2326
from .async_scorer import AsyncScorer
2427
from .async_snapshot import AsyncSnapshot
@@ -34,6 +37,8 @@
3437
"RunloopSDK",
3538
"AsyncRunloopSDK",
3639
# Management interfaces
40+
"AgentOps",
41+
"AsyncAgentOps",
3742
"DevboxOps",
3843
"AsyncDevboxOps",
3944
"BlueprintOps",
@@ -45,6 +50,8 @@
4550
"StorageObjectOps",
4651
"AsyncStorageObjectOps",
4752
# Resource classes
53+
"Agent",
54+
"AsyncAgent",
4855
"Devbox",
4956
"AsyncDevbox",
5057
"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
from ..lib.polling import PollingConfig
66
from ..types.devboxes import DiskSnapshotListParams, DiskSnapshotUpdateParams
77
from ..types.scenarios import ScorerListParams, ScorerCreateParams, ScorerUpdateParams, ScorerValidateParams
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
@@ -157,3 +159,11 @@ class SDKScorerUpdateParams(ScorerUpdateParams, LongRequestOptions):
157159

158160
class SDKScorerValidateParams(ScorerValidateParams, LongRequestOptions):
159161
pass
162+
163+
164+
class SDKAgentCreateParams(AgentCreateParams, LongRequestOptions):
165+
pass
166+
167+
168+
class SDKAgentListParams(AgentListParams, RequestOptions):
169+
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
@@ -14,9 +14,11 @@
1414

1515
from ._types import (
1616
LongRequestOptions,
17+
SDKAgentListParams,
1718
SDKDevboxListParams,
1819
SDKObjectListParams,
1920
SDKScorerListParams,
21+
SDKAgentCreateParams,
2022
SDKDevboxCreateParams,
2123
SDKObjectCreateParams,
2224
SDKScorerCreateParams,
@@ -28,6 +30,7 @@
2830
from .._types import Timeout, NotGiven, not_given
2931
from .._client import DEFAULT_MAX_RETRIES, AsyncRunloop
3032
from ._helpers import detect_content_type
33+
from .async_agent import AsyncAgent
3134
from .async_devbox import AsyncDevbox
3235
from .async_scorer import AsyncScorer
3336
from .async_snapshot import AsyncSnapshot
@@ -541,6 +544,66 @@ async def list(self, **params: Unpack[SDKScorerListParams]) -> list[AsyncScorer]
541544
"""
542545
page = await self._client.scenarios.scorers.list(**params)
543546
return [AsyncScorer(self._client, item.id) async for item in page]
547+
548+
class AsyncAgentOps:
549+
"""High-level async manager for creating and managing agents.
550+
551+
Accessed via ``runloop.agent`` from :class:`AsyncRunloopSDK`, provides
552+
coroutines to create, retrieve, and list agents.
553+
554+
Example:
555+
>>> runloop = AsyncRunloopSDK()
556+
>>> agent = await runloop.agent.create(name="my-agent")
557+
>>> agents = await runloop.agent.list(limit=10)
558+
"""
559+
560+
def __init__(self, client: AsyncRunloop) -> None:
561+
"""Initialize the manager.
562+
563+
:param client: Generated AsyncRunloop client to wrap
564+
:type client: AsyncRunloop
565+
"""
566+
self._client = client
567+
568+
async def create(
569+
self,
570+
**params: Unpack[SDKAgentCreateParams],
571+
) -> AsyncAgent:
572+
"""Create a new agent.
573+
574+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKAgentCreateParams` for available parameters
575+
:return: Wrapper bound to the newly created agent
576+
:rtype: AsyncAgent
577+
"""
578+
agent_view = await self._client.agents.create(
579+
**params,
580+
)
581+
return AsyncAgent(self._client, agent_view.id)
582+
583+
def from_id(self, agent_id: str) -> AsyncAgent:
584+
"""Attach to an existing agent by ID.
585+
586+
:param agent_id: Existing agent ID
587+
:type agent_id: str
588+
:return: Wrapper bound to the requested agent
589+
:rtype: AsyncAgent
590+
"""
591+
return AsyncAgent(self._client, agent_id)
592+
593+
async def list(
594+
self,
595+
**params: Unpack[SDKAgentListParams],
596+
) -> list[AsyncAgent]:
597+
"""List agents accessible to the caller.
598+
599+
:param params: See :typeddict:`~runloop_api_client.sdk._types.SDKAgentListParams` for available parameters
600+
:return: Collection of agent wrappers
601+
:rtype: list[AsyncAgent]
602+
"""
603+
page = await self._client.agents.list(
604+
**params,
605+
)
606+
return [AsyncAgent(self._client, item.id) for item in page.agents]
544607

545608

546609
class AsyncRunloopSDK:
@@ -552,6 +615,8 @@ class AsyncRunloopSDK:
552615
553616
:ivar api: Direct access to the generated async REST API client
554617
:vartype api: AsyncRunloop
618+
:ivar agent: High-level async interface for agent management.
619+
:vartype agent: AsyncAgentOps
555620
:ivar devbox: High-level async interface for devbox management
556621
:vartype devbox: AsyncDevboxOps
557622
:ivar blueprint: High-level async interface for blueprint management
@@ -572,6 +637,7 @@ class AsyncRunloopSDK:
572637
"""
573638

574639
api: AsyncRunloop
640+
agent: AsyncAgentOps
575641
devbox: AsyncDevboxOps
576642
blueprint: AsyncBlueprintOps
577643
scorer: AsyncScorerOps
@@ -616,6 +682,7 @@ def __init__(
616682
http_client=http_client,
617683
)
618684

685+
self.agent = AsyncAgentOps(self.api)
619686
self.devbox = AsyncDevboxOps(self.api)
620687
self.blueprint = AsyncBlueprintOps(self.api)
621688
self.scorer = AsyncScorerOps(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)