agentjam 0.3.0__tar.gz → 0.4.0__tar.gz
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-0.3.0 → agentjam-0.4.0}/PKG-INFO +15 -1
- {agentjam-0.3.0 → agentjam-0.4.0}/README.md +14 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/pyproject.toml +1 -1
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/__init__.py +4 -1
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent.py +6 -1
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_delegations.py +48 -21
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_executions.py +18 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_support.py +1 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_inputs.py +12 -1
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_profile.py +14 -8
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_protocol.py +18 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/memory.py +38 -8
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/schedules.py +5 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/sessions.py +11 -0
- agentjam-0.4.0/src/agentjam/_relay/subscriptions.py +162 -0
- agentjam-0.4.0/src/agentjam/_subscriptions.py +47 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/incoming.py +69 -2
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/outgoing.py +51 -1
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/scheduled.py +45 -1
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tools/network.py +25 -6
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tools/schedules.py +35 -2
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tools/shared.py +1 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_types.py +33 -7
- {agentjam-0.3.0 → agentjam-0.4.0}/.gitignore +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/LICENSE +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_adapters/__init__.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_adapters/responses.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_adapters/shared.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_access.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_judging.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_options.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_routing.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_agent_session.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_any_of.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_artifacts.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_attachments.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_backoff.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_base_error.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_chooser.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_connections.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_content.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_cron.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_datadog_alerts.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_discord.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_discord_events.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_discord_gateway.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_discord_interactions.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_downloads.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_errors.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_events.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_files.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_github.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_github_api.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_github_events.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_google.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_grafana_alerts.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_idempotency.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_managed_webhooks.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_microsoft.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_models.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_oauth_callbacks.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_pagerduty_incidents.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_pages.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_polling.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_presets.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_providers.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_recaps.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/__init__.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/base.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/chains.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/credentials.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/endpoints.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/frames.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/grants.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/guest_store.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/guests.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/links.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/payments.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/profiles.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/remote.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/revisions.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/secrets.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_relay/uploads.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_requests.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_screening.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_secrets.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_sentry.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_sentry_api.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_sentry_events.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_signals.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_slack.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_slack_events.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_slack_interactions.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_storage.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_stripe.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/__init__.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/access.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/serial.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/triggers.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tasks/watches.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tools/__init__.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tools/delegations.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_tools/inputs.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_utils.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_vaults/__init__.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_vaults/local.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_vaults/remote.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_vaults/vault.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_verdicts.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/_watermarks.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/anthropic.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/atlassian.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/datadog.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/discord.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/github.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/google.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/grafana.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/microsoft.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/mpp.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/oauth.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/openai.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/openai_agents.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/pagerduty.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/posthog.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/py.typed +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/pydantic_ai.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/sentry.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/skills.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/slack.py +0 -0
- {agentjam-0.3.0 → agentjam-0.4.0}/src/agentjam/splunk.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: agentjam
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Allow your agents to discover, message, and delegate tasks to any other agent over AgentJam.
|
|
5
5
|
Project-URL: Homepage, https://agentjam.com
|
|
6
6
|
License-Expression: MIT
|
|
@@ -174,6 +174,20 @@ async for run in scan.runs():
|
|
|
174
174
|
print(await run.result())
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
+
### Subscriptions
|
|
178
|
+
|
|
179
|
+
A skill can subscribe each task's requester to a trigger of another of its agent's skills, such as a forum agent that posts for you and then sends you the post's replies. The executor calls `task.subscribe(config)` before the task completes, and the requester gets a run for each event until the subscription expires or either side ends it.
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
post = await agent.propose("ada/forum", "Lisbon ramen tips?", skill="create-post")
|
|
183
|
+
|
|
184
|
+
replies = await post.get_subscription()
|
|
185
|
+
async for reply in replies.runs():
|
|
186
|
+
print(reply.event.summary)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Pass `subscribe=False` to `propose()` to take the task without the subscription. A subscription to a priced skill charges each run at that skill's price until it expires or is ended, and a skill whose `subscribes` is `optional` may complete a task without starting one, such as when there's nothing left to watch.
|
|
190
|
+
|
|
177
191
|
### Earn from your skills
|
|
178
192
|
|
|
179
193
|
Put a price on a skill, and every agent on the network can pay to use it. Charge a flat price per task, or your costs plus a markup for metered work. Requesters pay from their AgentJam Wallet, and once you set up payouts, your earnings are paid out to you.
|
|
@@ -132,6 +132,20 @@ async for run in scan.runs():
|
|
|
132
132
|
print(await run.result())
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
### Subscriptions
|
|
136
|
+
|
|
137
|
+
A skill can subscribe each task's requester to a trigger of another of its agent's skills, such as a forum agent that posts for you and then sends you the post's replies. The executor calls `task.subscribe(config)` before the task completes, and the requester gets a run for each event until the subscription expires or either side ends it.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
post = await agent.propose("ada/forum", "Lisbon ramen tips?", skill="create-post")
|
|
141
|
+
|
|
142
|
+
replies = await post.get_subscription()
|
|
143
|
+
async for reply in replies.runs():
|
|
144
|
+
print(reply.event.summary)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Pass `subscribe=False` to `propose()` to take the task without the subscription. A subscription to a priced skill charges each run at that skill's price until it expires or is ended, and a skill whose `subscribes` is `optional` may complete a task without starting one, such as when there's nothing left to watch.
|
|
148
|
+
|
|
135
149
|
### Earn from your skills
|
|
136
150
|
|
|
137
151
|
Put a price on a skill, and every agent on the network can pay to use it. Charge a flat price per task, or your costs plus a markup for metered work. Requesters pay from their AgentJam Wallet, and once you set up payouts, your earnings are paid out to you.
|
|
@@ -130,7 +130,7 @@ from agentjam._secrets import secret_connection
|
|
|
130
130
|
from agentjam._tasks.access import AccessOptions
|
|
131
131
|
from agentjam._tasks.incoming import IncomingTask, TaskOutput, current_task
|
|
132
132
|
from agentjam._tasks.outgoing import OutgoingTask
|
|
133
|
-
from agentjam._tasks.scheduled import Schedule
|
|
133
|
+
from agentjam._tasks.scheduled import Schedule, Subscription
|
|
134
134
|
from agentjam._tools.shared import NetworkTool, ToolName, ToolResult, network_tool_names
|
|
135
135
|
from agentjam._types import (
|
|
136
136
|
Account,
|
|
@@ -202,6 +202,7 @@ from agentjam._types import (
|
|
|
202
202
|
SkillCard,
|
|
203
203
|
SkillConnection,
|
|
204
204
|
SkillHandler,
|
|
205
|
+
SkillSubscription,
|
|
205
206
|
StopReason,
|
|
206
207
|
StoredAgent,
|
|
207
208
|
TaskEvent,
|
|
@@ -396,12 +397,14 @@ __all__ = [
|
|
|
396
397
|
"SkillConnection",
|
|
397
398
|
"SkillHandler",
|
|
398
399
|
"SkillRequiredError",
|
|
400
|
+
"SkillSubscription",
|
|
399
401
|
"SourceDelivery",
|
|
400
402
|
"SourceEvent",
|
|
401
403
|
"SourceRequest",
|
|
402
404
|
"SourceResponse",
|
|
403
405
|
"StopReason",
|
|
404
406
|
"StoredAgent",
|
|
407
|
+
"Subscription",
|
|
405
408
|
"SubtaskView",
|
|
406
409
|
"TaskCanceledError",
|
|
407
410
|
"TaskCommittedError",
|
|
@@ -433,6 +433,7 @@ class Agent:
|
|
|
433
433
|
watch: TaskWatch | None = None,
|
|
434
434
|
attachments: Sequence[AttachmentSource] | None = None,
|
|
435
435
|
follows: str | None = None,
|
|
436
|
+
subscribe: bool = True,
|
|
436
437
|
timeout: float | None = None,
|
|
437
438
|
idempotency_key: str | None = None,
|
|
438
439
|
) -> OutgoingTask:
|
|
@@ -450,6 +451,7 @@ class Agent:
|
|
|
450
451
|
watch: Reports the task's outcome to `on_watch_resolved`, alone when True, or with the group a string names.
|
|
451
452
|
attachments: Files to attach.
|
|
452
453
|
follows: The id of an ended task this agent delegated to `to` that this task follows up on.
|
|
454
|
+
subscribe: Whether to take the subscription a skill with `subscribes` starts once the task completes.
|
|
453
455
|
timeout: How many seconds to wait for the agent to accept. Defaults to the agent's timeout.
|
|
454
456
|
idempotency_key: Identifies the proposal, so a retry isn't proposed twice. Defaults to a new one.
|
|
455
457
|
Returns:
|
|
@@ -480,6 +482,7 @@ class Agent:
|
|
|
480
482
|
attachments=refs,
|
|
481
483
|
parent=parent,
|
|
482
484
|
follows=follows,
|
|
485
|
+
subscribe=None if subscribe else False,
|
|
483
486
|
)
|
|
484
487
|
|
|
485
488
|
def adopt(reply: Reply) -> OutgoingTask:
|
|
@@ -573,7 +576,9 @@ class Agent:
|
|
|
573
576
|
if parent is None:
|
|
574
577
|
self._delegations.require(to, verdict)
|
|
575
578
|
|
|
576
|
-
return self._delegations.follow(
|
|
579
|
+
return self._delegations.follow(
|
|
580
|
+
to, key, list_actions(verdict), parent, expires_at=expires_at
|
|
581
|
+
)
|
|
577
582
|
|
|
578
583
|
self._delegations.begin_scheduling(to, key)
|
|
579
584
|
response = self._requests.start(draft, adopt, timeout=timeout)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
from collections.abc import Awaitable, Callable, Coroutine, Sequence, Set
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
+
from datetime import datetime
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
6
7
|
from agentjam._agent_support import compute_key, construct_event, is_run, list_actions
|
|
@@ -28,8 +29,14 @@ from agentjam._protocol import (
|
|
|
28
29
|
)
|
|
29
30
|
from agentjam._relay.base import Draft
|
|
30
31
|
from agentjam._tasks.incoming import TaskSender
|
|
31
|
-
from agentjam._tasks.outgoing import
|
|
32
|
-
|
|
32
|
+
from agentjam._tasks.outgoing import (
|
|
33
|
+
OutgoingTask,
|
|
34
|
+
RunDetails,
|
|
35
|
+
SubscriptionDetails,
|
|
36
|
+
TaskHandle,
|
|
37
|
+
TaskLink,
|
|
38
|
+
)
|
|
39
|
+
from agentjam._tasks.scheduled import ScheduleHandle, ScheduleLink, SubscriptionHandle
|
|
33
40
|
from agentjam._types import ActionRequest, ProposalAction
|
|
34
41
|
from agentjam._utils import create_id, spawn
|
|
35
42
|
|
|
@@ -91,6 +98,11 @@ class Delegations:
|
|
|
91
98
|
def release() -> None:
|
|
92
99
|
self._outgoing.pop(id, None)
|
|
93
100
|
|
|
101
|
+
def follow(
|
|
102
|
+
schedule_id: str, details: SubscriptionDetails
|
|
103
|
+
) -> SubscriptionHandle:
|
|
104
|
+
return self.follow_subscription(to, schedule_id, details)
|
|
105
|
+
|
|
94
106
|
handle = TaskHandle(
|
|
95
107
|
task_id,
|
|
96
108
|
to,
|
|
@@ -100,6 +112,7 @@ class Delegations:
|
|
|
100
112
|
send=self._link.send_about(to, task_id),
|
|
101
113
|
release=release,
|
|
102
114
|
construct_assembler=lambda: self._link.construct_assembler(task_id),
|
|
115
|
+
follow=follow,
|
|
103
116
|
),
|
|
104
117
|
run=run,
|
|
105
118
|
parent=parent,
|
|
@@ -133,10 +146,34 @@ class Delegations:
|
|
|
133
146
|
schedule_id: str,
|
|
134
147
|
actions: list[ProposalAction],
|
|
135
148
|
parent: ParentRef | None = None,
|
|
149
|
+
*,
|
|
150
|
+
expires_at: datetime | None = None,
|
|
136
151
|
) -> ScheduleHandle:
|
|
137
152
|
"""Follows the accepted schedule `schedule_id` delegated to `to`."""
|
|
138
|
-
|
|
153
|
+
link = self._construct_schedule_link(to, schedule_id)
|
|
154
|
+
schedule = ScheduleHandle(
|
|
155
|
+
schedule_id, to, link, actions, parent, expires_at=expires_at
|
|
156
|
+
)
|
|
157
|
+
self.schedules[compute_key(to, schedule_id)] = schedule
|
|
158
|
+
|
|
159
|
+
return schedule
|
|
160
|
+
|
|
161
|
+
def follow_subscription(
|
|
162
|
+
self, to: str, schedule_id: str, details: SubscriptionDetails
|
|
163
|
+
) -> SubscriptionHandle:
|
|
164
|
+
"""Follows the subscription a delegated task started, handing its runs to `on_run` unless a reader takes them right away."""
|
|
165
|
+
existing = self.schedules.get(compute_key(to, schedule_id))
|
|
166
|
+
if isinstance(existing, SubscriptionHandle):
|
|
167
|
+
return existing
|
|
168
|
+
|
|
169
|
+
link = self._construct_schedule_link(to, schedule_id)
|
|
170
|
+
subscription = SubscriptionHandle(schedule_id, to, link, details)
|
|
171
|
+
self.schedules[compute_key(to, schedule_id)] = subscription
|
|
172
|
+
asyncio.get_running_loop().call_soon(subscription.stop_holding)
|
|
139
173
|
|
|
174
|
+
return subscription
|
|
175
|
+
|
|
176
|
+
def _construct_schedule_link(self, to: str, schedule_id: str) -> ScheduleLink:
|
|
140
177
|
def collect(run: OutgoingTask, handled: Awaitable[None]) -> None:
|
|
141
178
|
self.collect_after(run, schedule_id, handled)
|
|
142
179
|
|
|
@@ -144,26 +181,16 @@ class Delegations:
|
|
|
144
181
|
self.hand_run(run, schedule_id)
|
|
145
182
|
|
|
146
183
|
def release() -> None:
|
|
147
|
-
self.schedules.pop(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
hand_run=hand_run,
|
|
156
|
-
hand_follow_up=self.hand_follow_up,
|
|
157
|
-
release=release,
|
|
158
|
-
),
|
|
159
|
-
actions,
|
|
160
|
-
parent,
|
|
184
|
+
self.schedules.pop(compute_key(to, schedule_id), None)
|
|
185
|
+
|
|
186
|
+
return ScheduleLink(
|
|
187
|
+
post=self._link.post,
|
|
188
|
+
collect=collect,
|
|
189
|
+
hand_run=hand_run,
|
|
190
|
+
hand_follow_up=self.hand_follow_up,
|
|
191
|
+
release=release,
|
|
161
192
|
)
|
|
162
193
|
|
|
163
|
-
self.schedules[id] = schedule
|
|
164
|
-
|
|
165
|
-
return schedule
|
|
166
|
-
|
|
167
194
|
async def end_schedule(
|
|
168
195
|
self, to: str, schedule_id: str, reason: str | None = None
|
|
169
196
|
) -> None:
|
|
@@ -67,6 +67,7 @@ from agentjam._types import (
|
|
|
67
67
|
IncomingMessage,
|
|
68
68
|
Price,
|
|
69
69
|
SkillCard,
|
|
70
|
+
TriggerCard,
|
|
70
71
|
)
|
|
71
72
|
from agentjam._utils import create_id, resolve_value, spawn
|
|
72
73
|
|
|
@@ -256,6 +257,8 @@ class Executions:
|
|
|
256
257
|
is_self=proposal.sender == self._agent.name,
|
|
257
258
|
held_cents=proposal.held_cents,
|
|
258
259
|
resumable=not proposal.prepare and self._is_resumable(proposal.skill),
|
|
260
|
+
subscribed_trigger=self._find_subscribed_trigger(proposal.skill),
|
|
261
|
+
is_opted_out=proposal.subscribe is False,
|
|
259
262
|
access=self._access.construct_access(proposal.skill, holder),
|
|
260
263
|
),
|
|
261
264
|
self._construct_link(proposal, holder),
|
|
@@ -337,6 +340,8 @@ class Executions:
|
|
|
337
340
|
is_self=proposal.sender == self._agent.name,
|
|
338
341
|
held_cents=proposal.held_cents,
|
|
339
342
|
resumable=True,
|
|
343
|
+
subscribed_trigger=self._find_subscribed_trigger(proposal.skill),
|
|
344
|
+
is_opted_out=proposal.subscribe is False,
|
|
340
345
|
access=self._access.construct_access(proposal.skill, holder),
|
|
341
346
|
),
|
|
342
347
|
self._construct_link(proposal, holder),
|
|
@@ -578,6 +583,19 @@ class Executions:
|
|
|
578
583
|
(card for card in self._agent.card.skills if card.name == skill), None
|
|
579
584
|
)
|
|
580
585
|
|
|
586
|
+
def _find_subscribed_trigger(self, skill: str | None) -> TriggerCard | None:
|
|
587
|
+
card = self._find_skill_card(skill)
|
|
588
|
+
subscribes = None if card is None else card.subscribes
|
|
589
|
+
if subscribes is None:
|
|
590
|
+
return None
|
|
591
|
+
|
|
592
|
+
target = self._find_skill_card(subscribes.skill)
|
|
593
|
+
triggers = [] if target is None else target.triggers or []
|
|
594
|
+
|
|
595
|
+
return next(
|
|
596
|
+
(each for each in triggers if each.name == subscribes.trigger), None
|
|
597
|
+
)
|
|
598
|
+
|
|
581
599
|
def _is_resumable(self, skill: str | None) -> bool:
|
|
582
600
|
card = self._find_skill_card(skill)
|
|
583
601
|
|
|
@@ -10,7 +10,7 @@ from pydantic import TypeAdapter, ValidationError
|
|
|
10
10
|
from pydantic_core import ErrorDetails
|
|
11
11
|
|
|
12
12
|
from agentjam._errors import AgentJamError
|
|
13
|
-
from agentjam._types import InputSchema, JsonObject, JsonSchema, SkillCard
|
|
13
|
+
from agentjam._types import InputSchema, JsonObject, JsonSchema, SkillCard, TriggerCard
|
|
14
14
|
|
|
15
15
|
SchemaField = Literal["input", "output"]
|
|
16
16
|
"""Which of a skill's values a schema describes: its tasks' input or their output."""
|
|
@@ -172,3 +172,14 @@ def output_problem(output: JsonObject | None, skill: SkillCard | None) -> str |
|
|
|
172
172
|
return None
|
|
173
173
|
|
|
174
174
|
return f'Output for the "{skill.name}" skill doesn\'t match its schema: {problem}'
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def config_problem(trigger: TriggerCard, config: dict[str, Any]) -> str | None:
|
|
178
|
+
"""Describes why a subscription's config doesn't match the schema of the trigger it subscribes to."""
|
|
179
|
+
problem = find_value_problem(trigger.config, config, "config")
|
|
180
|
+
if problem is None:
|
|
181
|
+
return None
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
f'Config for the "{trigger.name}" trigger doesn\'t match its schema: {problem}'
|
|
185
|
+
)
|
|
@@ -10,6 +10,7 @@ from agentjam._errors import AgentExistsError
|
|
|
10
10
|
from agentjam._inputs import to_json_schema
|
|
11
11
|
from agentjam._relay.base import Relay
|
|
12
12
|
from agentjam._relay.payments import Payments
|
|
13
|
+
from agentjam._subscriptions import assert_subscriptions
|
|
13
14
|
from agentjam._types import (
|
|
14
15
|
AgentCard,
|
|
15
16
|
ConnectionCard,
|
|
@@ -76,6 +77,11 @@ def construct_skill_card(skill: Skill[Any, Any]) -> SkillCard:
|
|
|
76
77
|
resumable=skill.resumable or None,
|
|
77
78
|
triggers=triggers,
|
|
78
79
|
connections=connections,
|
|
80
|
+
subscribes=None
|
|
81
|
+
if skill.subscribes is None
|
|
82
|
+
else skill.subscribes.model_copy(
|
|
83
|
+
update={"optional": skill.subscribes.optional or None}
|
|
84
|
+
),
|
|
79
85
|
input_schema=None
|
|
80
86
|
if skill.input is None
|
|
81
87
|
else to_json_schema(skill.name, "input", skill.input),
|
|
@@ -90,13 +96,11 @@ def construct_update(
|
|
|
90
96
|
skills: Sequence[Skill[Any, Any]] | None,
|
|
91
97
|
visibility: Visibility | None,
|
|
92
98
|
) -> ProfileUpdate:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
visibility=visibility,
|
|
99
|
-
)
|
|
99
|
+
cards = None if skills is None else [construct_skill_card(each) for each in skills]
|
|
100
|
+
if cards is not None:
|
|
101
|
+
assert_subscriptions(cards)
|
|
102
|
+
|
|
103
|
+
return ProfileUpdate(description=description, skills=cards, visibility=visibility)
|
|
100
104
|
|
|
101
105
|
|
|
102
106
|
def warn_created(name: str, claim_url: str) -> None:
|
|
@@ -190,6 +194,7 @@ async def create(
|
|
|
190
194
|
A handle to connect the agent with.
|
|
191
195
|
Raises:
|
|
192
196
|
AgentExistsError: If an agent with that name exists and `upsert` isn't set.
|
|
197
|
+
AgentJamError: If a skill's `subscribes` doesn't name a trigger of another of its skills without connections.
|
|
193
198
|
"""
|
|
194
199
|
relay = construct_network(api_key=api_key, network=network, payments=payments)
|
|
195
200
|
update = construct_update(description, skills, visibility)
|
|
@@ -242,7 +247,8 @@ async def update(
|
|
|
242
247
|
Returns:
|
|
243
248
|
A handle to connect the agent with.
|
|
244
249
|
Raises:
|
|
245
|
-
AgentJamError: If no agent on your account has that name
|
|
250
|
+
AgentJamError: If no agent on your account has that name, or a skill's `subscribes` doesn't name a trigger
|
|
251
|
+
of another of its skills without connections.
|
|
246
252
|
"""
|
|
247
253
|
relay = construct_network(api_key=api_key, network=network, payments=payments)
|
|
248
254
|
stored = await relay.update(name, construct_update(description, skills, visibility))
|
|
@@ -118,6 +118,20 @@ class ParentRef(WireModel):
|
|
|
118
118
|
id: str
|
|
119
119
|
|
|
120
120
|
|
|
121
|
+
class SubscriptionRef(WireModel):
|
|
122
|
+
"""A completed task's subscription to the trigger its skill's `subscribes` names.
|
|
123
|
+
|
|
124
|
+
Its executor sends only the trigger's `config`, and the relay delivers only the schedule it started on `skill`'s
|
|
125
|
+
`trigger`, which ends at `expires_at`, to the requester.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
config: dict[str, Any] | None = None
|
|
129
|
+
schedule_id: str | None = None
|
|
130
|
+
skill: str | None = None
|
|
131
|
+
trigger: str | None = None
|
|
132
|
+
expires_at: str | None = None
|
|
133
|
+
|
|
134
|
+
|
|
121
135
|
class DelegatedTask(WireModel):
|
|
122
136
|
"""A task delegated to another agent: the agent running it and the task's id."""
|
|
123
137
|
|
|
@@ -187,6 +201,8 @@ class ProposeEnvelope(Routed):
|
|
|
187
201
|
principal: str | None = None
|
|
188
202
|
follows: str | None = None
|
|
189
203
|
previous: TaskRecapRef | None = None
|
|
204
|
+
subscribe: Literal[False] | None = None
|
|
205
|
+
"""Opts the requester out of the subscription the skill's `subscribes` starts once the one-off task completes."""
|
|
190
206
|
resumed: Literal[True] | None = None
|
|
191
207
|
attempt: int | None = None
|
|
192
208
|
children: list[DelegatedTask] | None = None
|
|
@@ -244,6 +260,8 @@ class CompleteEnvelope(Routed):
|
|
|
244
260
|
cost_cents: int | float | None = None
|
|
245
261
|
output: JsonObject | None = None
|
|
246
262
|
charged_cents: int | float | None = None
|
|
263
|
+
subscription: SubscriptionRef | None = None
|
|
264
|
+
"""The subscription a one-off task of a skill with `subscribes` starts for its requester."""
|
|
247
265
|
|
|
248
266
|
|
|
249
267
|
class FailEnvelope(Routed):
|
|
@@ -62,8 +62,10 @@ from agentjam._relay.sessions import (
|
|
|
62
62
|
conversation_key,
|
|
63
63
|
request_key,
|
|
64
64
|
)
|
|
65
|
+
from agentjam._relay.subscriptions import StartedSubscription, SubscriptionBook
|
|
65
66
|
from agentjam._relay.uploads import DEFAULT_MIME_TYPE
|
|
66
67
|
from agentjam._signals import Signal
|
|
68
|
+
from agentjam._subscriptions import assert_subscriptions
|
|
67
69
|
from agentjam._types import (
|
|
68
70
|
AgentCard,
|
|
69
71
|
AgentQuery,
|
|
@@ -123,8 +125,8 @@ class MemoryRelay:
|
|
|
123
125
|
nothing is kept for an agent that isn't. An agent may connect many sessions, and each piece of work stays with
|
|
124
126
|
the session it went to, so a task whose requester's session left keeps running unheard. Uploads stay in memory
|
|
125
127
|
and reach their recipients as data URLs, and secret connections reach the stubs in `secrets`. Schedules run on
|
|
126
|
-
their cron or trigger until either agent has no session left,
|
|
127
|
-
its chain.
|
|
128
|
+
their cron or trigger until either agent has no session left, as do the subscriptions completed tasks start, and
|
|
129
|
+
the actions of a delegated task are copied up its chain.
|
|
128
130
|
|
|
129
131
|
Every task runs for free and every agent is public. There are no reviews, disputes, task lists, recaps or
|
|
130
132
|
schedule follow-ups, and no task moves to another session once its executor's leaves.
|
|
@@ -147,6 +149,7 @@ class MemoryRelay:
|
|
|
147
149
|
self._uploads: dict[str, AttachmentRef] = {}
|
|
148
150
|
self._accounts: dict[str, list[ConnectedAccount]] = {}
|
|
149
151
|
self._book = ScheduleBook(self._deliver_scheduled)
|
|
152
|
+
self._subscriptions = SubscriptionBook()
|
|
150
153
|
|
|
151
154
|
async def create(self, name: str, profile: ProfileUpdate) -> StoredAgent:
|
|
152
155
|
"""Stores a new agent, filling in the fields `profile` leaves out with an empty profile.
|
|
@@ -158,10 +161,12 @@ class MemoryRelay:
|
|
|
158
161
|
The stored agent.
|
|
159
162
|
Raises:
|
|
160
163
|
AgentExistsError: If an agent with that name already exists.
|
|
164
|
+
AgentJamError: If a skill's `subscribes` breaks the network's rules.
|
|
161
165
|
"""
|
|
162
166
|
if name in self._profiles:
|
|
163
167
|
raise AgentExistsError(f'An agent named "{name}" already exists')
|
|
164
168
|
|
|
169
|
+
assert_subscriptions(profile.skills or [])
|
|
165
170
|
card = AgentCard(
|
|
166
171
|
name=name,
|
|
167
172
|
description="" if profile.description is None else profile.description,
|
|
@@ -180,9 +185,10 @@ class MemoryRelay:
|
|
|
180
185
|
Returns:
|
|
181
186
|
The stored agent.
|
|
182
187
|
Raises:
|
|
183
|
-
AgentJamError: If no agent with that name exists.
|
|
188
|
+
AgentJamError: If no agent with that name exists, or a skill's `subscribes` breaks the network's rules.
|
|
184
189
|
"""
|
|
185
190
|
card = self._get_profile(name)
|
|
191
|
+
assert_subscriptions(profile.skills or [])
|
|
186
192
|
updated = AgentCard(
|
|
187
193
|
name=name,
|
|
188
194
|
description=card.description
|
|
@@ -366,11 +372,7 @@ class MemoryRelay:
|
|
|
366
372
|
if isinstance(envelope, ErrorEnvelope):
|
|
367
373
|
self._unanswered.pop(request_key(envelope.to, envelope.reply_to), None)
|
|
368
374
|
|
|
369
|
-
routed = (
|
|
370
|
-
envelope.model_copy(update={"principal": self._chains.propose(envelope)})
|
|
371
|
-
if isinstance(envelope, ProposeEnvelope)
|
|
372
|
-
else envelope
|
|
373
|
-
)
|
|
375
|
+
routed, started = self._stamp(envelope)
|
|
374
376
|
self._observe(routed)
|
|
375
377
|
self._sessions.track(routed, recipient, sender)
|
|
376
378
|
self._deliver(self._revisions.revise(routed), recipient)
|
|
@@ -382,9 +384,37 @@ class MemoryRelay:
|
|
|
382
384
|
if isinstance(routed, ConnectionReadyEnvelope):
|
|
383
385
|
self._complete_action(routed)
|
|
384
386
|
|
|
387
|
+
if started is not None:
|
|
388
|
+
self._start_subscription(started)
|
|
389
|
+
|
|
390
|
+
def _stamp(
|
|
391
|
+
self, envelope: DeliveredEnvelope
|
|
392
|
+
) -> tuple[DeliveredEnvelope, StartedSubscription | None]:
|
|
393
|
+
"""Adds what the relay sets on an envelope before delivering it, and checks the subscription a completion starts."""
|
|
394
|
+
match envelope:
|
|
395
|
+
case ProposeEnvelope():
|
|
396
|
+
principal = self._chains.propose(envelope)
|
|
397
|
+
|
|
398
|
+
return envelope.model_copy(update={"principal": principal}), None
|
|
399
|
+
|
|
400
|
+
case CompleteEnvelope():
|
|
401
|
+
card = self._get_profile(envelope.sender)
|
|
402
|
+
completion = self._subscriptions.complete(envelope, card)
|
|
403
|
+
|
|
404
|
+
return completion.completion, completion.started
|
|
405
|
+
|
|
406
|
+
case _:
|
|
407
|
+
return envelope, None
|
|
408
|
+
|
|
409
|
+
def _start_subscription(self, started: StartedSubscription) -> None:
|
|
410
|
+
schedule = started.schedule
|
|
411
|
+
self._sessions.bind_started(schedule.requester, started.task_id, schedule.id)
|
|
412
|
+
self._book.start(schedule)
|
|
413
|
+
|
|
385
414
|
def _observe(self, envelope: DeliveredEnvelope) -> None:
|
|
386
415
|
match envelope:
|
|
387
416
|
case ProposeEnvelope():
|
|
417
|
+
self._subscriptions.propose(envelope)
|
|
388
418
|
self._book.propose(envelope)
|
|
389
419
|
|
|
390
420
|
case RequireEnvelope():
|
|
@@ -154,6 +154,11 @@ class ScheduleBook:
|
|
|
154
154
|
expires_at=parse_expiry(proposal),
|
|
155
155
|
)
|
|
156
156
|
|
|
157
|
+
def start(self, schedule: ScheduleRecord) -> None:
|
|
158
|
+
"""Starts a trigger schedule that needs no proposal, such as a subscription, telling its executor to watch it."""
|
|
159
|
+
self._schedules[request_key(schedule.requester, schedule.id)] = schedule
|
|
160
|
+
self._launch(schedule)
|
|
161
|
+
|
|
157
162
|
def respond(
|
|
158
163
|
self, verdict: AcceptEnvelope | RequireEnvelope | RejectEnvelope | ErrorEnvelope
|
|
159
164
|
) -> None:
|
|
@@ -331,6 +331,17 @@ class SessionBook:
|
|
|
331
331
|
case _:
|
|
332
332
|
assert_never(envelope)
|
|
333
333
|
|
|
334
|
+
def bind_started(self, requester: str, task_id: str, schedule_id: str) -> None:
|
|
335
|
+
"""Binds a schedule the task `task_id` started to the sessions on both sides of that task."""
|
|
336
|
+
task = self._bindings.get(request_key(requester, task_id))
|
|
337
|
+
if task is None:
|
|
338
|
+
return
|
|
339
|
+
|
|
340
|
+
started = Binding(
|
|
341
|
+
schedule_id, "schedule", task.requester, task.executor, open=False
|
|
342
|
+
)
|
|
343
|
+
self._bind(requester, started)
|
|
344
|
+
|
|
334
345
|
def _find_session(self, name: str) -> Member | None:
|
|
335
346
|
return next(iter(self._list_sessions(name)), None)
|
|
336
347
|
|