Skip to content

Commit 91f62c1

Browse files
committed
persist additional state in the Agent and AsyncAgent objects
1 parent 05bca17 commit 91f62c1

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/runloop_api_client/sdk/agent.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from typing import Optional
56
from typing_extensions import Unpack, override
67

78
from ._types import (
@@ -18,6 +19,7 @@ def __init__(
1819
self,
1920
client: Runloop,
2021
agent_id: str,
22+
agent_view: Optional[AgentView] = None,
2123
) -> None:
2224
"""Initialize the wrapper.
2325
@@ -28,6 +30,7 @@ def __init__(
2830
"""
2931
self._client = client
3032
self._id = agent_id
33+
self._agent_view = agent_view
3134

3235
@override
3336
def __repr__(self) -> str:
@@ -52,7 +55,9 @@ def get_info(
5255
:return: Agent details
5356
:rtype: AgentView
5457
"""
55-
return self._client.agents.retrieve(
56-
self._id,
57-
**options,
58-
)
58+
if self._agent_view is None:
59+
self._agent_view = self._client.agents.retrieve(
60+
self._id,
61+
**options,
62+
)
63+
return self._agent_view

src/runloop_api_client/sdk/async_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async def list(
156156
page = await self._client.devboxes.list(
157157
**params,
158158
)
159-
return [AsyncDevbox(self._client, item.id) for item in page.devboxes]
159+
return [AsyncDevbox(self._client, item.id, item) for item in page.devboxes]
160160

161161

162162
class AsyncSnapshotOps:

src/runloop_api_client/sdk/async_agent.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from typing import Optional
56
from typing_extensions import Unpack, override
67

78
from ._types import (
@@ -18,6 +19,7 @@ def __init__(
1819
self,
1920
client: AsyncRunloop,
2021
agent_id: str,
22+
agent_view: Optional[AgentView] = None,
2123
) -> None:
2224
"""Initialize the wrapper.
2325
@@ -28,6 +30,7 @@ def __init__(
2830
"""
2931
self._client = client
3032
self._id = agent_id
33+
self._agent_view = agent_view
3134

3235
@override
3336
def __repr__(self) -> str:
@@ -56,3 +59,9 @@ async def get_info(
5659
self._id,
5760
**options,
5861
)
62+
if self._agent_view is None:
63+
self._agent_view = self._client.agents.retrieve(
64+
self._id,
65+
**options,
66+
)
67+
return self._agent_view

src/runloop_api_client/sdk/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def list(
531531
page = self._client.agents.list(
532532
**params,
533533
)
534-
return [Agent(self._client, item.id) for item in page.agents]
534+
return [Agent(self._client, item.id, item) for item in page.agents]
535535

536536

537537
class RunloopSDK:

0 commit comments

Comments
 (0)