Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
bf7fc73
feat(gateway): make the tool calls a server's result defers, on the g…
earakely-scale Nov 24, 2026
80ae951
test(gateway): a clock clear moves a waiting deferred call onto wall …
earakely-scale Nov 24, 2026
49e00ce
fix(gateway): a deferred call is known by its server and key, and its…
earakely-scale Nov 24, 2026
f680b54
fix(gateway): deferred calls a trigger action declares provoke nothin…
earakely-scale Nov 24, 2026
5128d16
fix(task_step): settle checks wait for a deferred call the gateway ma…
earakely-scale Nov 24, 2026
8adb9bb
feat(protocol): a tool can declare the call it defers in its decorator
earakely-scale Nov 24, 2026
197b670
refactor(gateway): a deferred call is a typed record, and its statuse…
earakely-scale Nov 24, 2026
d2dbe08
refactor(gateway): every child tool call says whether its deferred ca…
earakely-scale Nov 24, 2026
3850482
refactor(task_step): one rule says which deferred calls a settle chec…
earakely-scale Nov 24, 2026
5303208
fix(gateway): each attempt of a deferred call has its own write window
earakely-scale Nov 24, 2026
676ddec
docs(gateway): rewrap the deferred call's docstring
earakely-scale Nov 24, 2026
48962e3
fix(protocol): a decorator's deferred calls follow those the tool's r…
earakely-scale Nov 24, 2026
5e1eebe
test(task_step): the due-deferred-call settle test bounds its wait lo…
earakely-scale Nov 24, 2026
5506799
test(gateway): the running-clock deferred-call test allows a real sec…
earakely-scale Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/agentenv-protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,59 @@ step names it. Steps that name it show and hide it as they do any tool. Steps fo
that role's earlier named steps, and a full reset (`role: "*", tools: "*"`) clears all of them, so
grant a hidden tool after such steps. Trigger tool actions call it as usual.

A tool's successful result can ask the gateway to call the same server later, for something the
server does at a time of its own (a scheduled message posted at its time) that no tool call would
otherwise mark. Its `_meta` `"agentenv.io/deferredCalls"` (`DEFERRED_CALLS_META_KEY`) is a list of
`{"key", "at", "call", "report_as"}`: `at` an RFC 3339 instant with an offset, `call` and
`report_as` each `{"tool", "arguments"}`. The gateway takes the key off the result, so no caller sees
it, and schedules each entry once per server and `key` (one its server declares again while pending
or done is ignored). When the gateway clock reaches `at` (its virtual time while armed, wall UTC
while not) it calls `call.tool` as the role that made the declaring call, as it makes a live call
(under the consistent mode's lock, its write attributed to it). After a transport failure it calls
again: five attempts in all, 1, 2, 4 and 8 s apart, each of which first reopens the server's session
if it must (retrying the connection for about ten seconds), so against a server that stays down the
call fails about 51 s after its first attempt (as observed). So make that tool idempotent (and
`hidden_by_default`, as plumbing). Unless the result is an error, the gateway hands its triggers that
result as that role's call of `report_as.tool` with `report_as.arguments`; a trigger action's own
call provokes no trigger, and neither does one it declares. `GET /triggers/state` lists each under
`deferred_calls` (`due` marks one the clock has reached that is still to make, which settle checks
wait for), and counts the earliest still to make in `next_event_at`. Behind no gateway, or one that
ignores the key, nothing calls it, so a server still acts by itself once the time has passed (on its
next read, say).

`@tool(..., defers=Defers(call=..., report_as=..., using=...))` builds that declaration for you, and
the tool returns its reply as before:

```python
from agentenv_protocol import DeferredCall, Defers, tool

@tool(hidden_by_default=True)
def deliver_reminder(self, reminder_id: str) -> str: ...

@tool(defers=Defers(call="deliver_reminder", report_as="send_notification", using="_reminder_delivery"))
def schedule_reminder(self, event_id: str, remind_at: str) -> str: ...

def _reminder_delivery(self, arguments: dict, result) -> DeferredCall | list[DeferredCall] | None:
if not result.get("ok"):
return None
return DeferredCall(key=result["reminder_id"], at=result["remind_at"],
arguments={"reminder_id": result["reminder_id"]},
report_arguments={"event_id": arguments["event_id"]})
```

After each successful call of the registered tool, the SDK calls `self.<using>(arguments, result)`
with the call's arguments and the tool's result: a JSON text reply parsed to its dict or list, a dict
as is, a `CallToolResult`'s `structuredContent` or else its text so parsed, anything else as it is.
Each `DeferredCall` it returns becomes one entry, with the named tools as its `call` and `report_as`;
`at` is an aware datetime, epoch seconds or an RFC 3339 string with an offset, declared in UTC. The
reply's content and structured content are unchanged, and the entries join any `_meta` it has. An
error reply declares nothing, and a declaration that fails (`using` raises, or returns a wrong type,
an empty key or an `at` without an offset) is logged and left out rather than breaking the reply.
The method called in process still returns its plain value. The mount raises unless `call` is a
`hidden_by_default` tool and `report_as` a tool the environment serves (by served name,
`{environment_name}` resolved), and `using` a plain method; the card lists both tools under the
tool's `defers`.

`@tool(..., annotations={"readOnlyHint": True}, structured_output=True, meta={...})` lists the tool
with MCP `ToolAnnotations`, an output schema and `_meta`, on mcp's FastMCP and on fastmcp alike.
`structured_output` follows mcp's FastMCP (None derives an output schema from the return annotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
from .preflight import intake_fit_check
from .tool_client import ToolResult, ToolSession, ToolSessionError
from .agent_env_environment import (
DEFERRED_CALLS_META_KEY,
HIDDEN_BY_DEFAULT_META_KEY,
AgentEnvApplication,
AgentEnvEnvironment,
AgentEnvFastMCPApplication,
AgentEnvStarletteApplication,
DeferredCall,
Defers,
ForwardedTool,
add_data,
agent_skill,
Expand Down Expand Up @@ -114,6 +117,9 @@
"ROLE_META_KEY",
"SESSION_META_KEY",
"HIDDEN_BY_DEFAULT_META_KEY",
"DEFERRED_CALLS_META_KEY",
"Defers",
"DeferredCall",
"ROLE_HEADER",
"DEFAULT_ROLE",
"EnvironmentCapabilities",
Expand Down
Loading
Loading