@gea-ai/agent-sdk 0.1.260917-alpha.2 → 0.1.260918-alpha.0
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.
- package/README.md +141 -88
- package/dist/agent-call.d.ts +133 -170
- package/dist/agent-call.js +26 -38
- package/dist/agent-channel-api.d.ts +56 -0
- package/dist/agent-channel-api.js +205 -0
- package/dist/agent-channel-author-runtime.d.ts +21 -14
- package/dist/agent-channel-author-runtime.js +36 -35
- package/dist/agent-channel-receiver.js +8 -1
- package/dist/agent-http.d.ts +4 -30
- package/dist/agent-http.js +4 -90
- package/dist/agent-remote-run.d.ts +16 -0
- package/dist/agent-remote-run.js +78 -0
- package/dist/agent-run-host.d.ts +55 -0
- package/dist/agent-run-host.js +234 -0
- package/dist/agent-session-children.d.ts +3 -0
- package/dist/agent-session-children.js +144 -0
- package/dist/agent-session-execution.js +107 -10
- package/dist/agent-session-inbox.d.ts +40 -6
- package/dist/agent-session-inbox.js +305 -144
- package/dist/agent-session-runner.d.ts +8 -10
- package/dist/agent-session-runner.js +16 -7
- package/dist/agent-session-stream.js +1 -1
- package/dist/agent-session.js +9 -6
- package/dist/agent-worker.d.ts +3 -5
- package/dist/agent-worker.js +149 -176
- package/dist/channels/index.d.ts +7 -9
- package/dist/index.d.ts +8 -12
- package/dist/index.js +4 -2
- package/dist/session-authority.d.ts +8 -9
- package/dist/trace-context.d.ts +1 -1
- package/dist/trace-context.js +1 -1
- package/package.json +5 -9
- package/dist/agent-session-tasks.d.ts +0 -3
- package/dist/agent-session-tasks.js +0 -198
- package/dist/agent-task-host.d.ts +0 -64
- package/dist/agent-task-host.js +0 -331
- package/dist/remote-agent.d.ts +0 -22
- package/dist/remote-agent.js +0 -149
package/README.md
CHANGED
|
@@ -13,7 +13,83 @@ for validation, Studio display, and exact-version execution. Snapshots never
|
|
|
13
13
|
contain handler functions, credentials, Connector Connections, tenant identity,
|
|
14
14
|
provider configuration, or environment values.
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## Calling the Agents HTTP API
|
|
17
|
+
|
|
18
|
+
Call the public `/api/v1` API with ordinary HTTP and a fixed Agent ID. No Agent
|
|
19
|
+
SDK dependency is required for API callers:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const baseUrl = "https://<tenant-host>/api/v1";
|
|
23
|
+
const headers = {
|
|
24
|
+
authorization: `Bearer ${projectApiKey}`, // Or a user OAuth token.
|
|
25
|
+
"content-type": "application/json",
|
|
26
|
+
};
|
|
27
|
+
const created = await fetch(`${baseUrl}/sessions`, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers,
|
|
30
|
+
credentials: "omit",
|
|
31
|
+
redirect: "error",
|
|
32
|
+
body: JSON.stringify({ agent_id: agentId, environment: "production" }),
|
|
33
|
+
});
|
|
34
|
+
if (!created.ok) throw new Error(`Session creation failed: ${created.status}`);
|
|
35
|
+
const session = await created.json();
|
|
36
|
+
const response = await fetch(`${baseUrl}/sessions/${session.id}/runs`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers,
|
|
39
|
+
credentials: "omit",
|
|
40
|
+
redirect: "error",
|
|
41
|
+
body: JSON.stringify({ input: "Hello", stream: true }),
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) throw new Error(`Run admission failed: ${response.status}`);
|
|
44
|
+
// Consume response.body as the API's SSE stream.
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Project Key access to deployed project Agents does not require OAuth or store
|
|
48
|
+
publication. OAuth access remains subject to user and tenant authorization.
|
|
49
|
+
For local development, use the CLI's separate API listener, omit authorization
|
|
50
|
+
and omit `environment` so the local API selects it. Shared HTTP schemas live in
|
|
51
|
+
`@gea-ai/contract/agent-http-api`; routes are documented by `/api/v1/openapi.json`.
|
|
52
|
+
|
|
53
|
+
Read `GET /sessions/{id}` for `active_run`, capture that Run ID, then observe
|
|
54
|
+
`GET /runs/{id}` or its stream. A later Run in the same Session does not change
|
|
55
|
+
the captured invocation. Cancellation acknowledgement is separate from final
|
|
56
|
+
cleanup. Aborting an HTTP request does not cancel a Run; a lost POST response
|
|
57
|
+
does not establish whether it was accepted, so do not automatically replay it.
|
|
58
|
+
|
|
59
|
+
The authoring SDK owns Agent execution. An Agents API client SDK is deferred.
|
|
60
|
+
The Worker `AGENTS.fetch` binding is an authenticated HTTP transport using the
|
|
61
|
+
same paths, payloads and responses. It does not introduce `agents.*`, `sessions.*`
|
|
62
|
+
or `runs.*` client methods. See the
|
|
63
|
+
[HTTP integration guide](https://musegea.com/developers/agent-api).
|
|
64
|
+
|
|
65
|
+
## Custom Agent execution URL
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
export default defineAgent({
|
|
69
|
+
name: "Support",
|
|
70
|
+
slug: "support",
|
|
71
|
+
model: "your-model",
|
|
72
|
+
http: { runPath: "/gea/support-entry" },
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`http.runPath` selects the Agent's actual Worker execution route. Omission uses
|
|
77
|
+
`/gea/agents/<key>/run`. The route belongs to the immutable snapshot and manifest;
|
|
78
|
+
changing it does not change the Agent ID. Hosts invoke the recorded version's
|
|
79
|
+
route, including retained child Runs. OPTIONS reports the declared route without
|
|
80
|
+
creating a Session. Build/upload validation probes it and rejects mismatches and
|
|
81
|
+
conflicting declarations. Private Session control endpoints keep their standard
|
|
82
|
+
protocol paths.
|
|
83
|
+
|
|
84
|
+
Agents API dispatches **to** this Worker route. The existing public authentication
|
|
85
|
+
adapter is still present; removing its control-plane round trip is unfinished.
|
|
86
|
+
This increment does not change `http.auth` behavior or add an API client SDK.
|
|
87
|
+
|
|
88
|
+
## Existing Worker URL authentication
|
|
89
|
+
|
|
90
|
+
The following Worker URL adapter remains available while the unified Agents API
|
|
91
|
+
migration proceeds. `StudioAgentClient` is still used by existing Worker handlers;
|
|
92
|
+
it is not the fixed-ID `/api/v1` interface above.
|
|
17
93
|
|
|
18
94
|
Agent HTTP accepts Project API keys and GEA user OAuth tokens by default. Push the
|
|
19
95
|
Worker and associate the Agent with its app in **Studio → Applications**. Publish
|
|
@@ -34,26 +110,13 @@ approval for external test tenants and explicit environment enablement. The
|
|
|
34
110
|
application starts standard OAuth; GEA confirms the actual user and consumer tenant
|
|
35
111
|
and resolves the installation internally. Do not send an installation ID.
|
|
36
112
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const response = await agent.run({ message: "Hello" });
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
The token identifies the user, app and tenant; the URL selects the environment
|
|
48
|
-
and Agent. Users need current consumer tenant membership and application authorization.
|
|
49
|
-
Their configuration, Connections, Chats, files and traces belong to that environment
|
|
50
|
-
installation. Existing Chat/Run calls retain their pinned execution version;
|
|
51
|
-
historical Workspace-bound records still require access to that Workspace.
|
|
52
|
-
|
|
53
|
-
`projectKeyAuth()` and Project API Keys retain Studio development access. `token`
|
|
54
|
-
accepts either credential, subject to the Agent's declared auth; a Project Key does
|
|
55
|
-
not represent a tenant user or grant cross-tenant installation access. There is no
|
|
56
|
-
third marketplace URL. Standalone Worker OAuth publication remains future work.
|
|
113
|
+
Use direct HTTP against platform `/api/v1/sessions` and
|
|
114
|
+
`/api/v1/sessions/{sessionId}/runs`, with a Bearer Project API Key or OAuth user
|
|
115
|
+
token and the canonical Agent ID. Project Keys retain Project service scope;
|
|
116
|
+
OAuth tokens resolve the current user and tenant installation. Neither changes
|
|
117
|
+
the Agent's default host-context execution policy. The older `studio-server`
|
|
118
|
+
client targets the retired Worker credential entry and should not be used for
|
|
119
|
+
new integrations.
|
|
57
120
|
|
|
58
121
|
## Agent Authoring Shapes
|
|
59
122
|
|
|
@@ -175,64 +238,28 @@ Generated code uses `createAgentApplicationFetch()`, which owns:
|
|
|
175
238
|
/gea/agents[/<agentKey>]/sessions/<sessionId>/v1/<operation>
|
|
176
239
|
```
|
|
177
240
|
|
|
178
|
-
|
|
179
|
-
|
|
241
|
+
Agent execution requires trusted host invocation context by default. Public
|
|
242
|
+
Agents API accepts Project API Keys and OAuth user tokens, checks their scope,
|
|
243
|
+
and admits the Session/Run before calling this Worker's configured execution URL.
|
|
244
|
+
The Worker does not authenticate those credentials again.
|
|
180
245
|
|
|
181
246
|
```ts
|
|
182
|
-
import {
|
|
183
|
-
defineAgent,
|
|
184
|
-
projectKeyAuth,
|
|
185
|
-
platformUserAuth,
|
|
186
|
-
} from "@gea-ai/agent-sdk";
|
|
247
|
+
import { defineAgent } from "@gea-ai/agent-sdk";
|
|
187
248
|
|
|
188
249
|
export default defineAgent({
|
|
189
250
|
name: "support",
|
|
190
251
|
slug: "support",
|
|
191
252
|
model: "gea-model-1",
|
|
192
|
-
http: {
|
|
253
|
+
http: { runPath: "/gea/support-entry" },
|
|
193
254
|
});
|
|
194
255
|
```
|
|
195
256
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
```ts
|
|
204
|
-
// Inside defineAgent(...):
|
|
205
|
-
http: {
|
|
206
|
-
auth: false;
|
|
207
|
-
} // Explicit public access to this Agent's HTTP API.
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
An application can replace the default with its own Session authenticator:
|
|
211
|
-
|
|
212
|
-
```ts
|
|
213
|
-
http: {
|
|
214
|
-
auth: async (request, { environment }) => {
|
|
215
|
-
const session = await getSession(request, environment); // Your verified session.
|
|
216
|
-
return session
|
|
217
|
-
? { principalType: "user", principalId: session.userId }
|
|
218
|
-
: null;
|
|
219
|
-
},
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
An authenticator returns a verified platform authorization, an external user,
|
|
224
|
-
a `Response`, or `null`. An array runs in order: `null` means this method does
|
|
225
|
-
not apply, while an identity or any `Response` stops the chain. An empty array
|
|
226
|
-
or a chain that returns only `null` rejects with 401. Exceptions stop the chain
|
|
227
|
-
and become an HTTP 500 at the Agent boundary. Built-in methods recognize their
|
|
228
|
-
credential prefix before validation; malformed, revoked or denied credentials
|
|
229
|
-
and service failures never fall through to another identity. Custom methods
|
|
230
|
-
should likewise return an error `Response` for invalid credentials, reserving
|
|
231
|
-
`null` for a method that does not apply. A single custom authenticator returning
|
|
232
|
-
`null` still rejects with 401. Project Keys stay on the backend; they never
|
|
233
|
-
represent the creator's GEA user.
|
|
234
|
-
`authenticateProjectKey(request, environment.PROJECT)` also works in ordinary
|
|
235
|
-
Worker routes with a declared Project binding and a Project attachment.
|
|
257
|
+
Omit `auth` for normal hosted execution. Set `http: { auth: false }` only when
|
|
258
|
+
this Agent's Worker HTTP entry should also admit anonymous requests. The host
|
|
259
|
+
still registers their Session/Run with project-scoped anonymous ownership.
|
|
260
|
+
Request headers and bodies cannot supply a trusted principal or parent Run.
|
|
261
|
+
This setting does not disable public Agents API Key/OAuth checks or expose
|
|
262
|
+
private Session controls. Ordinary business routes keep their own authentication.
|
|
236
263
|
|
|
237
264
|
`OPTIONS /gea/agents/<agentKey>/run` returns only the Agent key, canonical run
|
|
238
265
|
path and HTTP protocol version. It runs before authentication and does not
|
|
@@ -640,7 +667,7 @@ override to the public `/run` API or Studio composer. See the upstream
|
|
|
640
667
|
[OpenAI](https://ai-sdk.dev/providers/ai-sdk-providers/openai) and
|
|
641
668
|
[Anthropic](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic) options.
|
|
642
669
|
|
|
643
|
-
##
|
|
670
|
+
## Agent delegation through Sessions and Runs
|
|
644
671
|
|
|
645
672
|
Declare private definitions in `subagents/<name>/agent.ts` with their own `AGENTS.md`, tools, skills and connectors. They run in independent Sessions and may declare further subagents. Only top-level definitions become public Worker entrypoints.
|
|
646
673
|
|
|
@@ -649,18 +676,51 @@ References are explicit default exports from `subagents/<alias>.ts`:
|
|
|
649
676
|
```ts
|
|
650
677
|
import { defineAgentReference, defineRemoteAgent } from "@gea-ai/agent-sdk";
|
|
651
678
|
|
|
652
|
-
// Same Worker
|
|
679
|
+
// Same Worker, checked against the generated WorkerAgentRegistry.
|
|
653
680
|
const sales = defineAgentReference({
|
|
654
681
|
slug: "sales",
|
|
655
682
|
description: "Sales analysis",
|
|
656
683
|
});
|
|
657
|
-
|
|
684
|
+
|
|
685
|
+
// Same Agents API: the host revalidates the calling Run's authority.
|
|
658
686
|
const legal = defineRemoteAgent({
|
|
659
|
-
|
|
687
|
+
agentId: "bb141b12-6f63-43bd-8ab6-77930916d3ef",
|
|
660
688
|
description: "Legal review",
|
|
689
|
+
});
|
|
661
690
|
|
|
691
|
+
// Another service: use its API root and canonical Agent ID.
|
|
692
|
+
const external = defineRemoteAgent({
|
|
693
|
+
agentId: "34910649-2df7-4978-8794-8d8fb72f16cd",
|
|
694
|
+
url: "https://legal.example.com/api/v1",
|
|
695
|
+
environment: "production",
|
|
696
|
+
description: "External legal review",
|
|
697
|
+
auth: { bearerTokenEnv: "LEGAL_AGENT_KEY" },
|
|
698
|
+
});
|
|
662
699
|
```
|
|
663
700
|
|
|
701
|
+
Each reference file default-exports one reference. All targets use `agent({ target: "alias", message, sessionId? })` and return `{ status: "working", runId, sessionId }`. Callers only see their own declared aliases. Include `agentTool()` in the root's tools to allow self copies by omitting `target`; children cannot create unnamed copies.
|
|
702
|
+
|
|
703
|
+
Use `run_wait({ runIds, timeoutMs? })` to wait for specific Runs and `run_cancel({ runId })` to request cancellation. The SDK owns waiting, batched parent wakeups and descendant cleanup. Cancellation acceptance is not completion. A logical Run keeps its ID through normal waits and resumptions; continuing an idle child with the same target and `sessionId` creates a new Run. There is no Task resource or progress-reporting tool.
|
|
704
|
+
|
|
705
|
+
Remote references always use the canonical Agent ID, optionally with another service's API root. Their Session and Run IDs come from that API. Remote transport creates Sessions/Runs and reads status, messages and cancellation through ordinary HTTP; it never calls a Worker's `/gea/xxxx` execution URL directly. The API selects the versioned Worker route. A remote reference without `environment` inherits the invocation environment (`local` in CLI development).
|
|
706
|
+
|
|
707
|
+
Same-service calls inherit live Project Key or OAuth authority through a short-lived, host-only signed context. Studio host calls use a Project service scope isolated by Worker, environment and principal. Explicit credentials override inherited authority. Calls to another API origin use only explicitly configured credentials; they never forward the parent's bearer. Knowing an Agent ID does not grant access. Same-service parent links are registered by the host; cross-service relationships live in the parent Session and point to the actual remote IDs.
|
|
708
|
+
|
|
709
|
+
Remote observation survives parent waiting using the existing Session pending-dispatch mechanism. A transport error does not invent a terminal outcome, and accepted Run creation is never automatically replayed. Host shutdown stops observation without cancelling remote execution. General crash recovery and approval continuation remain separate lifecycle work.
|
|
710
|
+
|
|
711
|
+
Upgrade SDK, CLI, server and Worker Runtime together and rebuild immutable bundles. The physical `AGENT_TASK_SESSIONS` namespace remains to preserve existing child Session history; it no longer represents Tasks.
|
|
712
|
+
|
|
713
|
+
## Fetch-style Agents binding
|
|
714
|
+
|
|
715
|
+
Generated Agent Workers include an `AGENTS` binding. Other Workers can declare `{ name: "AGENTS", type: "agents" }` in their bindings. It exposes the same HTTP paths and payloads, without a separate API client SDK:
|
|
716
|
+
|
|
717
|
+
```ts
|
|
718
|
+
const response = await env.AGENTS.fetch("/api/v1/agents?limit=20");
|
|
719
|
+
const agents = await response.json();
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
Within a trusted Agent invocation, the host supplies signed invocation authority. An ordinary hosted Worker invocation without a source Run must provide its Project API Key or OAuth token in `Authorization`. Local development uses the local API's existing authority. The binding does not expose host signing secrets or permit arbitrary destinations. Default host authority covers Agents, Sessions and Runs; File, Connector and Computer operations require explicit credentials with their existing grants.
|
|
723
|
+
|
|
664
724
|
## Call a Studio Agent with AI SDK
|
|
665
725
|
|
|
666
726
|
Use `StudioAgentChatTransport` from `@gea-ai/agent-sdk/studio-client` with
|
|
@@ -708,22 +768,8 @@ const agent = new StudioAgentClient({
|
|
|
708
768
|
api: env.GEA_AGENT_API_URL, // Agent base URL without /run.
|
|
709
769
|
token: env.GEA_PROJECT_API_KEY,
|
|
710
770
|
});
|
|
711
|
-
// URL: a GEA Agent protocol endpoint. The key stays in runtime environment configuration.
|
|
712
|
-
const external = defineRemoteAgent({
|
|
713
|
-
url: "https://legal.example.com/gea/agents/advisor",
|
|
714
|
-
description: "Legal review",
|
|
715
|
-
auth: { bearerTokenEnv: "LEGAL_AGENT_KEY" },
|
|
716
|
-
});
|
|
717
771
|
```
|
|
718
772
|
|
|
719
|
-
Each reference file default-exports one reference. All targets use `agent({ target: "alias", message, agentId? })`; callers only see their own declared aliases. Include `agentTool()` in the root's tools to additionally allow self copies by omitting `target`. Named delegation follows each node's own declarations; child invocations cannot create another unnamed copy.
|
|
720
|
-
|
|
721
|
-
The tool returns `{ status: "working", taskId, agentId }`. `task_update({ message })` reports progress, and `task_cancel({ taskId })` requests cancellation. The host continues idle parent conversations when updates arrive. A child task finishes after its descendants and notification inbox settle, including any final summary turn. Continue an idle child with its returned `agentId` and the same target.
|
|
722
|
-
|
|
723
|
-
URL targets implement GEA task create/status/cancel endpoints. New calls and continuations follow the deployment selected by the URL, retaining history while using its current model, instructions and tools. Accepted tasks finish on their selected version. URL credentials are explicitly configured; source credentials and principals are not forwarded. Pure local development uses URLs for cross-Worker calls because it has no hosted Project identity.
|
|
724
|
-
|
|
725
|
-
This requires matching SDK, CLI, server and Worker Runtime support and rebuilding immutable bundles. Task Sessions opt into `durable-object-worker-namespace-v1`; existing ordinary Session storage is unchanged. Channel wakeups, approval relay, active-child steering and execution recovery after a host crash remain deferred.
|
|
726
|
-
|
|
727
773
|
### Worker build plugins
|
|
728
774
|
|
|
729
775
|
The Node-only `@gea-ai/agent-sdk/worker-build-plugins` entry exports the shared
|
|
@@ -737,7 +783,7 @@ Applications call `/api/v1` using `fetch`, `curl` or another HTTP client. Payloa
|
|
|
737
783
|
use JSON and streams use AI SDK UI-message SSE. The Agent SDK owns Agent execution;
|
|
738
784
|
calling the HTTP API does not require an SDK client.
|
|
739
785
|
|
|
740
|
-
Hosted requests use
|
|
786
|
+
Hosted requests use a Project API Key or a Project user OAuth token. An independently running
|
|
741
787
|
`gea agent dev --model-source local --api-port 8788` exposes token-free local access:
|
|
742
788
|
|
|
743
789
|
```sh
|
|
@@ -759,3 +805,10 @@ read-only through the local API.
|
|
|
759
805
|
|
|
760
806
|
See the [HTTP integration guide](https://musegea.com/developers/agent-api) and the
|
|
761
807
|
running server's `/api/v1/openapi.json` for routes and payloads.
|
|
808
|
+
|
|
809
|
+
API callers use ordinary HTTP. Subagents reuse Agent/Session/Run resources,
|
|
810
|
+
with parent/child coordination owned by logical Runs in the SDK Session inbox.
|
|
811
|
+
Internal Task logic has been removed. Worker fetch bindings and remote references
|
|
812
|
+
use the same API, which invokes each Agent at its versioned custom or standard
|
|
813
|
+
Worker route. See the [HTTP integration guide](https://musegea.com/developers/agent-api)
|
|
814
|
+
for authentication and Session/Run operations.
|