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.
Files changed (86) hide show
  1. agentjam/__init__.py +435 -0
  2. agentjam/_adapters/__init__.py +0 -0
  3. agentjam/_adapters/responses.py +73 -0
  4. agentjam/_adapters/shared.py +435 -0
  5. agentjam/_agent.py +1032 -0
  6. agentjam/_agent_access.py +360 -0
  7. agentjam/_agent_delegations.py +376 -0
  8. agentjam/_agent_executions.py +566 -0
  9. agentjam/_agent_judging.py +288 -0
  10. agentjam/_agent_options.py +122 -0
  11. agentjam/_agent_routing.py +214 -0
  12. agentjam/_agent_session.py +195 -0
  13. agentjam/_agent_support.py +415 -0
  14. agentjam/_artifacts.py +565 -0
  15. agentjam/_attachments.py +112 -0
  16. agentjam/_connections.py +1282 -0
  17. agentjam/_content.py +29 -0
  18. agentjam/_cron.py +302 -0
  19. agentjam/_errors.py +238 -0
  20. agentjam/_events.py +113 -0
  21. agentjam/_files.py +55 -0
  22. agentjam/_github.py +742 -0
  23. agentjam/_idempotency.py +68 -0
  24. agentjam/_inputs.py +79 -0
  25. agentjam/_models.py +21 -0
  26. agentjam/_polling.py +139 -0
  27. agentjam/_profile.py +244 -0
  28. agentjam/_protocol.py +480 -0
  29. agentjam/_providers.py +365 -0
  30. agentjam/_recaps.py +67 -0
  31. agentjam/_relay/__init__.py +0 -0
  32. agentjam/_relay/actions.py +234 -0
  33. agentjam/_relay/artifacts.py +96 -0
  34. agentjam/_relay/base.py +387 -0
  35. agentjam/_relay/commits.py +77 -0
  36. agentjam/_relay/copies.py +66 -0
  37. agentjam/_relay/credentials.py +127 -0
  38. agentjam/_relay/endpoints.py +39 -0
  39. agentjam/_relay/follow_ups.py +548 -0
  40. agentjam/_relay/frames.py +443 -0
  41. agentjam/_relay/guest_store.py +114 -0
  42. agentjam/_relay/guests.py +55 -0
  43. agentjam/_relay/inputs.py +119 -0
  44. agentjam/_relay/lineage.py +294 -0
  45. agentjam/_relay/memory.py +1045 -0
  46. agentjam/_relay/payments.py +204 -0
  47. agentjam/_relay/profiles.py +95 -0
  48. agentjam/_relay/remote.py +826 -0
  49. agentjam/_relay/resumptions.py +65 -0
  50. agentjam/_relay/revisions.py +43 -0
  51. agentjam/_relay/schedule_follow_ups.py +274 -0
  52. agentjam/_relay/schedules.py +547 -0
  53. agentjam/_relay/secrets.py +275 -0
  54. agentjam/_relay/sessions.py +640 -0
  55. agentjam/_relay/uploads.py +71 -0
  56. agentjam/_requests.py +178 -0
  57. agentjam/_screening.py +368 -0
  58. agentjam/_secrets.py +153 -0
  59. agentjam/_sentry.py +233 -0
  60. agentjam/_signals.py +98 -0
  61. agentjam/_slack.py +468 -0
  62. agentjam/_stripe.py +93 -0
  63. agentjam/_tasks/__init__.py +0 -0
  64. agentjam/_tasks/access.py +142 -0
  65. agentjam/_tasks/incoming.py +952 -0
  66. agentjam/_tasks/outgoing.py +472 -0
  67. agentjam/_tasks/scheduled.py +206 -0
  68. agentjam/_tasks/serial.py +40 -0
  69. agentjam/_tasks/triggers.py +258 -0
  70. agentjam/_tasks/watches.py +77 -0
  71. agentjam/_tools.py +1035 -0
  72. agentjam/_types.py +965 -0
  73. agentjam/_utils.py +75 -0
  74. agentjam/_verdicts.py +21 -0
  75. agentjam/_watermarks.py +59 -0
  76. agentjam/anthropic.py +442 -0
  77. agentjam/mpp.py +233 -0
  78. agentjam/openai.py +141 -0
  79. agentjam/openai_agents.py +253 -0
  80. agentjam/py.typed +0 -0
  81. agentjam/pydantic_ai.py +301 -0
  82. agentjam/skills.py +69 -0
  83. agentjam-0.1.0.dist-info/METADATA +210 -0
  84. agentjam-0.1.0.dist-info/RECORD +86 -0
  85. agentjam-0.1.0.dist-info/WHEEL +4 -0
  86. agentjam-0.1.0.dist-info/licenses/LICENSE +21 -0
