-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathagent.py
More file actions
86 lines (70 loc) · 2.12 KB
/
agent.py
File metadata and controls
86 lines (70 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Agent resource class for synchronous operations."""
from __future__ import annotations
from typing import Optional
from typing_extensions import Unpack, override
from ._types import (
BaseRequestOptions,
LongRequestOptions,
)
from .._client import Runloop
from ..types.agent_view import AgentView
class Agent:
"""Wrapper around synchronous agent operations.
This class provides a Pythonic interface for interacting with agents,
including retrieving agent information.
Example:
>>> agent = runloop.agent.create_from_npm(name="my-agent", package_name="@runloop/example-agent")
>>> info = agent.get_info()
>>> print(info.name)
"""
def __init__(
self,
client: Runloop,
agent_id: str,
agent_view: Optional[AgentView] = None,
) -> None:
"""Initialize the wrapper.
:param client: Generated Runloop client
:type client: Runloop
:param agent_id: Agent identifier returned by the API
:type agent_id: str
"""
self._client = client
self._id = agent_id
self._agent_view = agent_view
@override
def __repr__(self) -> str:
return f"<Agent id={self._id!r}>"
@property
def id(self) -> str:
"""Return the agent identifier.
:return: Unique agent ID
:rtype: str
"""
return self._id
def get_info(
self,
**options: Unpack[BaseRequestOptions],
) -> AgentView:
"""Retrieve the latest agent information.
:param options: Optional request configuration
:return: Agent details
:rtype: AgentView
"""
return self._client.agents.retrieve(
self._id,
**options,
)
def delete(
self,
**options: Unpack[LongRequestOptions],
) -> object:
"""Delete this agent. This action is irreversible.
:param options: Optional request configuration
:return: API response acknowledging deletion
:rtype: object
"""
return self._client.agents.delete(
self._id,
**options,
)