@gea-ai/agent-sdk 0.1.261016-alpha.0 → 0.1.261019-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/dist/agent-core.wasm +0 -0
- package/dist/agent-session-execution.d.ts +44 -0
- package/dist/agent-session-execution.js +18 -0
- package/dist/agent-session-inbox.d.ts +1 -0
- package/dist/agent-session-inbox.js +5 -0
- package/dist/agent-session-stale-run.d.ts +22 -0
- package/dist/agent-worker-context.js +8 -65
- package/dist/agent-worker.d.ts +4 -0
- package/dist/agent-worker.js +239 -139
- package/dist/evals-core.d.ts +20 -0
- package/dist/evals-core.js +147 -0
- package/dist/evals.d.ts +4 -0
- package/dist/evals.js +60 -110
- package/dist/experimental/agent-core-worker-tools.d.ts +7 -3
- package/dist/gea-core.d.ts +25 -0
- package/dist/gea-core.js +96 -0
- package/dist/host-rejection.d.ts +23 -0
- package/dist/host-rejection.js +39 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/runtime-selected-connector-tool.d.ts +34 -0
- package/dist/runtime-selected-connector-tool.js +40 -0
- package/dist/runtime-team-skill-tools.d.ts +1104 -0
- package/dist/runtime-team-skill-tools.js +31 -0
- package/dist/session-authority.d.ts +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/agent-core.wasm
CHANGED
|
Binary file
|
|
@@ -46,7 +46,29 @@ export declare function completeAgentSessionInvocation(tx: AgentSessionTransacti
|
|
|
46
46
|
status: "aborted" | "completed" | "failed";
|
|
47
47
|
occurredAt: string;
|
|
48
48
|
usage: import("ai").LanguageModelUsage | null;
|
|
49
|
+
termination?: {
|
|
50
|
+
finishReason?: "length" | "stop" | "tool_calls" | undefined;
|
|
51
|
+
provider?: {
|
|
52
|
+
format: "openai-completions";
|
|
53
|
+
reason: "length" | "stop" | "tool_calls";
|
|
54
|
+
} | {
|
|
55
|
+
format: "anthropic-messages";
|
|
56
|
+
reason: "end_turn" | "max_tokens" | "refusal" | "stop_sequence" | "tool_use";
|
|
57
|
+
} | {
|
|
58
|
+
format: "openai-responses";
|
|
59
|
+
reason: "completed" | "max_output_tokens";
|
|
60
|
+
} | undefined;
|
|
61
|
+
step?: number | undefined;
|
|
62
|
+
attempt?: number | undefined;
|
|
63
|
+
sessionAttemptId?: string | undefined;
|
|
64
|
+
requestId?: string | undefined;
|
|
65
|
+
} | undefined;
|
|
49
66
|
}[] | undefined;
|
|
67
|
+
diagnostics?: {
|
|
68
|
+
coreReason: "awaiting_approval" | "awaiting_tool_results" | "cancelled" | "completed" | "failed" | "model_limit" | "step_limit" | "stopped";
|
|
69
|
+
maxSteps?: number | undefined;
|
|
70
|
+
maxRetries?: number | undefined;
|
|
71
|
+
} | undefined;
|
|
50
72
|
attempt: number;
|
|
51
73
|
completedAt: string;
|
|
52
74
|
status: "aborted" | "error" | "finished" | "interrupted";
|
|
@@ -76,7 +98,29 @@ export declare function reclaimAgentSessionRun(tx: AgentSessionTransactionStorag
|
|
|
76
98
|
status: "aborted" | "completed" | "failed";
|
|
77
99
|
occurredAt: string;
|
|
78
100
|
usage: import("ai").LanguageModelUsage | null;
|
|
101
|
+
termination?: {
|
|
102
|
+
finishReason?: "length" | "stop" | "tool_calls" | undefined;
|
|
103
|
+
provider?: {
|
|
104
|
+
format: "openai-completions";
|
|
105
|
+
reason: "length" | "stop" | "tool_calls";
|
|
106
|
+
} | {
|
|
107
|
+
format: "anthropic-messages";
|
|
108
|
+
reason: "end_turn" | "max_tokens" | "refusal" | "stop_sequence" | "tool_use";
|
|
109
|
+
} | {
|
|
110
|
+
format: "openai-responses";
|
|
111
|
+
reason: "completed" | "max_output_tokens";
|
|
112
|
+
} | undefined;
|
|
113
|
+
step?: number | undefined;
|
|
114
|
+
attempt?: number | undefined;
|
|
115
|
+
sessionAttemptId?: string | undefined;
|
|
116
|
+
requestId?: string | undefined;
|
|
117
|
+
} | undefined;
|
|
79
118
|
}[] | undefined;
|
|
119
|
+
diagnostics?: {
|
|
120
|
+
coreReason: "awaiting_approval" | "awaiting_tool_results" | "cancelled" | "completed" | "failed" | "model_limit" | "step_limit" | "stopped";
|
|
121
|
+
maxSteps?: number | undefined;
|
|
122
|
+
maxRetries?: number | undefined;
|
|
123
|
+
} | undefined;
|
|
80
124
|
attempt: number;
|
|
81
125
|
completedAt: string;
|
|
82
126
|
status: "aborted" | "error" | "finished" | "interrupted";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { agentExecutionDiagnosticsSchema, } from "@gea-ai/contract/agent-usage";
|
|
1
2
|
import { digestAgentSessionMessage } from "./agent-session-transport.js";
|
|
2
3
|
import { getSessionPayload, putSessionPayload } from "./agent-session-payload.js";
|
|
3
4
|
import { agentModelCallsSchema, } from "@gea-ai/contract/agent-usage";
|
|
@@ -164,6 +165,8 @@ export async function appendAgentSessionInputMessages(tx, messages, runId) {
|
|
|
164
165
|
await advanceRevision(tx);
|
|
165
166
|
}
|
|
166
167
|
async function writeValues(tx, input) {
|
|
168
|
+
if (input.diagnostics !== undefined)
|
|
169
|
+
await tx.put(key(`diagnostics:${encodeURIComponent(input.runId)}:${encodeURIComponent(input.attemptId)}`), agentExecutionDiagnosticsSchema.parse(input.diagnostics));
|
|
167
170
|
for (const output of input.toolOutputs ?? [])
|
|
168
171
|
await putSessionPayload(tx, `tool-output:${output.id}`, output.content);
|
|
169
172
|
let messageSequence = (await tx.get(key("message-sequence"))) ?? 0;
|
|
@@ -352,6 +355,7 @@ export async function completeAgentSessionInvocation(tx, input) {
|
|
|
352
355
|
input.events.length === 0 &&
|
|
353
356
|
!input.context &&
|
|
354
357
|
input.modelCalls === undefined &&
|
|
358
|
+
input.diagnostics === undefined &&
|
|
355
359
|
input.toolOutputs === undefined;
|
|
356
360
|
const state = await getAgentSessionRunState(tx, input.runId);
|
|
357
361
|
if (state?.status === "draining")
|
|
@@ -375,6 +379,7 @@ export async function completeAgentSessionInvocation(tx, input) {
|
|
|
375
379
|
input.events.length === 0 &&
|
|
376
380
|
input.context === undefined &&
|
|
377
381
|
input.modelCalls === undefined &&
|
|
382
|
+
input.diagnostics === undefined &&
|
|
378
383
|
input.toolOutputs === undefined &&
|
|
379
384
|
input.accounting === undefined;
|
|
380
385
|
// Cancelling a waiting turn closes it directly: pausing already revoked its
|
|
@@ -386,6 +391,7 @@ export async function completeAgentSessionInvocation(tx, input) {
|
|
|
386
391
|
input.events.length === 0 &&
|
|
387
392
|
!input.context &&
|
|
388
393
|
input.modelCalls === undefined &&
|
|
394
|
+
input.diagnostics === undefined &&
|
|
389
395
|
input.toolOutputs === undefined;
|
|
390
396
|
const turn = state?.status === "terminal" &&
|
|
391
397
|
waiting &&
|
|
@@ -402,7 +408,11 @@ export async function completeAgentSessionInvocation(tx, input) {
|
|
|
402
408
|
const previousRevision = await readRevision(tx);
|
|
403
409
|
await writeValues(tx, input);
|
|
404
410
|
const modelCalls = await tx.get(key(`model-calls:${encodeURIComponent(input.runId)}`));
|
|
411
|
+
const diagnostics = await tx.get(key(`diagnostics:${encodeURIComponent(input.runId)}:${encodeURIComponent(input.attemptId)}`));
|
|
405
412
|
const outcome = {
|
|
413
|
+
...(diagnostics === undefined
|
|
414
|
+
? {}
|
|
415
|
+
: { diagnostics: agentExecutionDiagnosticsSchema.parse(diagnostics) }),
|
|
406
416
|
...(modelCalls === undefined
|
|
407
417
|
? {}
|
|
408
418
|
: { modelCalls: agentModelCallsSchema.parse(modelCalls) }),
|
|
@@ -918,6 +928,7 @@ export async function handleAgentSessionExecutionRequest(request, storage) {
|
|
|
918
928
|
input.events.length === 0 &&
|
|
919
929
|
!input.context &&
|
|
920
930
|
input.modelCalls === undefined &&
|
|
931
|
+
input.diagnostics === undefined &&
|
|
921
932
|
input.toolOutputs === undefined;
|
|
922
933
|
const state = await getAgentSessionRunState(tx, input.runId);
|
|
923
934
|
if (state?.status === "draining")
|
|
@@ -943,6 +954,7 @@ export async function handleAgentSessionExecutionRequest(request, storage) {
|
|
|
943
954
|
input.events.length === 0 &&
|
|
944
955
|
input.context === undefined &&
|
|
945
956
|
input.modelCalls === undefined &&
|
|
957
|
+
input.diagnostics === undefined &&
|
|
946
958
|
input.toolOutputs === undefined &&
|
|
947
959
|
input.accounting === undefined;
|
|
948
960
|
const turn = state?.status === "terminal" &&
|
|
@@ -960,7 +972,13 @@ export async function handleAgentSessionExecutionRequest(request, storage) {
|
|
|
960
972
|
const previousRevision = await readRevision(tx);
|
|
961
973
|
await writeValues(tx, stored ? { ...input, messages: [] } : input);
|
|
962
974
|
const modelCalls = await tx.get(key(`model-calls:${encodeURIComponent(input.runId)}`));
|
|
975
|
+
const diagnostics = await tx.get(key(`diagnostics:${encodeURIComponent(input.runId)}:${encodeURIComponent(input.attemptId)}`));
|
|
963
976
|
const outcome = {
|
|
977
|
+
...(diagnostics === undefined
|
|
978
|
+
? {}
|
|
979
|
+
: {
|
|
980
|
+
diagnostics: agentExecutionDiagnosticsSchema.parse(diagnostics),
|
|
981
|
+
}),
|
|
964
982
|
...(modelCalls === undefined
|
|
965
983
|
? {}
|
|
966
984
|
: { modelCalls: agentModelCallsSchema.parse(modelCalls) }),
|
|
@@ -124,6 +124,7 @@ export declare function getAppServerSessionAdmission(tx: AgentSessionTransaction
|
|
|
124
124
|
turnId: string;
|
|
125
125
|
metadata?: Record<string, z.util.JSONType> | undefined;
|
|
126
126
|
messages: {
|
|
127
|
+
runtimeResourceSourceRunId?: string | undefined;
|
|
127
128
|
id: string;
|
|
128
129
|
runId?: string | undefined;
|
|
129
130
|
sender: {
|
|
@@ -342,6 +342,11 @@ function takeMessages(state, steeringOnly) {
|
|
|
342
342
|
for (const entry of state.messages) {
|
|
343
343
|
if (steeringOnly && entry.mode !== "steering")
|
|
344
344
|
continue;
|
|
345
|
+
if (!steeringOnly &&
|
|
346
|
+
messages.length &&
|
|
347
|
+
entry.runtimeResourceSourceRunId !==
|
|
348
|
+
messages[0].runtimeResourceSourceRunId)
|
|
349
|
+
break;
|
|
345
350
|
const size = new TextEncoder().encode(JSON.stringify(entry)).byteLength;
|
|
346
351
|
const count = (typeof entry.message === "string" ? 1 : entry.message.parts.length) +
|
|
347
352
|
(entry.sender.type === "agent" ? 1 : 0);
|
|
@@ -13,7 +13,29 @@ export declare function handleStaleAgentSessionRun(storage: AgentSessionStorage,
|
|
|
13
13
|
status: "aborted" | "completed" | "failed";
|
|
14
14
|
occurredAt: string;
|
|
15
15
|
usage: import("ai").LanguageModelUsage | null;
|
|
16
|
+
termination?: {
|
|
17
|
+
finishReason?: "length" | "stop" | "tool_calls" | undefined;
|
|
18
|
+
provider?: {
|
|
19
|
+
format: "openai-completions";
|
|
20
|
+
reason: "length" | "stop" | "tool_calls";
|
|
21
|
+
} | {
|
|
22
|
+
format: "anthropic-messages";
|
|
23
|
+
reason: "end_turn" | "max_tokens" | "refusal" | "stop_sequence" | "tool_use";
|
|
24
|
+
} | {
|
|
25
|
+
format: "openai-responses";
|
|
26
|
+
reason: "completed" | "max_output_tokens";
|
|
27
|
+
} | undefined;
|
|
28
|
+
step?: number | undefined;
|
|
29
|
+
attempt?: number | undefined;
|
|
30
|
+
sessionAttemptId?: string | undefined;
|
|
31
|
+
requestId?: string | undefined;
|
|
32
|
+
} | undefined;
|
|
16
33
|
}[] | undefined;
|
|
34
|
+
diagnostics?: {
|
|
35
|
+
coreReason: "awaiting_approval" | "awaiting_tool_results" | "cancelled" | "completed" | "failed" | "model_limit" | "step_limit" | "stopped";
|
|
36
|
+
maxSteps?: number | undefined;
|
|
37
|
+
maxRetries?: number | undefined;
|
|
38
|
+
} | undefined;
|
|
17
39
|
attempt: number;
|
|
18
40
|
completedAt: string;
|
|
19
41
|
status: "aborted" | "error" | "finished" | "interrupted";
|
|
@@ -484,59 +484,6 @@ function makeSummaryMessage(summaryText) {
|
|
|
484
484
|
].join("\n"),
|
|
485
485
|
};
|
|
486
486
|
}
|
|
487
|
-
function makeFallbackSummary(chatId, error) {
|
|
488
|
-
const message = getCompactionErrorMessage(error);
|
|
489
|
-
const summaryText = [
|
|
490
|
-
"## Current Goal\n- Continue from the recent raw tail.",
|
|
491
|
-
"## User Requirements and Constraints\n- Recover older exact details from raw chat history when needed.",
|
|
492
|
-
"## Important Decisions\n- Older history was dropped after context compaction failed.",
|
|
493
|
-
"## Progress So Far\n- No reliable compact summary was produced.",
|
|
494
|
-
"## Files, Artifacts, and Paths\n### Read\n- Unknown.\n### Modified\n- Unknown.\n### Created\n- Unknown.\n### Offloaded Artifacts\n- Check the recent tail and raw history.",
|
|
495
|
-
"## Tool Results and Observations Worth Preserving\n- Unknown from failed compaction.",
|
|
496
|
-
"## Errors, Failed Attempts, and Warnings\n- Context compaction failed; details are in runtime metadata.",
|
|
497
|
-
"## Open Questions\n- Whether older raw history is still needed.",
|
|
498
|
-
"## Next Steps\n- Continue from the recent tail and recover raw history if required.",
|
|
499
|
-
"## Critical Exact Details\n- The compactable raw history remains available through chat history.",
|
|
500
|
-
`## Raw Chat Recovery\n- Chat id: \`${chatId}\`.\n- Use \`gea chat messages\` to retrieve exact raw messages.`,
|
|
501
|
-
].join("\n\n");
|
|
502
|
-
return {
|
|
503
|
-
contextSummary: {
|
|
504
|
-
compactionError: { message, partialSummaryText: false },
|
|
505
|
-
createdAt: new Date().toISOString(),
|
|
506
|
-
rawHistoryRecovery: { chatId },
|
|
507
|
-
summaryText,
|
|
508
|
-
},
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
function getCompactionErrorMessage(error) {
|
|
512
|
-
return error instanceof Error && error.message.trim()
|
|
513
|
-
? error.message.trim().slice(0, 1_000)
|
|
514
|
-
: "Unknown summarizer error";
|
|
515
|
-
}
|
|
516
|
-
function makePartialSummary(input) {
|
|
517
|
-
const missingHeadings = REQUIRED_SUMMARY_HEADINGS.filter((heading) => !input.summaryText.includes(heading));
|
|
518
|
-
return {
|
|
519
|
-
compactionError: {
|
|
520
|
-
message: getCompactionErrorMessage(input.error),
|
|
521
|
-
partialSummaryText: true,
|
|
522
|
-
},
|
|
523
|
-
createdAt: new Date().toISOString(),
|
|
524
|
-
rawHistoryRecovery: { chatId: input.chatId },
|
|
525
|
-
summaryText: [
|
|
526
|
-
"## Context Compaction Warning",
|
|
527
|
-
"- The summarizer stream failed after producing partial text. Verify important details against raw history.",
|
|
528
|
-
"",
|
|
529
|
-
input.summaryText.trim(),
|
|
530
|
-
"",
|
|
531
|
-
"## Raw Chat Recovery",
|
|
532
|
-
`- Chat id: \`${input.chatId}\`.`,
|
|
533
|
-
"- Use `gea chat messages` to retrieve exact raw messages if compacted details are missing.",
|
|
534
|
-
].join("\n"),
|
|
535
|
-
...(missingHeadings.length > 0
|
|
536
|
-
? { validationWarning: { missingHeadings } }
|
|
537
|
-
: {}),
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
487
|
export { addAgentModelUsage as addAgentWorkerUsage } from "@gea-ai/contract/agent-usage";
|
|
541
488
|
export async function compactAgentWorkerContext(input) {
|
|
542
489
|
const options = input.options ?? defaultAgentContextOptionsSchema.parse({});
|
|
@@ -619,7 +566,6 @@ export async function compactAgentWorkerContext(input) {
|
|
|
619
566
|
.slice(splitIndex)
|
|
620
567
|
.flatMap((group) => group.messages);
|
|
621
568
|
let summaryText = "";
|
|
622
|
-
let outcome = "applied";
|
|
623
569
|
let summaryUsage = null;
|
|
624
570
|
try {
|
|
625
571
|
const summaryMessages = buildSummaryMessages({
|
|
@@ -653,6 +599,7 @@ export async function compactAgentWorkerContext(input) {
|
|
|
653
599
|
if (completion.finishReason !== "stop") {
|
|
654
600
|
// The provider call still counts toward usage, but an incomplete
|
|
655
601
|
// summary must not replace the previous summary or active history.
|
|
602
|
+
span.recordError(new Error(`Context summarizer finished with ${completion.finishReason}.`));
|
|
656
603
|
span.setAttributes({
|
|
657
604
|
"gea.context.compaction.outcome": "rejected",
|
|
658
605
|
"gea.context.compaction.finish_reason": completion.finishReason,
|
|
@@ -681,21 +628,17 @@ export async function compactAgentWorkerContext(input) {
|
|
|
681
628
|
}
|
|
682
629
|
catch (error) {
|
|
683
630
|
input.signal?.throwIfAborted();
|
|
684
|
-
|
|
685
|
-
span.
|
|
686
|
-
"
|
|
631
|
+
span.recordError(error instanceof Error ? error : String(error));
|
|
632
|
+
span.setAttributes({
|
|
633
|
+
"gea.context.compaction.outcome": "rejected",
|
|
634
|
+
"gea.context.messages.output_count": input.context.messages.length,
|
|
687
635
|
});
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
chatId: input.chatId,
|
|
691
|
-
error,
|
|
692
|
-
summaryText,
|
|
693
|
-
})
|
|
694
|
-
: makeFallbackSummary(input.chatId, error).contextSummary;
|
|
636
|
+
// A failed or partial summary cannot replace the original task/history.
|
|
637
|
+
return { summaryUsage, messagesUpdated };
|
|
695
638
|
}
|
|
696
639
|
input.context.messages = recentTail;
|
|
697
640
|
span.setAttributes({
|
|
698
|
-
"gea.context.compaction.outcome":
|
|
641
|
+
"gea.context.compaction.outcome": "applied",
|
|
699
642
|
"gea.context.messages.output_count": recentTail.length,
|
|
700
643
|
});
|
|
701
644
|
await input.persist?.();
|
package/dist/agent-worker.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { extractChannelReply } from "./agent-channel-api.js";
|
|
|
7
7
|
import { type AgentInteractionPolicy } from "@gea-ai/contract";
|
|
8
8
|
import type { AgentTracing } from "@gea-ai/contract/agent-tracing";
|
|
9
9
|
import type { AgentContextStrategy } from "./context.js";
|
|
10
|
+
import { agentInitializationFailure } from "@gea-ai/contract/agent-worker-tools";
|
|
10
11
|
import { type AgentSessionInboxExecution } from "@gea-ai/contract/agent-session-inbox";
|
|
11
12
|
import type { AgentWorkerToolInitialization } from "@gea-ai/contract/agent-worker-tools";
|
|
12
13
|
import { type ComputerProcessOperation } from "@gea-ai/contract/computer-commands";
|
|
@@ -110,6 +111,9 @@ export type AgentApplicationDefinition = {
|
|
|
110
111
|
type AgentStartupTiming = {
|
|
111
112
|
startedAt: number;
|
|
112
113
|
phases: Record<string, number>;
|
|
114
|
+
failure?: ReturnType<typeof agentInitializationFailure> & {
|
|
115
|
+
phase: string;
|
|
116
|
+
};
|
|
113
117
|
};
|
|
114
118
|
export declare function composeFetch<TEnvironment, TContext>(...handlers: ReadonlyArray<ComposableFetch<TEnvironment, TContext>>): (request: Request, environment: TEnvironment, context: TContext) => Promise<Response>;
|
|
115
119
|
export declare function createAgentApplicationFetch<TEnvironment extends AgentFetchEnvironment = AgentFetchEnvironment, TContext = unknown>(input: {
|