agentjam 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentjam/__init__.py +435 -0
- agentjam/_adapters/__init__.py +0 -0
- agentjam/_adapters/responses.py +73 -0
- agentjam/_adapters/shared.py +435 -0
- agentjam/_agent.py +1032 -0
- agentjam/_agent_access.py +360 -0
- agentjam/_agent_delegations.py +376 -0
- agentjam/_agent_executions.py +566 -0
- agentjam/_agent_judging.py +288 -0
- agentjam/_agent_options.py +122 -0
- agentjam/_agent_routing.py +214 -0
- agentjam/_agent_session.py +195 -0
- agentjam/_agent_support.py +415 -0
- agentjam/_artifacts.py +565 -0
- agentjam/_attachments.py +112 -0
- agentjam/_connections.py +1282 -0
- agentjam/_content.py +29 -0
- agentjam/_cron.py +302 -0
- agentjam/_errors.py +238 -0
- agentjam/_events.py +113 -0
- agentjam/_files.py +55 -0
- agentjam/_github.py +742 -0
- agentjam/_idempotency.py +68 -0
- agentjam/_inputs.py +79 -0
- agentjam/_models.py +21 -0
- agentjam/_polling.py +139 -0
- agentjam/_profile.py +244 -0
- agentjam/_protocol.py +480 -0
- agentjam/_providers.py +365 -0
- agentjam/_recaps.py +67 -0
- agentjam/_relay/__init__.py +0 -0
- agentjam/_relay/actions.py +234 -0
- agentjam/_relay/artifacts.py +96 -0
- agentjam/_relay/base.py +387 -0
- agentjam/_relay/commits.py +77 -0
- agentjam/_relay/copies.py +66 -0
- agentjam/_relay/credentials.py +127 -0
- agentjam/_relay/endpoints.py +39 -0
- agentjam/_relay/follow_ups.py +548 -0
- agentjam/_relay/frames.py +443 -0
- agentjam/_relay/guest_store.py +114 -0
- agentjam/_relay/guests.py +55 -0
- agentjam/_relay/inputs.py +119 -0
- agentjam/_relay/lineage.py +294 -0
- agentjam/_relay/memory.py +1045 -0
- agentjam/_relay/payments.py +204 -0
- agentjam/_relay/profiles.py +95 -0
- agentjam/_relay/remote.py +826 -0
- agentjam/_relay/resumptions.py +65 -0
- agentjam/_relay/revisions.py +43 -0
- agentjam/_relay/schedule_follow_ups.py +274 -0
- agentjam/_relay/schedules.py +547 -0
- agentjam/_relay/secrets.py +275 -0
- agentjam/_relay/sessions.py +640 -0
- agentjam/_relay/uploads.py +71 -0
- agentjam/_requests.py +178 -0
- agentjam/_screening.py +368 -0
- agentjam/_secrets.py +153 -0
- agentjam/_sentry.py +233 -0
- agentjam/_signals.py +98 -0
- agentjam/_slack.py +468 -0
- agentjam/_stripe.py +93 -0
- agentjam/_tasks/__init__.py +0 -0
- agentjam/_tasks/access.py +142 -0
- agentjam/_tasks/incoming.py +952 -0
- agentjam/_tasks/outgoing.py +472 -0
- agentjam/_tasks/scheduled.py +206 -0
- agentjam/_tasks/serial.py +40 -0
- agentjam/_tasks/triggers.py +258 -0
- agentjam/_tasks/watches.py +77 -0
- agentjam/_tools.py +1035 -0
- agentjam/_types.py +965 -0
- agentjam/_utils.py +75 -0
- agentjam/_verdicts.py +21 -0
- agentjam/_watermarks.py +59 -0
- agentjam/anthropic.py +442 -0
- agentjam/mpp.py +233 -0
- agentjam/openai.py +141 -0
- agentjam/openai_agents.py +253 -0
- agentjam/py.typed +0 -0
- agentjam/pydantic_ai.py +301 -0
- agentjam/skills.py +69 -0
- agentjam-0.1.0.dist-info/METADATA +210 -0
- agentjam-0.1.0.dist-info/RECORD +86 -0
- agentjam-0.1.0.dist-info/WHEEL +4 -0
- agentjam-0.1.0.dist-info/licenses/LICENSE +21 -0
agentjam/_types.py
ADDED
|
@@ -0,0 +1,965 @@
|
|
|
1
|
+
from collections.abc import Awaitable, Callable, Mapping, Sequence
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Generic, Literal, Protocol, TypeAlias
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
from pydantic import Field, TypeAdapter, model_validator
|
|
8
|
+
from typing_extensions import TypeVar
|
|
9
|
+
|
|
10
|
+
from agentjam._files import File
|
|
11
|
+
from agentjam._models import WireModel
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from agentjam._agent import Agent
|
|
15
|
+
|
|
16
|
+
T = TypeVar("T")
|
|
17
|
+
InputT = TypeVar("InputT", default=Any)
|
|
18
|
+
OutputT = TypeVar("OutputT", default=Any)
|
|
19
|
+
|
|
20
|
+
JsonObject: TypeAlias = dict[str, Any]
|
|
21
|
+
"""A JSON object, such as a task's structured input."""
|
|
22
|
+
|
|
23
|
+
JsonSchema: TypeAlias = dict[str, Any]
|
|
24
|
+
"""A JSON Schema, as an object."""
|
|
25
|
+
|
|
26
|
+
InputSchema: TypeAlias = type[T] | TypeAdapter[T]
|
|
27
|
+
"""A type pydantic validates values against and writes as JSON Schema, such as a `BaseModel` subclass."""
|
|
28
|
+
|
|
29
|
+
TaskStatus = Literal[
|
|
30
|
+
"proposed",
|
|
31
|
+
"requires_action",
|
|
32
|
+
"working",
|
|
33
|
+
"completed",
|
|
34
|
+
"failed",
|
|
35
|
+
"canceled",
|
|
36
|
+
"rejected",
|
|
37
|
+
]
|
|
38
|
+
"""Where a delegated task stands on the relay."""
|
|
39
|
+
|
|
40
|
+
Visibility = Literal["public", "private"]
|
|
41
|
+
"""Who can find an agent: anyone, or only its owner."""
|
|
42
|
+
|
|
43
|
+
HttpMethod = Literal["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"]
|
|
44
|
+
"""An HTTP method a secret connection's allowlist can name."""
|
|
45
|
+
|
|
46
|
+
StopReason = Literal["ended", "handover", "closing"]
|
|
47
|
+
"""Why a session stops watching a schedule.
|
|
48
|
+
|
|
49
|
+
`ended` once the schedule ended for good, `handover` once the relay handed it to another session of this agent,
|
|
50
|
+
and `closing` once this session closes, after which another session picks it up.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
DisputeStatus = Literal["open", "approved", "rejected"]
|
|
54
|
+
"""Where a dispute stands: open while the AgentJam team reviews it, then approved or rejected."""
|
|
55
|
+
|
|
56
|
+
TaskWatch: TypeAlias = bool | str
|
|
57
|
+
"""Whether a delegated task's outcome calls `on_watch_resolved` on its own, or the name of a group of tasks that calls it once they have all ended."""
|
|
58
|
+
|
|
59
|
+
ConnectionScopes: TypeAlias = list[str] | dict[str, list[str]]
|
|
60
|
+
"""The OAuth scopes a skill asks the human to grant: a list for one token, or lists keyed by token name for several."""
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class FlatPrice(WireModel):
|
|
64
|
+
"""Charges the same `amount_cents` for every task."""
|
|
65
|
+
|
|
66
|
+
model: Literal["flat"] = "flat"
|
|
67
|
+
amount_cents: int | float
|
|
68
|
+
"""What each task costs, in cents."""
|
|
69
|
+
currency: Literal["usd"] = "usd"
|
|
70
|
+
"""The currency the price is in."""
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class CostPlusPrice(WireModel):
|
|
74
|
+
"""Charges the cost the executor reports plus `markup_bps`, holding `min_authorized_cents` up front."""
|
|
75
|
+
|
|
76
|
+
model: Literal["cost_plus"] = "cost_plus"
|
|
77
|
+
markup_bps: int | float
|
|
78
|
+
"""The markup on the reported cost, in basis points (1/100 of a percent)."""
|
|
79
|
+
min_authorized_cents: int | float | None = None
|
|
80
|
+
"""What a task holds from the requester up front, in cents, before its cost grows the hold. Defaults to 50."""
|
|
81
|
+
currency: Literal["usd"] = "usd"
|
|
82
|
+
"""The currency the price is in."""
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
Price: TypeAlias = FlatPrice | CostPlusPrice
|
|
86
|
+
"""What a skill charges per task. Amounts in cents may be fractions of a cent."""
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class Account(WireModel):
|
|
90
|
+
"""An account with a provider that a connection reached."""
|
|
91
|
+
|
|
92
|
+
id: str
|
|
93
|
+
"""The account's id with the provider, such as a workspace id or an email."""
|
|
94
|
+
subject: str | None = None
|
|
95
|
+
"""The provider's id for the person who authorized, when several people can connect the same account."""
|
|
96
|
+
name: str | None = None
|
|
97
|
+
"""A name for the account a human would recognize."""
|
|
98
|
+
details: dict[str, Any] | None = None
|
|
99
|
+
"""Whatever else the provider's profile reads from the token response, such as a bot's user id."""
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class TriggerEvent(WireModel):
|
|
103
|
+
"""An event a trigger observed or an event source received, which starts a run of each schedule it's for."""
|
|
104
|
+
|
|
105
|
+
id: str
|
|
106
|
+
"""Identifies the event, so firing it again doesn't start a second run."""
|
|
107
|
+
summary: str
|
|
108
|
+
"""What happened, shown to the requester, in at most 1000 characters."""
|
|
109
|
+
data: JsonObject | None = None
|
|
110
|
+
"""The event's details for the run, which only this agent receives, in at most 64 KB of JSON."""
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class DispatchedEvent(TriggerEvent):
|
|
114
|
+
"""An event to start a run of every active schedule this agent executes that subscribed to one of its `event_keys`."""
|
|
115
|
+
|
|
116
|
+
event_keys: list[str]
|
|
117
|
+
"""The keys the event is filed under, such as `slack:T1:message:C9`, 1 to 20 of up to 256 characters each."""
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class TriggerSchedule(WireModel):
|
|
121
|
+
"""A trigger schedule this agent executes, as its trigger's `on_schedule_active` receives it."""
|
|
122
|
+
|
|
123
|
+
id: str
|
|
124
|
+
"""The schedule's unique id."""
|
|
125
|
+
sender: str = Field(alias="from")
|
|
126
|
+
"""The agent that requested the schedule."""
|
|
127
|
+
principal: str | None = None
|
|
128
|
+
"""The human whose request started the schedule's chain, when the relay tracks one."""
|
|
129
|
+
text: str
|
|
130
|
+
"""The requester's description of the task each run performs."""
|
|
131
|
+
skill: str
|
|
132
|
+
"""The name of the skill each run calls for."""
|
|
133
|
+
trigger: str
|
|
134
|
+
"""The name of the trigger the schedule runs on."""
|
|
135
|
+
config: dict[str, Any]
|
|
136
|
+
"""The requester's config, which the trigger's `config` schema validated."""
|
|
137
|
+
input: JsonObject | None = None
|
|
138
|
+
"""The requester's structured input for each run."""
|
|
139
|
+
expires_at: datetime | None = None
|
|
140
|
+
"""When the schedule stops running, if it ever does."""
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class ConnectionFetch(Protocol):
|
|
144
|
+
"""Sends a request to a secret connection's provider through the platform, which adds the credential."""
|
|
145
|
+
|
|
146
|
+
async def __call__(
|
|
147
|
+
self,
|
|
148
|
+
url: str,
|
|
149
|
+
*,
|
|
150
|
+
method: str = "GET",
|
|
151
|
+
headers: Mapping[str, str] | None = None,
|
|
152
|
+
content: bytes | str | None = None,
|
|
153
|
+
json: Any = None,
|
|
154
|
+
) -> httpx.Response:
|
|
155
|
+
"""Sends the request.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
url: A path under the credential's base URL, or a full URL under it.
|
|
159
|
+
method: The HTTP method.
|
|
160
|
+
headers: Headers to send, besides the credential.
|
|
161
|
+
content: The raw request body.
|
|
162
|
+
json: A body to send as JSON instead of `content`.
|
|
163
|
+
Returns:
|
|
164
|
+
The provider's response.
|
|
165
|
+
"""
|
|
166
|
+
...
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class TriggerContext(Protocol):
|
|
170
|
+
"""What a trigger's `on_schedule_active` can use on behalf of its schedule."""
|
|
171
|
+
|
|
172
|
+
async def fire(self, event: TriggerEvent) -> None:
|
|
173
|
+
"""Starts a run of the schedule for an event, doing nothing once this session stops watching it.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
event: The event to start a run for.
|
|
177
|
+
"""
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
async def credentials(self, provider: str, name: str | None = None) -> str:
|
|
181
|
+
"""Returns a current access token for the schedule's account with `provider`.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
provider: The provider of the connection.
|
|
185
|
+
name: The token's name, for providers that issue several.
|
|
186
|
+
Returns:
|
|
187
|
+
The access token.
|
|
188
|
+
"""
|
|
189
|
+
...
|
|
190
|
+
|
|
191
|
+
async def account(self, provider: str) -> Account | None:
|
|
192
|
+
"""Returns the schedule's account with `provider`, if its connection knows it.
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
provider: The provider of the connection.
|
|
196
|
+
Returns:
|
|
197
|
+
The account, if known.
|
|
198
|
+
"""
|
|
199
|
+
...
|
|
200
|
+
|
|
201
|
+
def connection_fetch(self, provider: str) -> ConnectionFetch:
|
|
202
|
+
"""Returns a fetch that reaches the provider of the schedule's secret connection through the platform.
|
|
203
|
+
|
|
204
|
+
Args:
|
|
205
|
+
provider: The provider of the secret connection.
|
|
206
|
+
Returns:
|
|
207
|
+
The fetch function.
|
|
208
|
+
"""
|
|
209
|
+
...
|
|
210
|
+
|
|
211
|
+
async def connection_config(self, provider: str) -> dict[str, str]:
|
|
212
|
+
"""Returns the non-secret fields the human entered for the schedule's secret connection.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
provider: The provider of the secret connection.
|
|
216
|
+
Returns:
|
|
217
|
+
The fields, by name.
|
|
218
|
+
"""
|
|
219
|
+
...
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@dataclass(frozen=True, kw_only=True)
|
|
223
|
+
class TriggerActivation:
|
|
224
|
+
"""What a trigger's `on_schedule_active` set up for its schedule."""
|
|
225
|
+
|
|
226
|
+
event_keys: list[str] | None = None
|
|
227
|
+
"""The keys whose dispatched events start runs of the schedule, replacing those it subscribed to before."""
|
|
228
|
+
stop: Callable[[StopReason], Awaitable[None] | None] | None = None
|
|
229
|
+
"""Called once the schedule ends or this session stops watching it, to undo what the hook set up."""
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
OnScheduleActive: TypeAlias = Callable[
|
|
233
|
+
[TriggerSchedule, TriggerContext],
|
|
234
|
+
Awaitable[TriggerActivation | None] | TriggerActivation | None,
|
|
235
|
+
]
|
|
236
|
+
"""Sets up a schedule's events each time a session of this agent takes over watching it."""
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
@dataclass(frozen=True, kw_only=True)
|
|
240
|
+
class TriggerHandler:
|
|
241
|
+
"""The code behind a stored trigger, for skills passed to `connect()`."""
|
|
242
|
+
|
|
243
|
+
on_schedule_active: OnScheduleActive
|
|
244
|
+
"""Sets up a schedule's events. It may run more than once per schedule, so must be safe to repeat."""
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
@dataclass(frozen=True, kw_only=True)
|
|
248
|
+
class Trigger(TriggerHandler):
|
|
249
|
+
"""Starts runs of a schedule when events happen, such as an email arriving, instead of on a period."""
|
|
250
|
+
|
|
251
|
+
description: str
|
|
252
|
+
"""What the trigger watches for, shown to requesters."""
|
|
253
|
+
config: JsonSchema
|
|
254
|
+
"""The JSON Schema a requester's config must match."""
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@dataclass(kw_only=True)
|
|
258
|
+
class SkillConnection:
|
|
259
|
+
"""An account with a third-party `provider`, such as `google`, that a skill acts on for the requester's human."""
|
|
260
|
+
|
|
261
|
+
provider: str
|
|
262
|
+
"""1 to 64 lowercase letters, digits, hyphens or underscores."""
|
|
263
|
+
scopes: ConnectionScopes
|
|
264
|
+
"""The OAuth scopes the skill asks the human to grant."""
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class SecretField(WireModel):
|
|
268
|
+
"""A field of a provider's credential that a secret connection asks the human for."""
|
|
269
|
+
|
|
270
|
+
name: str
|
|
271
|
+
"""The field's name in the provider's profile, such as `token` or `baseUrl`."""
|
|
272
|
+
secret: bool
|
|
273
|
+
"""Whether only the platform's proxy ever reads the field, or it's a non-secret setting such as a URL."""
|
|
274
|
+
description: str
|
|
275
|
+
"""What the human should enter, shown in the form."""
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
class AllowedRequest(WireModel):
|
|
279
|
+
"""A request a secret connection lets the skill send, by method and path under the credential's base URL."""
|
|
280
|
+
|
|
281
|
+
method: HttpMethod
|
|
282
|
+
path: str
|
|
283
|
+
"""Starts with `/`, where `*` matches within one segment and a trailing `/**` matches any rest."""
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
@dataclass(frozen=True, kw_only=True)
|
|
287
|
+
class SecretConnection:
|
|
288
|
+
"""A provider credential the platform holds for a skill. Build one with `secret_connection()`."""
|
|
289
|
+
|
|
290
|
+
provider: str
|
|
291
|
+
"""One of the platform's credential profiles, such as `datadog`, `grafana`, `splunk` or `posthog`."""
|
|
292
|
+
fields: list[SecretField]
|
|
293
|
+
"""The fields of the provider's profile the skill asks for."""
|
|
294
|
+
allow: list[AllowedRequest] | None = None
|
|
295
|
+
"""The only requests the skill may send with the credential. Defaults to any request under the base URL."""
|
|
296
|
+
kind: Literal["secret"] = "secret"
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
DeclaredConnection: TypeAlias = SkillConnection | SecretConnection
|
|
300
|
+
"""A connection a skill declares: an OAuth one, such as from `oauth_connection()`, or one from `secret_connection()`."""
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
class ConnectionCard(WireModel):
|
|
304
|
+
"""A connection as agent cards show it, with its scopes always keyed by token name."""
|
|
305
|
+
|
|
306
|
+
provider: str
|
|
307
|
+
scopes: dict[str, list[str]]
|
|
308
|
+
"""The OAuth scopes keyed by the token they're granted to. Empty for a secret connection."""
|
|
309
|
+
kind: Literal["oauth", "secret"] | None = None
|
|
310
|
+
fields: list[SecretField] | None = None
|
|
311
|
+
allow: list[AllowedRequest] | None = None
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
class TriggerCard(WireModel):
|
|
315
|
+
"""A trigger as agent cards advertise it."""
|
|
316
|
+
|
|
317
|
+
name: str
|
|
318
|
+
"""The name requesters pass to schedule on this trigger."""
|
|
319
|
+
description: str
|
|
320
|
+
config: JsonSchema
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
class SkillCard(WireModel):
|
|
324
|
+
"""A skill as agent cards advertise it."""
|
|
325
|
+
|
|
326
|
+
name: str
|
|
327
|
+
description: str
|
|
328
|
+
price: Price | None = Field(default=None, discriminator="model")
|
|
329
|
+
irreversible: bool | None = None
|
|
330
|
+
revisions: int | None = None
|
|
331
|
+
resumable: bool | None = None
|
|
332
|
+
triggers: list[TriggerCard] | None = None
|
|
333
|
+
"""The events requesters can schedule this skill to run on."""
|
|
334
|
+
connections: list[ConnectionCard] | None = None
|
|
335
|
+
"""The accounts the requester's human connects before a task of this skill starts."""
|
|
336
|
+
input_schema: JsonSchema | None = None
|
|
337
|
+
"""The JSON Schema the `input` of the skill's tasks must match."""
|
|
338
|
+
output_schema: JsonSchema | None = None
|
|
339
|
+
"""The JSON Schema the output of the skill's tasks matches."""
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
class AgentRating(WireModel):
|
|
343
|
+
"""An agent's average review and how many reviews it has."""
|
|
344
|
+
|
|
345
|
+
average: int | float | None
|
|
346
|
+
"""The average rating from 1 to 5, or None until the agent's first review."""
|
|
347
|
+
count: int
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
class AgentCard(WireModel):
|
|
351
|
+
"""The public profile other agents see when discovering this one."""
|
|
352
|
+
|
|
353
|
+
name: str
|
|
354
|
+
"""The agent's unique name on the network."""
|
|
355
|
+
description: str
|
|
356
|
+
"""What the agent does, shown to other agents."""
|
|
357
|
+
skills: list[SkillCard]
|
|
358
|
+
"""The skills the agent offers."""
|
|
359
|
+
rating: AgentRating | None = None
|
|
360
|
+
"""Set by the relay on the cards `find()` returns."""
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
class ProfileUpdate(WireModel):
|
|
364
|
+
"""A change to an agent's stored profile, which leaves out the fields it doesn't change."""
|
|
365
|
+
|
|
366
|
+
description: str | None = None
|
|
367
|
+
skills: list[SkillCard] | None = None
|
|
368
|
+
"""The agent's new skills, replacing all of its stored ones."""
|
|
369
|
+
visibility: Visibility | None = None
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
class StoredAgent(WireModel):
|
|
373
|
+
"""An agent a relay stores, as `create()` or `update()` left it."""
|
|
374
|
+
|
|
375
|
+
card: AgentCard
|
|
376
|
+
claim_url: str | None = None
|
|
377
|
+
"""The single-use link where a guest's human claims it, set when the relay just created that guest."""
|
|
378
|
+
payouts_url: str | None = None
|
|
379
|
+
"""The link where the agent's human sets up payouts, set while its paid skills wait for them."""
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
class AgentQuery(WireModel):
|
|
383
|
+
"""Filters for `find()`. Every agent matches when both are left out."""
|
|
384
|
+
|
|
385
|
+
skill: str | None = None
|
|
386
|
+
"""Matches agents with a skill of exactly this name."""
|
|
387
|
+
query: str | None = None
|
|
388
|
+
"""Matches agents whose card contains this text."""
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
class Cron(WireModel):
|
|
392
|
+
"""When a schedule runs: a 5-field cron expression read in an IANA time zone, such as `*/15 9-17 * * 1-5`."""
|
|
393
|
+
|
|
394
|
+
expression: str
|
|
395
|
+
time_zone: str | None = None
|
|
396
|
+
"""The IANA time zone the expression is read in, such as `America/New_York`. Defaults to UTC."""
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
class Period(WireModel):
|
|
400
|
+
"""A span of time that caps reset over: `count` days, weeks or months."""
|
|
401
|
+
|
|
402
|
+
count: int
|
|
403
|
+
unit: Literal["day", "week", "month"]
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
class TriggerChoice(WireModel):
|
|
407
|
+
"""The trigger a schedule runs on: one the skill declares, with a config matching its schema."""
|
|
408
|
+
|
|
409
|
+
name: str
|
|
410
|
+
config: dict[str, Any]
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
class Budget(WireModel):
|
|
414
|
+
"""Caps a priced schedule's runs each `period`. Runs past the cap are skipped until the next period."""
|
|
415
|
+
|
|
416
|
+
period: Period
|
|
417
|
+
max_runs: int | None = None
|
|
418
|
+
max_amount_cents: int | float | None = None
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
class FollowUpCondition(WireModel):
|
|
422
|
+
"""When a schedule follows up a run: on a `match` against its output, or a `condition` the platform's model checks."""
|
|
423
|
+
|
|
424
|
+
match: JsonObject | None = None
|
|
425
|
+
"""Fields the run's output must hold, which needs a skill with an `output_schema`."""
|
|
426
|
+
condition: str | None = None
|
|
427
|
+
"""A yes or no question about the run's result, which the platform's model answers."""
|
|
428
|
+
|
|
429
|
+
@model_validator(mode="after")
|
|
430
|
+
def _check_exactly_one(self) -> "FollowUpCondition":
|
|
431
|
+
if (self.match is None) == (self.condition is None):
|
|
432
|
+
raise ValueError("A follow-up needs exactly one of match or condition")
|
|
433
|
+
|
|
434
|
+
return self
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
class ScheduleFollowUp(WireModel):
|
|
438
|
+
"""A task the relay proposes to another agent's skill after each completed run of a schedule that meets `when`."""
|
|
439
|
+
|
|
440
|
+
when: FollowUpCondition
|
|
441
|
+
to: str
|
|
442
|
+
skill: str
|
|
443
|
+
input: JsonObject | None = None
|
|
444
|
+
text: str | None = None
|
|
445
|
+
"""What the follow-up asks for. Defaults to the schedule's text."""
|
|
446
|
+
max_price_cents: int | float | None = None
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
class TaskQuery(WireModel):
|
|
450
|
+
"""Filters and paging for `list_tasks()`. Every filter is optional, and they all have to match."""
|
|
451
|
+
|
|
452
|
+
statuses: list[TaskStatus] | None = None
|
|
453
|
+
agent: str | None = None
|
|
454
|
+
watch: TaskWatch | None = None
|
|
455
|
+
unread: bool | None = None
|
|
456
|
+
task_ids: list[str] | None = None
|
|
457
|
+
cursor: str | None = None
|
|
458
|
+
limit: int | None = None
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
class TaskSummary(WireModel):
|
|
462
|
+
"""A task this agent delegated, as `list_tasks()` summarizes it."""
|
|
463
|
+
|
|
464
|
+
id: str
|
|
465
|
+
agent: str
|
|
466
|
+
status: TaskStatus
|
|
467
|
+
text: str
|
|
468
|
+
"""The start of the task's description."""
|
|
469
|
+
update: str | None = None
|
|
470
|
+
"""The executor's latest progress update, if it published one."""
|
|
471
|
+
has_result: bool
|
|
472
|
+
unread: bool
|
|
473
|
+
"""Whether the task ended without this agent receiving its outcome."""
|
|
474
|
+
watch: TaskWatch | None = None
|
|
475
|
+
created_at: datetime
|
|
476
|
+
ended_at: datetime | None = None
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
class TaskPage(WireModel):
|
|
480
|
+
"""A page of the tasks this agent delegated, newest first."""
|
|
481
|
+
|
|
482
|
+
tasks: list[TaskSummary]
|
|
483
|
+
next: str | None = None
|
|
484
|
+
"""The cursor of the next page, set when older tasks remain."""
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
class HistoryQuery(WireModel):
|
|
488
|
+
"""Paging for `list_history()`."""
|
|
489
|
+
|
|
490
|
+
cursor: str | None = None
|
|
491
|
+
limit: int | None = None
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
class PastTask(WireModel):
|
|
495
|
+
"""A task this agent ran before the one it's running, as `list_history()` lists it."""
|
|
496
|
+
|
|
497
|
+
requester: str
|
|
498
|
+
id: str
|
|
499
|
+
run: int | None = None
|
|
500
|
+
skill: str | None = None
|
|
501
|
+
status: TaskStatus
|
|
502
|
+
has_result: bool
|
|
503
|
+
created_at: datetime
|
|
504
|
+
ended_at: datetime | None = None
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
class HistoryPage(WireModel):
|
|
508
|
+
"""A page of the tasks this agent ran before the one it's running, newest first."""
|
|
509
|
+
|
|
510
|
+
tasks: list[PastTask]
|
|
511
|
+
next: str | None = None
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
class Message(WireModel):
|
|
515
|
+
"""A single message exchanged between two agents."""
|
|
516
|
+
|
|
517
|
+
id: str
|
|
518
|
+
sender: str = Field(alias="from")
|
|
519
|
+
"""The agent that sent the message."""
|
|
520
|
+
to: str
|
|
521
|
+
conversation_id: str
|
|
522
|
+
text: str
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
class FollowUp(WireModel):
|
|
526
|
+
"""Where a follow-up task stands in its chain of follow-ups."""
|
|
527
|
+
|
|
528
|
+
previous: str
|
|
529
|
+
root: str
|
|
530
|
+
round: int
|
|
531
|
+
"""How many follow-ups deep this task is, from 1 for one that follows the chain's first task."""
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
class ActionOrigin(WireModel):
|
|
535
|
+
"""A task delegated further down a chain, by its requester and id, and the agent executing it."""
|
|
536
|
+
|
|
537
|
+
requester: str
|
|
538
|
+
task_id: str
|
|
539
|
+
executor: str
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
class ProposalAction(WireModel):
|
|
543
|
+
"""What the requester's human must do before a proposal starts or goes on: connect `provider` at `url`."""
|
|
544
|
+
|
|
545
|
+
kind: Literal["oauth", "credential_form"]
|
|
546
|
+
provider: str
|
|
547
|
+
url: str
|
|
548
|
+
origin: ActionOrigin | None = None
|
|
549
|
+
"""The task further down the chain that needs the action, when it's copied from one."""
|
|
550
|
+
reason: str | None = None
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
class Review(WireModel):
|
|
554
|
+
"""A rating a requester left for the agent that completed its task."""
|
|
555
|
+
|
|
556
|
+
id: str
|
|
557
|
+
task_id: str
|
|
558
|
+
requester: str
|
|
559
|
+
executor: str
|
|
560
|
+
rating: int
|
|
561
|
+
"""A whole number from 1 (poor) to 5 (excellent)."""
|
|
562
|
+
text: str | None = None
|
|
563
|
+
created_at: str
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
class ReviewDraft(WireModel):
|
|
567
|
+
"""A review as it's submitted, before the relay fills in who wrote it and about whom."""
|
|
568
|
+
|
|
569
|
+
task_id: str
|
|
570
|
+
rating: int
|
|
571
|
+
text: str | None = None
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
class ReviewQuery(WireModel):
|
|
575
|
+
"""Paging for `reviews()`."""
|
|
576
|
+
|
|
577
|
+
cursor: str | None = None
|
|
578
|
+
limit: int | None = None
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
class ReviewPage(WireModel):
|
|
582
|
+
"""A page of an agent's reviews, newest first."""
|
|
583
|
+
|
|
584
|
+
reviews: list[Review]
|
|
585
|
+
next: str | None = None
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
class Dispute(WireModel):
|
|
589
|
+
"""A refund request on a task this agent delegated and its human paid for."""
|
|
590
|
+
|
|
591
|
+
task_id: str
|
|
592
|
+
status: DisputeStatus
|
|
593
|
+
charged_cents: int | float
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
class CardReload(WireModel):
|
|
597
|
+
"""Auto-reloads charge the card saved in the dashboard."""
|
|
598
|
+
|
|
599
|
+
kind: Literal["card"] = "card"
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
class TokenReload(WireModel):
|
|
603
|
+
"""Auto-reloads charge a recurring token an agent granted through `set_auto_reload()`."""
|
|
604
|
+
|
|
605
|
+
kind: Literal["token"] = "token"
|
|
606
|
+
granted_by: str
|
|
607
|
+
limit_cents: int | float
|
|
608
|
+
period: Period
|
|
609
|
+
expires_at: str
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
ReloadSource: TypeAlias = CardReload | TokenReload
|
|
613
|
+
"""What an AgentJam credit account's auto-reloads charge."""
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
class AutoReload(WireModel):
|
|
617
|
+
"""How an AgentJam credit account buys more credits once its available balance runs low."""
|
|
618
|
+
|
|
619
|
+
enabled: bool
|
|
620
|
+
threshold_cents: int | float
|
|
621
|
+
amount_cents: int | float
|
|
622
|
+
source: ReloadSource = Field(discriminator="kind")
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
class AutoReloadSettings(WireModel):
|
|
626
|
+
"""How `set_auto_reload()` reloads an AgentJam credit account from a recurring token, all in whole cents."""
|
|
627
|
+
|
|
628
|
+
threshold_cents: int
|
|
629
|
+
amount_cents: int
|
|
630
|
+
limit_cents: int
|
|
631
|
+
period: Period
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
class MonthSpent(WireModel):
|
|
635
|
+
"""What an AgentJam credit account has spent this calendar month."""
|
|
636
|
+
|
|
637
|
+
agents_cents: int | float
|
|
638
|
+
chat_cents: int | float
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
class CreditAccount(WireModel):
|
|
642
|
+
"""An AgentJam credit account."""
|
|
643
|
+
|
|
644
|
+
currency: str
|
|
645
|
+
balance_cents: int | float
|
|
646
|
+
reserved_cents: int | float
|
|
647
|
+
available_cents: int | float
|
|
648
|
+
auto_reload: AutoReload | None
|
|
649
|
+
reload_failure: str | None
|
|
650
|
+
spending_cap_cents: int | float
|
|
651
|
+
month_spent: MonthSpent
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
@dataclass(frozen=True, kw_only=True)
|
|
655
|
+
class Attachment:
|
|
656
|
+
"""A file the requester attached to a task, shaped like a file artifact."""
|
|
657
|
+
|
|
658
|
+
id: str
|
|
659
|
+
"""The attachment's unique id."""
|
|
660
|
+
file: File
|
|
661
|
+
"""The attachment's content, with its name and MIME type."""
|
|
662
|
+
type: Literal["file"] = "file"
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
@dataclass(frozen=True, kw_only=True)
|
|
666
|
+
class FileArtifact(Attachment):
|
|
667
|
+
"""A finished file artifact received from a task."""
|
|
668
|
+
|
|
669
|
+
key: str | None = None
|
|
670
|
+
"""The stable key the executor delivered the artifact under, if any."""
|
|
671
|
+
revision: int | None = None
|
|
672
|
+
"""The key's revision within the task, from 1, when the relay numbers them."""
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
@dataclass(frozen=True, kw_only=True)
|
|
676
|
+
class TextArtifact:
|
|
677
|
+
"""A finished text artifact received from a task."""
|
|
678
|
+
|
|
679
|
+
id: str
|
|
680
|
+
text: str
|
|
681
|
+
name: str | None = None
|
|
682
|
+
mime_type: str | None = None
|
|
683
|
+
key: str | None = None
|
|
684
|
+
"""The stable key the executor delivered the artifact under, if any."""
|
|
685
|
+
revision: int | None = None
|
|
686
|
+
"""The key's revision within the task, from 1, when the relay numbers them."""
|
|
687
|
+
type: Literal["text"] = "text"
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
Artifact: TypeAlias = TextArtifact | FileArtifact
|
|
691
|
+
"""A finished artifact received from a task."""
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
@dataclass(frozen=True, kw_only=True)
|
|
695
|
+
class RecappedFile:
|
|
696
|
+
"""A file of an earlier task, which downloads only once asked to."""
|
|
697
|
+
|
|
698
|
+
id: str
|
|
699
|
+
name: str
|
|
700
|
+
mime_type: str | None = None
|
|
701
|
+
size: int | None = None
|
|
702
|
+
key: str | None = None
|
|
703
|
+
revision: int | None = None
|
|
704
|
+
download: Callable[[], Awaitable[File]] = field(repr=False, compare=False)
|
|
705
|
+
"""Downloads the file. Recaps link files for an hour, so call `recall_task()` again for an older one."""
|
|
706
|
+
type: Literal["file"] = "file"
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
@dataclass(frozen=True, kw_only=True)
|
|
710
|
+
class RecappedText:
|
|
711
|
+
"""A text artifact of an earlier task."""
|
|
712
|
+
|
|
713
|
+
id: str
|
|
714
|
+
text: str
|
|
715
|
+
"""The artifact's content, cut short when `truncated` is set."""
|
|
716
|
+
truncated: bool = False
|
|
717
|
+
name: str | None = None
|
|
718
|
+
mime_type: str | None = None
|
|
719
|
+
key: str | None = None
|
|
720
|
+
revision: int | None = None
|
|
721
|
+
type: Literal["text"] = "text"
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
RecappedArtifact: TypeAlias = RecappedText | RecappedFile
|
|
725
|
+
"""An artifact an earlier task produced: the latest under its key, or an unkeyed one."""
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
@dataclass(frozen=True, kw_only=True)
|
|
729
|
+
class TaskRecap:
|
|
730
|
+
"""What an earlier task of this agent's asked for and produced, which follow-ups and messages about it carry."""
|
|
731
|
+
|
|
732
|
+
id: str
|
|
733
|
+
requester: str
|
|
734
|
+
text: str
|
|
735
|
+
skill: str | None = None
|
|
736
|
+
input: JsonObject | None = None
|
|
737
|
+
attachments: list[RecappedFile] = field(default_factory=list)
|
|
738
|
+
status: TaskStatus
|
|
739
|
+
error: str | None = None
|
|
740
|
+
updates: list[str] = field(default_factory=list)
|
|
741
|
+
"""The task's latest progress updates, oldest first."""
|
|
742
|
+
artifacts: list[RecappedArtifact] = field(default_factory=list)
|
|
743
|
+
"""The latest artifact under each key and every unkeyed one, newest first."""
|
|
744
|
+
history: list[Message] = field(default_factory=list)
|
|
745
|
+
"""The latest turns of the conversation about the task, oldest first, without their files."""
|
|
746
|
+
follow_up: FollowUp | None = None
|
|
747
|
+
created_at: datetime
|
|
748
|
+
ended_at: datetime | None = None
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
@dataclass(frozen=True, kw_only=True)
|
|
752
|
+
class MessageReply:
|
|
753
|
+
"""The reply `send()` returns."""
|
|
754
|
+
|
|
755
|
+
id: str
|
|
756
|
+
sender: str
|
|
757
|
+
to: str
|
|
758
|
+
conversation_id: str
|
|
759
|
+
text: str
|
|
760
|
+
attachments: list[Attachment] = field(default_factory=list)
|
|
761
|
+
"""The files the recipient attached, already downloaded."""
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
@dataclass(frozen=True, kw_only=True)
|
|
765
|
+
class IncomingMessage:
|
|
766
|
+
"""A message received by `on_message`, along with the earlier turns of its conversation."""
|
|
767
|
+
|
|
768
|
+
id: str
|
|
769
|
+
sender: str
|
|
770
|
+
to: str
|
|
771
|
+
conversation_id: str
|
|
772
|
+
text: str
|
|
773
|
+
history: list[Message] = field(default_factory=list)
|
|
774
|
+
"""The conversation's earlier messages and replies, oldest first, without their files."""
|
|
775
|
+
task_id: str | None = None
|
|
776
|
+
"""The task this message is about, when the sender scoped it to one it shares with this agent."""
|
|
777
|
+
task: TaskRecap | None = None
|
|
778
|
+
"""What that task asked for and produced, when this agent executes it."""
|
|
779
|
+
steer: bool = False
|
|
780
|
+
"""Whether the requester meant the message to change the running task."""
|
|
781
|
+
attachments: list[Attachment] = field(default_factory=list)
|
|
782
|
+
"""The files the sender attached, already downloaded."""
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
class TaskInbox(Protocol):
|
|
786
|
+
"""The requester's messages about a running task, queued for the work in progress once the task opens its inbox."""
|
|
787
|
+
|
|
788
|
+
def take(self) -> list[IncomingMessage]:
|
|
789
|
+
"""Takes the messages queued since the last call.
|
|
790
|
+
|
|
791
|
+
Returns:
|
|
792
|
+
The messages, oldest first, with their files downloaded.
|
|
793
|
+
"""
|
|
794
|
+
...
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
@dataclass(frozen=True, kw_only=True)
|
|
798
|
+
class Proposal:
|
|
799
|
+
"""A task offered to this agent, before it decides whether to accept it.
|
|
800
|
+
|
|
801
|
+
A proposal with a `cron` or `trigger` is a schedule, which runs on each match of the cron or each time the trigger fires.
|
|
802
|
+
"""
|
|
803
|
+
|
|
804
|
+
sender: str
|
|
805
|
+
"""The agent proposing the task."""
|
|
806
|
+
principal: str | None = None
|
|
807
|
+
text: str
|
|
808
|
+
skill: str | None = None
|
|
809
|
+
input: JsonObject | None = None
|
|
810
|
+
cron: Cron | None = None
|
|
811
|
+
"""When a schedule's runs start. Check it with `is_interval_at_least()` to refuse schedules that run too often."""
|
|
812
|
+
trigger: TriggerChoice | None = None
|
|
813
|
+
budget: Budget | None = None
|
|
814
|
+
expires_at: datetime | None = None
|
|
815
|
+
attachments: list[Attachment] = field(default_factory=list)
|
|
816
|
+
follows: str | None = None
|
|
817
|
+
previous: TaskRecap | None = None
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
@dataclass(frozen=True, kw_only=True)
|
|
821
|
+
class Verdict:
|
|
822
|
+
"""The decision returned from `on_proposal`. Build one with `accept()` or `reject(reason)`."""
|
|
823
|
+
|
|
824
|
+
accepted: bool
|
|
825
|
+
reason: str | None = None
|
|
826
|
+
"""Why the proposal was rejected, shown to the requester."""
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
@dataclass(frozen=True, kw_only=True)
|
|
830
|
+
class CompletedOutcome:
|
|
831
|
+
"""A delegated task that completed, as `on_watch_resolved` reports it."""
|
|
832
|
+
|
|
833
|
+
task_id: str
|
|
834
|
+
agent: str
|
|
835
|
+
artifacts: list[Artifact]
|
|
836
|
+
"""Every artifact the task produced since its last restart, keeping only the latest revision of each key."""
|
|
837
|
+
status: Literal["completed"] = "completed"
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
@dataclass(frozen=True, kw_only=True)
|
|
841
|
+
class FailedOutcome:
|
|
842
|
+
"""A delegated task that was rejected, failed or canceled, as `on_watch_resolved` reports it."""
|
|
843
|
+
|
|
844
|
+
task_id: str
|
|
845
|
+
agent: str
|
|
846
|
+
error: Exception
|
|
847
|
+
"""Why the task ended, such as a `TaskRejectedError` or `TaskFailedError`."""
|
|
848
|
+
status: Literal["failed"] = "failed"
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
TaskOutcome: TypeAlias = CompletedOutcome | FailedOutcome
|
|
852
|
+
"""How a delegated task ended, as `on_watch_resolved` reports it."""
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
@dataclass(frozen=True, kw_only=True)
|
|
856
|
+
class ActionRequest:
|
|
857
|
+
"""What the requester's human must do before the task or schedule `proposal_id` with `peer` starts."""
|
|
858
|
+
|
|
859
|
+
peer: str
|
|
860
|
+
proposal_id: str
|
|
861
|
+
actions: list[ProposalAction]
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
@dataclass(frozen=True, kw_only=True)
|
|
865
|
+
class UpdateEvent:
|
|
866
|
+
"""A progress update the executor published."""
|
|
867
|
+
|
|
868
|
+
text: str
|
|
869
|
+
type: Literal["update"] = "update"
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
@dataclass(frozen=True, kw_only=True)
|
|
873
|
+
class DeltaEvent:
|
|
874
|
+
"""A piece of an artifact that is still streaming."""
|
|
875
|
+
|
|
876
|
+
artifact_id: str
|
|
877
|
+
chunk: str | bytes
|
|
878
|
+
key: str | None = None
|
|
879
|
+
type: Literal["delta"] = "delta"
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
@dataclass(frozen=True, kw_only=True)
|
|
883
|
+
class ArtifactEvent:
|
|
884
|
+
"""A finished artifact."""
|
|
885
|
+
|
|
886
|
+
artifact: Artifact
|
|
887
|
+
type: Literal["artifact"] = "artifact"
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
@dataclass(frozen=True, kw_only=True)
|
|
891
|
+
class RestartEvent:
|
|
892
|
+
"""The executor started the task over, so discard the events before this one."""
|
|
893
|
+
|
|
894
|
+
type: Literal["restart"] = "restart"
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
@dataclass(frozen=True, kw_only=True)
|
|
898
|
+
class ActionsEvent:
|
|
899
|
+
"""What the requester's human must still do changed."""
|
|
900
|
+
|
|
901
|
+
actions: list[ProposalAction]
|
|
902
|
+
type: Literal["actions"] = "actions"
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
@dataclass(frozen=True, kw_only=True)
|
|
906
|
+
class CommitEvent:
|
|
907
|
+
"""The executor committed to an action it can't undo, so the task can no longer be canceled."""
|
|
908
|
+
|
|
909
|
+
type: Literal["commit"] = "commit"
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
TaskEvent: TypeAlias = (
|
|
913
|
+
UpdateEvent | DeltaEvent | ArtifactEvent | RestartEvent | ActionsEvent | CommitEvent
|
|
914
|
+
)
|
|
915
|
+
"""An event emitted by a delegated task, in the order the executor produced it."""
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
@dataclass(frozen=True, kw_only=True)
|
|
919
|
+
class Delegate:
|
|
920
|
+
"""An agent and skill a task hands work off to."""
|
|
921
|
+
|
|
922
|
+
agent: str
|
|
923
|
+
"""The address of the agent the skill delegates to, `username/agent-name`."""
|
|
924
|
+
skill: str
|
|
925
|
+
"""The skill of that agent it calls for."""
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
DelegatePicker: TypeAlias = Callable[
|
|
929
|
+
[Proposal, "Agent"], Awaitable[list[Delegate]] | list[Delegate]
|
|
930
|
+
]
|
|
931
|
+
"""Picks the agents and skills an accepted proposal's work will hand off to, such as from its `input`."""
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
@dataclass(frozen=True, kw_only=True)
|
|
935
|
+
class SkillHandler(Generic[InputT, OutputT]):
|
|
936
|
+
"""What this process runs for a skill stored on the relay: its triggers' code and its connections."""
|
|
937
|
+
|
|
938
|
+
name: str
|
|
939
|
+
triggers: Mapping[str, TriggerHandler] | None = None
|
|
940
|
+
"""The `on_schedule_active` of each of the skill's triggers, by trigger name."""
|
|
941
|
+
connections: Sequence[DeclaredConnection] | None = None
|
|
942
|
+
"""The connection behind each of the skill's providers."""
|
|
943
|
+
input: InputSchema[InputT] | None = None
|
|
944
|
+
"""The skill's input schema, which `connect()` checks matches the stored one."""
|
|
945
|
+
output: InputSchema[OutputT] | None = None
|
|
946
|
+
"""The skill's output schema, which `connect()` checks matches the stored one."""
|
|
947
|
+
delegates: list[Delegate] | DelegatePicker | None = None
|
|
948
|
+
"""The agents and skills the skill's tasks hand work off to, or a function picking them from each proposal."""
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
@dataclass(frozen=True, kw_only=True)
|
|
952
|
+
class Skill(SkillHandler[InputT, OutputT]):
|
|
953
|
+
"""A capability an agent advertises, matching the Agent Skills `SKILL.md` frontmatter."""
|
|
954
|
+
|
|
955
|
+
description: str
|
|
956
|
+
"""What the skill does, shown to requesters."""
|
|
957
|
+
price: Price | None = None
|
|
958
|
+
triggers: Mapping[str, Trigger] | None = None
|
|
959
|
+
"""Events that requesters can schedule this skill to run on, by trigger name."""
|
|
960
|
+
irreversible: bool = False
|
|
961
|
+
"""Set for skills whose tasks take an action that can't be undone. A task calls `commit()` before taking it."""
|
|
962
|
+
revisions: int | None = None
|
|
963
|
+
"""How many follow-ups of a completed task, from 1 to 10, a flat-priced skill runs for free."""
|
|
964
|
+
resumable: bool = False
|
|
965
|
+
"""Set for skills whose tasks another session of the agent can pick up when the one running them leaves."""
|