agentjam 0.3.0__tar.gz → 0.5.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.
Files changed (130) hide show
  1. {agentjam-0.3.0 → agentjam-0.5.0}/PKG-INFO +15 -1
  2. {agentjam-0.3.0 → agentjam-0.5.0}/README.md +14 -0
  3. {agentjam-0.3.0 → agentjam-0.5.0}/pyproject.toml +1 -1
  4. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/__init__.py +4 -1
  5. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent.py +7 -2
  6. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_delegations.py +48 -21
  7. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_executions.py +59 -2
  8. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_judging.py +5 -1
  9. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_options.py +2 -2
  10. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_support.py +1 -0
  11. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_any_of.py +16 -0
  12. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_connections.py +29 -2
  13. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_inputs.py +12 -1
  14. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_profile.py +15 -8
  15. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_protocol.py +25 -2
  16. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/memory.py +38 -8
  17. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/schedules.py +5 -0
  18. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/sessions.py +11 -0
  19. agentjam-0.5.0/src/agentjam/_relay/subscriptions.py +163 -0
  20. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_secrets.py +5 -0
  21. agentjam-0.5.0/src/agentjam/_subscriptions.py +93 -0
  22. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/incoming.py +69 -2
  23. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/outgoing.py +51 -1
  24. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/scheduled.py +45 -1
  25. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tools/network.py +25 -6
  26. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tools/schedules.py +35 -2
  27. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tools/shared.py +1 -0
  28. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_types.py +34 -7
  29. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_vaults/local.py +16 -0
  30. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_vaults/remote.py +5 -0
  31. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_vaults/vault.py +6 -0
  32. {agentjam-0.3.0 → agentjam-0.5.0}/.gitignore +0 -0
  33. {agentjam-0.3.0 → agentjam-0.5.0}/LICENSE +0 -0
  34. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_adapters/__init__.py +0 -0
  35. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_adapters/responses.py +0 -0
  36. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_adapters/shared.py +0 -0
  37. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_access.py +0 -0
  38. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_routing.py +0 -0
  39. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_agent_session.py +0 -0
  40. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_artifacts.py +0 -0
  41. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_attachments.py +0 -0
  42. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_backoff.py +0 -0
  43. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_base_error.py +0 -0
  44. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_chooser.py +0 -0
  45. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_content.py +0 -0
  46. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_cron.py +0 -0
  47. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_datadog_alerts.py +0 -0
  48. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_discord.py +0 -0
  49. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_discord_events.py +0 -0
  50. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_discord_gateway.py +0 -0
  51. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_discord_interactions.py +0 -0
  52. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_downloads.py +0 -0
  53. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_errors.py +0 -0
  54. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_events.py +0 -0
  55. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_files.py +0 -0
  56. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_github.py +0 -0
  57. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_github_api.py +0 -0
  58. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_github_events.py +0 -0
  59. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_google.py +0 -0
  60. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_grafana_alerts.py +0 -0
  61. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_idempotency.py +0 -0
  62. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_managed_webhooks.py +0 -0
  63. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_microsoft.py +0 -0
  64. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_models.py +0 -0
  65. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_oauth_callbacks.py +0 -0
  66. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_pagerduty_incidents.py +0 -0
  67. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_pages.py +0 -0
  68. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_polling.py +0 -0
  69. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_presets.py +0 -0
  70. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_providers.py +0 -0
  71. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_recaps.py +0 -0
  72. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/__init__.py +0 -0
  73. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/base.py +0 -0
  74. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/chains.py +0 -0
  75. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/credentials.py +0 -0
  76. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/endpoints.py +0 -0
  77. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/frames.py +0 -0
  78. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/grants.py +0 -0
  79. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/guest_store.py +0 -0
  80. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/guests.py +0 -0
  81. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/links.py +0 -0
  82. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/payments.py +0 -0
  83. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/profiles.py +0 -0
  84. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/remote.py +0 -0
  85. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/revisions.py +0 -0
  86. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/secrets.py +0 -0
  87. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_relay/uploads.py +0 -0
  88. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_requests.py +0 -0
  89. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_screening.py +0 -0
  90. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_sentry.py +0 -0
  91. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_sentry_api.py +0 -0
  92. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_sentry_events.py +0 -0
  93. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_signals.py +0 -0
  94. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_slack.py +0 -0
  95. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_slack_events.py +0 -0
  96. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_slack_interactions.py +0 -0
  97. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_storage.py +0 -0
  98. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_stripe.py +0 -0
  99. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/__init__.py +0 -0
  100. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/access.py +0 -0
  101. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/serial.py +0 -0
  102. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/triggers.py +0 -0
  103. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tasks/watches.py +0 -0
  104. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tools/__init__.py +0 -0
  105. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tools/delegations.py +0 -0
  106. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_tools/inputs.py +0 -0
  107. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_utils.py +0 -0
  108. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_vaults/__init__.py +0 -0
  109. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_verdicts.py +0 -0
  110. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/_watermarks.py +0 -0
  111. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/anthropic.py +0 -0
  112. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/atlassian.py +0 -0
  113. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/datadog.py +0 -0
  114. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/discord.py +0 -0
  115. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/github.py +0 -0
  116. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/google.py +0 -0
  117. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/grafana.py +0 -0
  118. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/microsoft.py +0 -0
  119. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/mpp.py +0 -0
  120. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/oauth.py +0 -0
  121. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/openai.py +0 -0
  122. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/openai_agents.py +0 -0
  123. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/pagerduty.py +0 -0
  124. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/posthog.py +0 -0
  125. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/py.typed +0 -0
  126. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/pydantic_ai.py +0 -0
  127. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/sentry.py +0 -0
  128. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/skills.py +0 -0
  129. {agentjam-0.3.0 → agentjam-0.5.0}/src/agentjam/slack.py +0 -0
  130. {agentjam-0.3.0 → agentjam-0.5.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.0
3
+ Version: 0.5.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. The subscribed skill may need connections when the subscribing skill declares each of them with at least the same scopes, and the subscription keeps using the accounts its task was granted.
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. The subscribed skill may need connections when the subscribing skill declares each of them with at least the same scopes, and the subscription keeps using the accounts its task was granted.
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.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "agentjam"
7
- version = "0.3.0"
7
+ version = "0.5.0"
8
8
  description = "Allow your agents to discover, message, and delegate tasks to any other agent over AgentJam."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -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(to, key, list_actions(verdict), parent)
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)
@@ -1040,7 +1045,7 @@ class Agent:
1040
1045
  raise self._failure