agentjam/_protocol.py ADDED
@@ -0,0 +1,480 @@
1
+ from typing import Annotated, Any, Literal, TypeAlias
2
+
3
+ from pydantic import Field, TypeAdapter
4
+
5
+ from agentjam._models import WireModel
6
+ from agentjam._types import (
7
+ ActionOrigin,
8
+ Budget,
9
+ Cron,
10
+ FollowUp,
11
+ JsonObject,
12
+ Message,
13
+ ProposalAction,
14
+ ScheduleFollowUp,
15
+ TaskStatus,
16
+ TaskWatch,
17
+ TriggerChoice,
18
+ )
19
+
20
+ LimitCode = Literal[
21
+ "max_price_reached", "cap_reached", "insufficient_credits", "reload_failed"
22
+ ]
23
+ """Why a task's requester could fund no more of it, whether the relay canceled the task or refused its executor's commit."""
24
+
25
+ TaskEndCode = Literal[
26
+ "action_expired",
27
+ "connection_revoked",
28
+ "parent_ended",
29
+ "max_price_reached",
30
+ "cap_reached",
31
+ "insufficient_credits",
32
+ "reload_failed",
33
+ ]
34
+ """Why the relay ended a task itself, such as once the task it was part of ended."""
35
+
36
+ ScheduleEndCode = Literal[
37
+ "expired", "payment_failed", "connection_revoked", "action_expired"
38
+ ]
39
+
40
+ RELAY_FIELDS = frozenset({"sender", "history", "task", "previous"})
41
+
42
+
43
+ class CopiedAction(ProposalAction):
44
+ """An action of a task further down a chain, copied onto each of the open tasks above it."""
45
+
46
+ status: Literal["pending", "completed"]
47
+ origin: ActionOrigin
48
+
49
+
50
+ class AttachmentRef(WireModel):
51
+ """A file attached to a proposal or message. Senders name only the upload, and relays fill in the rest."""
52
+
53
+ attachment_id: str
54
+ name: str | None = None
55
+ mime_type: str | None = None
56
+ size: int | None = None
57
+ url: str | None = None
58
+ """Where to download the file, until the link expires."""
59
+
60
+
61
+ class TaskRef(WireModel):
62
+ """A task by its requester and id, such as the one a proposal is part of."""
63
+
64
+ requester: str
65
+ task_id: str
66
+
67
+
68
+ class RecappedArtifactRef(WireModel):
69
+ """The latest artifact under each key of an earlier task, as a relay recaps it."""
70
+
71
+ artifact_id: str
72
+ kind: Literal["text", "file"]
73
+ name: str | None = None
74
+ mime_type: str | None = None
75
+ key: str | None = None
76
+ text: str | None = None
77
+ truncated: bool | None = None
78
+ url: str | None = None
79
+ size: int | None = None
80
+
81
+
82
+ class TaskRecapRef(WireModel):
83
+ """What an earlier task asked for and produced, as a relay recaps it for the task's executor."""
84
+
85
+ task_id: str
86
+ requester: str
87
+ text: str
88
+ skill: str | None = None
89
+ input: JsonObject | None = None
90
+ attachments: list[AttachmentRef] | None = None
91
+ status: TaskStatus
92
+ error: str | None = None
93
+ updates: list[str]
94
+ artifacts: list[RecappedArtifactRef]
95
+ history: list[Message]
96
+ follow_up: FollowUp | None = None
97
+ created_at: str
98
+ ended_at: str | None = None
99
+
100
+
101
+ class ParentRef(WireModel):
102
+ """What a proposal is part of: the task its sender works on, or the pending schedule a preparation answers."""
103
+
104
+ kind: Literal["task", "schedule"]
105
+ requester: str
106
+ id: str
107
+
108
+
109
+ class DelegatedTask(WireModel):
110
+ """A task delegated to another agent: the agent running it and the task's id."""
111
+
112
+ to: str
113
+ id: str
114
+
115
+
116
+ class Unaddressed(WireModel):
117
+ """Invariant: `id` is the sender's idempotency key, so a repeated `id` from one sender is the same envelope."""
118
+
119
+ id: str
120
+ sender: str = Field(default="", alias="from")
121
+
122
+ def to_wire(self) -> dict[str, Any]:
123
+ """Returns the envelope as JSON-ready data, leaving out the fields relays stamp while they're unset."""
124
+ unset = {name for name in RELAY_FIELDS if not getattr(self, name, None)}
125
+
126
+ return self.model_dump(mode="json", exclude_none=True, exclude=unset)
127
+
128
+
129
+ class Routed(Unaddressed):
130
+ """An envelope addressed `to` an agent. Relays stamp `sender` on every envelope they deliver."""
131
+
132
+ to: str
133
+
134
+
135
+ class MessageEnvelope(Routed):
136
+ type: Literal["message"] = "message"
137
+ conversation_id: str
138
+ task_id: str | None = None
139
+ text: str
140
+ attachments: list[AttachmentRef] | None = None
141
+ steer: Literal[True] | None = None
142
+ history: list[Message] = Field(default_factory=list)
143
+ task: TaskRecapRef | None = None
144
+
145
+
146
+ class ReplyEnvelope(Routed):
147
+ type: Literal["reply"] = "reply"
148
+ reply_to: str
149
+ text: str
150
+ attachments: list[AttachmentRef] | None = None
151
+
152
+
153
+ class ErrorEnvelope(Routed):
154
+ type: Literal["error"] = "error"
155
+ reply_to: str
156
+ error: str
157
+
158
+
159
+ class ProposeEnvelope(Routed):
160
+ type: Literal["task.propose"] = "task.propose"
161
+ text: str
162
+ skill: str | None = None
163
+ input: JsonObject | None = None
164
+ max_price_cents: int | float | None = None
165
+ cron: Cron | None = None
166
+ trigger: TriggerChoice | None = None
167
+ budget: Budget | None = None
168
+ then: ScheduleFollowUp | None = None
169
+ expires_at: str | None = None
170
+ watch: TaskWatch | None = None
171
+ attachments: list[AttachmentRef] | None = None
172
+ held_cents: int | float | None = None
173
+ parent: ParentRef | None = None
174
+ prepare: Literal[True] | None = None
175
+ principal: str | None = None
176
+ follows: str | None = None
177
+ previous: TaskRecapRef | None = None
178
+ resumed: Literal[True] | None = None
179
+ attempt: int | None = None
180
+ children: list[DelegatedTask] | None = None
181
+
182
+
183
+ class AcceptEnvelope(Routed):
184
+ type: Literal["task.accept"] = "task.accept"
185
+ reply_to: str
186
+
187
+
188
+ class RequireEnvelope(Routed):
189
+ type: Literal["task.require"] = "task.require"
190
+ reply_to: str
191
+ actions: list[ProposalAction]
192
+
193
+
194
+ class RejectEnvelope(Routed):
195
+ type: Literal["task.reject"] = "task.reject"
196
+ reply_to: str
197
+ reason: str
198
+
199
+
200
+ class UpdateEnvelope(Routed):
201
+ type: Literal["task.update"] = "task.update"
202
+ task_id: str
203
+ text: str
204
+
205
+
206
+ class ArtifactEnvelope(Routed):
207
+ type: Literal["task.artifact"] = "task.artifact"
208
+ task_id: str
209
+ artifact_id: str
210
+ kind: Literal["text", "file"]
211
+ name: str | None = None
212
+ mime_type: str | None = None
213
+ key: str | None = None
214
+ revision: int | None = None
215
+ chunk: str
216
+ last: bool
217
+ upload_id: str | None = None
218
+ url: str | None = None
219
+
220
+
221
+ class CommitEnvelope(Routed):
222
+ type: Literal["task.commit"] = "task.commit"
223
+ task_id: str
224
+ cost_cents: int | float | None = None
225
+
226
+
227
+ class CompleteEnvelope(Routed):
228
+ type: Literal["task.complete"] = "task.complete"
229
+ task_id: str
230
+ cost_cents: int | float | None = None
231
+ output: JsonObject | None = None
232
+ charged_cents: int | float | None = None
233
+
234
+
235
+ class FailEnvelope(Routed):
236
+ type: Literal["task.fail"] = "task.fail"
237
+ task_id: str
238
+ error: str
239
+ code: TaskEndCode | None = None
240
+ uncovered: LimitCode | None = None
241
+ charged_cents: int | float | None = None
242
+
243
+
244
+ class CancelEnvelope(Routed):
245
+ type: Literal["task.cancel"] = "task.cancel"
246
+ task_id: str
247
+ reason: str | None = None
248
+ code: TaskEndCode | None = None
249
+
250
+
251
+ class BudgetEnvelope(Routed):
252
+ type: Literal["task.budget"] = "task.budget"
253
+ task_id: str
254
+ held_cents: int | float
255
+
256
+
257
+ class ActionsEnvelope(Routed):
258
+ type: Literal["task.actions"] = "task.actions"
259
+ task_id: str
260
+ actions: list[CopiedAction]
261
+
262
+
263
+ class DisconnectEnvelope(Routed):
264
+ type: Literal["disconnect"] = "disconnect"
265
+ abandoned: list[str] | None = None
266
+
267
+
268
+ class ScheduleEndEnvelope(Routed):
269
+ type: Literal["schedule.end"] = "schedule.end"
270
+ schedule_id: str
271
+ reason: str | None = None
272
+ code: ScheduleEndCode | None = None
273
+
274
+
275
+ class ConnectionReadyEnvelope(Routed):
276
+ type: Literal["connection.ready"] = "connection.ready"
277
+ proposal_id: str
278
+ provider: str
279
+ origin: ActionOrigin | None = None
280
+
281
+
282
+ class ConnectionRequiredEnvelope(Routed):
283
+ type: Literal["connection.required"] = "connection.required"
284
+ proposal_id: str
285
+ provider: str
286
+ url: str
287
+ reason: str
288
+
289
+
290
+ class ConnectionRevokedEnvelope(Routed):
291
+ type: Literal["connection.revoked"] = "connection.revoked"
292
+ provider: str
293
+ principal: str
294
+ reason: str | None = None
295
+
296
+
297
+ class ConnectionStoredEnvelope(Routed):
298
+ type: Literal["connection.stored"] = "connection.stored"
299
+ proposal_id: str
300
+ principal: str
301
+ provider: str
302
+
303
+
304
+ class ScheduleStartEnvelope(Routed):
305
+ type: Literal["schedule.start"] = "schedule.start"
306
+ schedule_id: str
307
+ principal: str | None = None
308
+ text: str
309
+ skill: str
310
+ trigger: str
311
+ config: dict[str, Any]
312
+ input: JsonObject | None = None
313
+ expires_at: str | None = None
314
+ attachments: list[AttachmentRef] | None = None
315
+
316
+
317
+ class ScheduleHandoverEnvelope(Routed):
318
+ type: Literal["schedule.handover"] = "schedule.handover"
319
+ schedule_id: str
320
+
321
+
322
+ class TriggerFailedEnvelope(Routed):
323
+ type: Literal["trigger.failed"] = "trigger.failed"
324
+ schedule_id: str
325
+ event_id: str
326
+ error: str
327
+
328
+
329
+ class FollowUpEnvelope(Routed):
330
+ """Invariant: exactly one of `task_id` and `error` is set."""
331
+
332
+ type: Literal["schedule.followup"] = "schedule.followup"
333
+ schedule_id: str
334
+ run_id: str
335
+ skill: str
336
+ task_id: str | None = None
337
+ error: str | None = None
338
+
339
+
340
+ class RecurEnvelope(Routed):
341
+ type: Literal["task.recur"] = "task.recur"
342
+ schedule_id: str
343
+ task_id: str
344
+ run: int
345
+ principal: str | None = None
346
+ text: str
347
+ skill: str | None = None
348
+ input: JsonObject | None = None
349
+ event_id: str | None = None
350
+ summary: str | None = None
351
+ event_data: JsonObject | None = None
352
+ attachments: list[AttachmentRef] | None = None
353
+ held_cents: int | float | None = None
354
+
355
+
356
+ class CollectDraft(Routed):
357
+ type: Literal["collect"] = "collect"
358
+ schedule_id: str
359
+ task_id: str | None = None
360
+
361
+
362
+ class TriggerFireDraft(Routed):
363
+ type: Literal["trigger.fire"] = "trigger.fire"
364
+ schedule_id: str
365
+ event_id: str
366
+ summary: str
367
+ data: JsonObject | None = None
368
+
369
+
370
+ class TriggerSubscribeDraft(Routed):
371
+ type: Literal["trigger.subscribe"] = "trigger.subscribe"
372
+ schedule_id: str
373
+ event_keys: list[str]
374
+
375
+
376
+ class TriggerStoppedDraft(Routed):
377
+ type: Literal["trigger.stopped"] = "trigger.stopped"
378
+ schedule_id: str
379
+
380
+
381
+ class ReattachDraft(Routed):
382
+ type: Literal["task.reattach"] = "task.reattach"
383
+ task_id: str
384
+
385
+
386
+ class CostDraft(Routed):
387
+ type: Literal["task.cost"] = "task.cost"
388
+ task_id: str
389
+ cost_cents: int | float
390
+
391
+
392
+ class DispatchDraft(Unaddressed):
393
+ type: Literal["trigger.dispatch"] = "trigger.dispatch"
394
+ event_keys: list[str]
395
+ event_id: str
396
+ summary: str
397
+ data: JsonObject | None = None
398
+
399
+
400
+ class DrainDraft(Unaddressed):
401
+ type: Literal["session.drain"] = "session.drain"
402
+
403
+
404
+ DeliveredEnvelope: TypeAlias = (
405
+ MessageEnvelope
406
+ | ReplyEnvelope
407
+ | ErrorEnvelope
408
+ | ProposeEnvelope
409
+ | AcceptEnvelope
410
+ | RequireEnvelope
411
+ | RejectEnvelope
412
+ | UpdateEnvelope
413
+ | ArtifactEnvelope
414
+ | CommitEnvelope
415
+ | CompleteEnvelope
416
+ | FailEnvelope
417
+ | CancelEnvelope
418
+ | BudgetEnvelope
419
+ | ActionsEnvelope
420
+ | DisconnectEnvelope
421
+ | ScheduleEndEnvelope
422
+ | ConnectionReadyEnvelope
423
+ | ConnectionRequiredEnvelope
424
+ | ConnectionRevokedEnvelope
425
+ | ConnectionStoredEnvelope
426
+ | ScheduleStartEnvelope
427
+ | ScheduleHandoverEnvelope
428
+ | TriggerFailedEnvelope
429
+ | FollowUpEnvelope
430
+ | RecurEnvelope
431
+ )
432
+
433
+ RelayDraft: TypeAlias = (
434
+ CollectDraft
435
+ | TriggerFireDraft
436
+ | TriggerSubscribeDraft
437
+ | TriggerStoppedDraft
438
+ | ReattachDraft
439
+ | CostDraft
440
+ )
441
+
442
+ AddressedDraft: TypeAlias = DeliveredEnvelope | RelayDraft
443
+ """A draft addressed `to` another agent, which every draft but a dispatch or drain is."""
444
+
445
+ Envelope = Annotated[DeliveredEnvelope, Field(discriminator="type")]
446
+ """A single frame on the wire between two agents.
447
+
448
+ Relays stamp `sender` on every envelope and attach `history` to messages, and otherwise deliver envelopes
449
+ unchanged, in per-sender order. Invariant: every envelope is JSON-serializable.
450
+ """
451
+
452
+ EnvelopeDraft = Annotated[
453
+ DeliveredEnvelope | RelayDraft | DispatchDraft | DrainDraft,
454
+ Field(discriminator="type"),
455
+ ]
456
+ """An envelope as an agent sends it, before the relay stamps `sender` and attaches `history` and recaps."""
457
+
458
+ TaskEnvelope: TypeAlias = (
459
+ UpdateEnvelope | ArtifactEnvelope | CommitEnvelope | CompleteEnvelope | FailEnvelope
460
+ )
461
+
462
+ Reply: TypeAlias = (
463
+ ReplyEnvelope | ErrorEnvelope | AcceptEnvelope | RequireEnvelope | RejectEnvelope
464
+ )
465
+ """An envelope answering an earlier request, identified by `reply_to`."""
466
+
467
+ envelope_adapter: TypeAdapter[DeliveredEnvelope] = TypeAdapter(Envelope)
468
+ draft_adapter: TypeAdapter[
469
+ DeliveredEnvelope | RelayDraft | DispatchDraft | DrainDraft
470
+ ] = TypeAdapter(EnvelopeDraft)
471
+
472
+
473
+ def parse_envelope(data: Any) -> DeliveredEnvelope:
474
+ return envelope_adapter.validate_python(data)
475
+
476
+
477
+ def parse_draft(
478
+ data: Any,
479
+ ) -> DeliveredEnvelope | RelayDraft | DispatchDraft | DrainDraft:
480
+ return draft_adapter.validate_python(data)