1041
1046
 
1042
1047
  def check_proposal(self, proposal: Proposal) -> Verdict:
1043
- """Runs the checks proposals get without an `on_proposal`, so `on_proposal` can keep them.
1048
+ """Runs the checks a proposal must pass before it reaches `on_proposal`.
1044
1049
 
1045
1050
  It rejects every proposal without an `on_task`, and ones that name a skill the agent doesn't advertise or a
1046
1051
  trigger its skill doesn't declare.
@@ -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 OutgoingTask, RunDetails, TaskHandle, TaskLink
32
- from agentjam._tasks.scheduled import ScheduleHandle, ScheduleLink
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
- id = compute_key(to, schedule_id)
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(id, None)
148
-
149
- schedule = ScheduleHandle(
150
- schedule_id,
151
- to,
152
- ScheduleLink(
153
- post=self._link.post,
154
- collect=collect,
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:
@@ -31,7 +31,11 @@ from agentjam._agent_support import (
31
31
  resolve_principal,
32
32
  )
33
33
  from agentjam._attachments import AttachmentSource, receive_attachments
34
- from agentjam._connections import ConnectionGrant, ConnectionHolder
34
+ from agentjam._connections import (
35
+ ConnectionGrant,
36
+ ConnectionHolder,
37
+ HandingOverSource,
38
+ )
35
39
  from agentjam._downloads import FileReceiver
36
40
  from agentjam._errors import AgentJamError, ReassignedError, describe_error
37
41
  from agentjam._files import UploadSource
@@ -39,6 +43,7 @@ from agentjam._idempotency import IdempotencyCache
39
43
  from agentjam._inputs import ValueProblem
40
44
  from agentjam._protocol import (
41
45
  AttachmentRef,
46
+ CompleteEnvelope,
42
47
  ErrorEnvelope,
43
48
  MessageEnvelope,
44
49
  ParentRef,
@@ -50,6 +55,7 @@ from agentjam._protocol import (
50
55
  from agentjam._recaps import recap_from_wire
51
56
  from agentjam._relay.base import Draft
52
57
  from agentjam._signals import Signal
58
+ from agentjam._subscriptions import construct_subscription_id
53
59
  from agentjam._tasks.incoming import (
54
60
  ExecutionLink,
55
61
  ParsedInput,
@@ -67,6 +73,7 @@ from agentjam._types import (
67
73
  IncomingMessage,
68
74
  Price,
69
75
  SkillCard,
76
+ TriggerCard,
70
77
  )
71
78
  from agentjam._utils import create_id, resolve_value, spawn
72
79
 
@@ -256,6 +263,8 @@ class Executions:
256
263
  is_self=proposal.sender == self._agent.name,
257
264
  held_cents=proposal.held_cents,
258
265
  resumable=not proposal.prepare and self._is_resumable(proposal.skill),
266
+ subscribed_trigger=self._find_subscribed_trigger(proposal.skill),
267
+ is_opted_out=proposal.subscribe is False,
259
268
  access=self._access.construct_access(proposal.skill, holder),
260
269
  ),
261
270
  self._construct_link(proposal, holder),
@@ -337,6 +346,8 @@ class Executions:
337
346
  is_self=proposal.sender == self._agent.name,
338
347
  held_cents=proposal.held_cents,
339
348
  resumable=True,
349
+ subscribed_trigger=self._find_subscribed_trigger(proposal.skill),
350
+ is_opted_out=proposal.subscribe is False,
340
351
  access=self._access.construct_access(proposal.skill, holder),
341
352
  ),
342
353
  self._construct_link(proposal, holder),
@@ -527,7 +538,9 @@ class Executions:
527
538
  return await self._link.list_history(anchor, query)
528
539
 
529
540
  return ExecutionLink(
530
- post=self._link.post,
541
+ post=self._post_for_task(envelope.skill, holder)
542
+ if isinstance(envelope, ProposeEnvelope)
543
+ else self._link.post,
531
544
  send=self._link.construct_sender(requester, task_id),
532
545
  upload=self._link.upload,
533
546
  prepare=prepare,
@@ -537,6 +550,37 @@ class Executions:
537
550
  ),
538
551
  )
539
552
 
553
+ def _post_for_task(
554
+ self, skill: str | None, task: ConnectionHolder
555
+ ) -> Callable[[Draft], Awaitable[None]]:
556
+ """Posts for a one-off task, handing its accounts over to the subscription its completion starts before sending it."""
557
+
558
+ async def post(draft: Draft) -> None:
559
+ if not isinstance(draft, CompleteEnvelope) or draft.subscription is None:
560
+ await self._link.post(draft)
561
+
562
+ return
563
+
564
+ subscription = ConnectionHolder(
565
+ requester=task.requester, id=construct_subscription_id(task.id)
566
+ )
567
+ sources = self._access.list_skill_sources(skill)
568
+
569
+ try:
570
+ await asyncio.gather(
571
+ *(
572
+ source.hand_over(task, subscription)
573
+ for source in sources
574
+ if isinstance(source, HandingOverSource)
575
+ )
576
+ )
577
+ await self._link.post(draft)
578
+ except Exception:
579
+ self._access.release(subscription, sources)
580
+ raise
581
+
582
+ return post
583
+
540
584
  async def _execute(
541
585
  self, task: TaskExecution, clean_up: Callable[[], None], work: Work
542
586
  ) -> None:
@@ -578,6 +622,19 @@ class Executions:
578
622
  (card for card in self._agent.card.skills if card.name == skill), None
579
623
  )
580
624
 
625
+ def _find_subscribed_trigger(self, skill: str | None) -> TriggerCard | None:
626
+ card = self._find_skill_card(skill)
627
+ subscribes = None if card is None else card.subscribes
628
+ if subscribes is None:
629
+ return None
630
+
631
+ target = self._find_skill_card(subscribes.skill)
632
+ triggers = [] if target is None else target.triggers or []
633
+
634
+ return next(
635
+ (each for each in triggers if each.name == subscribes.trigger), None
636
+ )
637
+
581
638
  def _is_resumable(self, skill: str | None) -> bool:
582
639
  card = self._find_skill_card(skill)
583
640
 
@@ -277,10 +277,14 @@ class ProposalJudge:
277
277
  return await self._requests.request(draft, adopt)
278
278
 
279
279
  async def _decide(self, proposal: Proposal) -> Verdict:
280
+ checked = self._agent.check_proposal(proposal)
281
+ if not checked.accepted:
282
+ return checked
283
+
280
284
  verdict = (
281
285
  await resolve_value(self._on_proposal(proposal, self._agent))
282
286
  if self._on_proposal is not None
283
- else self._agent.check_proposal(proposal)
287
+ else checked
284
288
  )
285
289
 
286
290
  if (
@@ -73,13 +73,13 @@ class HandlerOptions(TypedDict, total=False):
73
73
  on_message: OnMessage | None
74
74
  """Handles a message from another agent. Returns the reply, which goes back to the sender along with any files when the message is about a task."""
75
75
  on_proposal: OnProposal | None
76
- """Handles a task or schedule proposed to this agent. Returns whether to accept it, and by default accepts proposals for the agent's stored skills."""
76
+ """Handles a task or schedule proposed to this agent once it passes `check_proposal()`. Returns whether to accept it, and accepts every such proposal by default."""
77
77
  on_task: OnTask | None
78
78
  """Handles an accepted task. Returns the final task output, which is delivered to the task's proposer."""
79
79
  tool_names: Sequence[str]
80
80
  """Your agent's own tool names, which `connect()` checks don't clash with the network tools."""
81
81
  screen: ProposalScreen | None
82
- """Screens each proposal `on_proposal` or the default checks accept with a model, before accepting it.
82
+ """Screens each proposal `check_proposal()` and `on_proposal` accept with a model, before accepting it.
83
83
 
84
84
  Leave it out to accept without one, and turn it on with an adapter's `screen` option or a `judge` calling any model.
85
85
  """
@@ -346,6 +346,7 @@ def to_proposal(
346
346
  previous=None
347
347
  if proposal.previous is None
348
348
  else recap_from_wire(proposal.previous, files),
349
+ subscribe=proposal.subscribe is not False,
349
350
  )
350
351
 
351
352
 
@@ -270,6 +270,22 @@ class AnyOfConnection(SkillConnection):
270
270
  *(offered.connection.release(holder) for offered in self.options.values())
271
271
  )
272
272
 
273
+ async def hand_over(
274
+ self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
275
+ ) -> None:
276
+ """Pins `to_holder` to the option and account `from_holder` uses, if any, so it keeps them once `from_holder` is released.
277
+
278
+ Args:
279
+ from_holder: The completed task whose account to hand over.
280
+ to_holder: The subscription the task started.
281
+ """
282
+ await asyncio.gather(
283
+ *(
284
+ offered.connection.hand_over(from_holder, to_holder)
285
+ for offered in self.options.values()
286
+ )
287
+ )
288
+
273
289
  async def revoke(
274
290
  self,
275
291
  principal: str,
@@ -138,8 +138,8 @@ class CredentialSource(Protocol):
138
138
 
139
139
  Each human can connect several accounts, which every agent's tasks for that human can share. `oauth_connection()`
140
140
  builds one, and a credential vault can implement it instead, subclassing `SkillConnection` so skills can list it.
141
- Its optional capabilities are `AccountReadingSource`, `AccountRevokingSource`, `AccessLinkingSource` and
142
- `GrantListingSource`.
141
+ Its optional capabilities are `AccountReadingSource`, `AccountRevokingSource`, `AccessLinkingSource`,
142
+ `HandingOverSource` and `GrantListingSource`.
143
143
  """
144
144
 
145
145
  provider: str
@@ -250,6 +250,22 @@ class AccessLinkingSource(Protocol):
250
250
  ...
251
251
 
252
252
 
253
+ @runtime_checkable
254
+ class HandingOverSource(Protocol):
255
+ """A credential source that can let the subscription a completed task starts keep the task's account."""
256
+
257
+ async def hand_over(
258
+ self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
259
+ ) -> None:
260
+ """Pins `to_holder` to the account `from_holder` uses, if any, so it keeps it once `from_holder` is released.
261
+
262
+ Args:
263
+ from_holder: The completed task whose account to hand over.
264
+ to_holder: The subscription the task started.
265
+ """
266
+ ...
267
+
268
+
253
269
  @runtime_checkable
254
270
  class GrantListingSource(Protocol):
255
271
  """A credential source that lists the tasks and schedules holding its grants."""
@@ -676,6 +692,17 @@ class OAuthConnection(SkillConnection):
676
692
  """
677
693
  await self._vault.release(holder)
678
694
 
695
+ async def hand_over(
696
+ self, from_holder: ConnectionHolder, to_holder: ConnectionHolder
697
+ ) -> None:
698
+ """Pins `to_holder` to the account `from_holder` uses, if any, so it keeps it once `from_holder` is released.
699
+
700
+ Args:
701
+ from_holder: The completed task whose account to hand over.
702
+ to_holder: The subscription the task started.
703
+ """
704
+ await self._vault.hand_over(from_holder, to_holder)
705
+
679
706
  async def revoke(self, principal: str, account_id: str | None = None) -> None:
680
707
  """Revokes a human's grant for one account with the provider, or for each of their accounts, and forgets its tokens.
681
708
 
@@ -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
- return ProfileUpdate(
94
- description=description,
95
- skills=None
96
- if skills is None
97
- else [construct_skill_card(each) for each in skills],
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,8 @@ 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 whose connections it
198
+ declares.
193
199
  """
194
200
  relay = construct_network(api_key=api_key, network=network, payments=payments)
195
201
  update = construct_update(description, skills, visibility)
@@ -242,7 +248,8 @@ async def update(
242
248
  Returns:
243
249
  A handle to connect the agent with.
244
250
  Raises:
245
- AgentJamError: If no agent on your account has that name.
251
+ AgentJamError: If no agent on your account has that name, or a skill's `subscribes` doesn't name a trigger
252
+ of another of its skills whose connections it declares.
246
253
  """
247
254
  relay = construct_network(api_key=api_key, network=network, payments=payments)
248
255
  stored = await relay.update(name, construct_update(description, skills, visibility))
@@ -37,9 +37,14 @@ TaskEndCode = Literal[
37
37
  """Why the relay ended a task itself, such as once the task it was part of ended or its requester's owner canceled it from AgentJam."""
38
38
 
39
39
  ScheduleEndCode = Literal[
40
- "expired", "payment_failed", "connection_revoked", "action_expired"
40
+ "expired",
41
+ "payment_failed",
42
+ "connection_revoked",
43
+ "action_expired",
44
+ "subscription_refused",
41
45
  ]
42
- """Why the relay ended a schedule itself, such as once it reached its expiry."""
46
+ """Why the relay ended a schedule itself, such as once it reached its expiry, or `subscription_refused` once it couldn't
47
+ start the subscription a completed task started, which its executor may never have seen start."""
43
48
 
44
49
  ScheduleStatus = Literal["proposed", "requires_action", "active", "ended"]
45
50
  """Where a schedule stands on the relay."""
@@ -118,6 +123,20 @@ class ParentRef(WireModel):
118
123
  id: str
119
124
 
120
125
 
126
+ class SubscriptionRef(WireModel):
127
+ """A completed task's subscription to the trigger its skill's `subscribes` names.
128
+
129
+ Its executor sends only the trigger's `config`, and the relay delivers only the schedule it started on `skill`'s
130
+ `trigger`, which ends at `expires_at`, to the requester.
131
+ """
132
+
133
+ config: dict[str, Any] | None = None
134
+ schedule_id: str | None = None
135
+ skill: str | None = None
136
+ trigger: str | None = None
137
+ expires_at: str | None = None
138
+
139
+
121
140
  class DelegatedTask(WireModel):
122
141
  """A task delegated to another agent: the agent running it and the task's id."""
123
142
 
@@ -187,6 +206,8 @@ class ProposeEnvelope(Routed):
187
206
  principal: str | None = None
188
207
  follows: str | None = None
189
208
  previous: TaskRecapRef | None = None
209
+ subscribe: Literal[False] | None = None
210
+ """Opts the requester out of the subscription the skill's `subscribes` starts once the one-off task completes."""
190
211
  resumed: Literal[True] | None = None
191
212
  attempt: int | None = None
192
213
  children: list[DelegatedTask] | None = None
@@ -244,6 +265,8 @@ class CompleteEnvelope(Routed):
244
265
  cost_cents: int | float | None = None
245
266
  output: JsonObject | None = None
246
267
  charged_cents: int | float | None = None
268
+ subscription: SubscriptionRef | None = None
269
+ """The subscription a one-off task of a skill with `subscribes` starts for its requester."""
247
270
 
248
271
 
249
272
  class FailEnvelope(Routed):