@vercel/agent-runs 1.0.1 → 1.1.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/CHANGELOG.md +5 -5
- package/dist/src/adapters/agent-transport.d.ts.map +1 -1
- package/dist/src/adapters/agent-transport.js +0 -1
- package/dist/src/adapters/agent-transport.js.map +1 -1
- package/dist/src/adapters/ai-sdk-payload.d.ts +2 -0
- package/dist/src/adapters/ai-sdk-payload.d.ts.map +1 -1
- package/dist/src/adapters/ai-sdk-payload.js +2 -0
- package/dist/src/adapters/ai-sdk-payload.js.map +1 -1
- package/dist/src/adapters/ai-sdk-telemetry.d.ts +1 -0
- package/dist/src/adapters/ai-sdk-telemetry.d.ts.map +1 -1
- package/dist/src/adapters/ai-sdk-telemetry.js +0 -1
- package/dist/src/adapters/ai-sdk-telemetry.js.map +1 -1
- package/dist/src/adapters/otel-error.d.ts +0 -1
- package/dist/src/adapters/otel-error.d.ts.map +1 -1
- package/dist/src/adapters/otel-error.js +0 -2
- package/dist/src/adapters/otel-error.js.map +1 -1
- package/dist/src/adapters/otel.d.ts +8 -0
- package/dist/src/adapters/otel.d.ts.map +1 -1
- package/dist/src/adapters/otel.js +8 -6
- package/dist/src/adapters/otel.js.map +1 -1
- package/dist/src/adapters/serialization.d.ts +3 -12
- package/dist/src/adapters/serialization.d.ts.map +1 -1
- package/dist/src/adapters/serialization.js +3 -19
- package/dist/src/adapters/serialization.js.map +1 -1
- package/dist/src/agent-run.d.ts +14 -0
- package/dist/src/agent-run.d.ts.map +1 -1
- package/dist/src/agent-run.js +4 -13
- package/dist/src/agent-run.js.map +1 -1
- package/dist/src/ai-sdk.d.ts +0 -5
- package/dist/src/ai-sdk.d.ts.map +1 -1
- package/dist/src/ai-sdk.js +0 -5
- package/dist/src/ai-sdk.js.map +1 -1
- package/dist/src/capture.d.ts +2 -0
- package/dist/src/capture.d.ts.map +1 -1
- package/dist/src/capture.js +2 -0
- package/dist/src/capture.js.map +1 -1
- package/dist/src/core/attributes.d.ts +1 -1
- package/dist/src/core/attributes.d.ts.map +1 -1
- package/dist/src/core/attributes.js +1 -1
- package/dist/src/core/attributes.js.map +1 -1
- package/dist/src/core/content-policy.d.ts +0 -21
- package/dist/src/core/content-policy.d.ts.map +1 -1
- package/dist/src/core/content-policy.js +0 -28
- package/dist/src/core/content-policy.js.map +1 -1
- package/dist/src/core/context.d.ts +0 -1
- package/dist/src/core/context.d.ts.map +1 -1
- package/dist/src/core/context.js +0 -1
- package/dist/src/core/context.js.map +1 -1
- package/dist/src/core/delegation.d.ts +3 -0
- package/dist/src/core/delegation.d.ts.map +1 -1
- package/dist/src/core/delegation.js +2 -0
- package/dist/src/core/delegation.js.map +1 -1
- package/dist/src/core/mcp.d.ts +3 -0
- package/dist/src/core/mcp.d.ts.map +1 -1
- package/dist/src/core/mcp.js +1 -0
- package/dist/src/core/mcp.js.map +1 -1
- package/dist/src/core/scopes.d.ts +0 -11
- package/dist/src/core/scopes.d.ts.map +1 -1
- package/dist/src/core/scopes.js +0 -13
- package/dist/src/core/scopes.js.map +1 -1
- package/dist/src/core/snapshot.d.ts.map +1 -1
- package/dist/src/core/snapshot.js +0 -21
- package/dist/src/core/snapshot.js.map +1 -1
- package/dist/src/core/span-kinds.d.ts +1 -0
- package/dist/src/core/span-kinds.d.ts.map +1 -1
- package/dist/src/core/span-kinds.js +1 -7
- package/dist/src/core/span-kinds.js.map +1 -1
- package/dist/src/core/types.d.ts +15 -1
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/writer.d.ts +0 -1
- package/dist/src/core/writer.d.ts.map +1 -1
- package/dist/src/core/writer.js.map +1 -1
- package/dist/src/operations.d.ts +14 -0
- package/dist/src/operations.d.ts.map +1 -1
- package/dist/src/operations.js +0 -1
- package/dist/src/operations.js.map +1 -1
- package/dist/src/otel.d.ts +0 -5
- package/dist/src/otel.d.ts.map +1 -1
- package/dist/src/otel.js +0 -5
- package/dist/src/otel.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/agent-transport.ts +0 -1
- package/src/adapters/ai-sdk-payload.ts +2 -0
- package/src/adapters/ai-sdk-telemetry.ts +1 -1
- package/src/adapters/otel-error.ts +0 -2
- package/src/adapters/otel.ts +10 -6
- package/src/adapters/serialization.ts +3 -19
- package/src/agent-run.ts +14 -21
- package/src/ai-sdk.ts +0 -5
- package/src/capture.ts +2 -0
- package/src/core/attributes.ts +1 -1
- package/src/core/content-policy.ts +0 -29
- package/src/core/context.ts +0 -1
- package/src/core/delegation.ts +3 -0
- package/src/core/mcp.ts +3 -0
- package/src/core/scopes.ts +0 -23
- package/src/core/snapshot.ts +0 -21
- package/src/core/span-kinds.ts +1 -7
- package/src/core/types.ts +15 -1
- package/src/core/writer.ts +0 -1
- package/src/operations.ts +14 -1
- package/src/otel.ts +0 -5
package/dist/src/operations.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ type Completion = ScopeTerminal & {
|
|
|
4
4
|
errorType?: string;
|
|
5
5
|
result?: ModelResult;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* A handle to one traced operation, such as a turn, attempt, model call, or tool call.
|
|
9
|
+
* Use it to run work inside the operation's span, add attributes, and complete or fail it.
|
|
10
|
+
*/
|
|
7
11
|
export interface Operation {
|
|
8
12
|
readonly type: ScopeData["type"];
|
|
9
13
|
readonly reference: TraceReference;
|
|
@@ -27,6 +31,7 @@ export interface WrappedOperation<I, H extends Operation> {
|
|
|
27
31
|
type MemoryInput = Extract<ScopeData, {
|
|
28
32
|
type: "memory";
|
|
29
33
|
}>["options"];
|
|
34
|
+
/** Identifies one attempt of a turn's step by step index and attempt number, with optional runtime context, channel, and links. */
|
|
30
35
|
export interface AttemptInput {
|
|
31
36
|
readonly stepIndex: number;
|
|
32
37
|
readonly attempt: number;
|
|
@@ -34,6 +39,7 @@ export interface AttemptInput {
|
|
|
34
39
|
readonly channel?: StepOptions["channel"];
|
|
35
40
|
readonly links?: readonly TraceLink[];
|
|
36
41
|
}
|
|
42
|
+
/** A traced agent turn. Start attempts, memory calls, and turn-level approvals under it. */
|
|
37
43
|
export interface TurnOperation extends Operation {
|
|
38
44
|
attempt: WrappedOperation<AttemptInput, AttemptOperation>;
|
|
39
45
|
/** Returns an open attempt without starting one. Durable turns only. */
|
|
@@ -68,6 +74,7 @@ export interface ApprovalInput {
|
|
|
68
74
|
export interface ToolInput extends ToolOptions {
|
|
69
75
|
readonly startTimeMs?: number;
|
|
70
76
|
}
|
|
77
|
+
/** A traced attempt of one turn step. Start model calls, model streams, tool calls, agent delegations, and memory calls under it. */
|
|
71
78
|
export interface AttemptOperation extends Operation {
|
|
72
79
|
tool: WrappedOperation<ToolInput, ToolOperation>;
|
|
73
80
|
callSubAgent: WrappedOperation<{
|
|
@@ -83,6 +90,7 @@ export interface AttemptOperation extends Operation {
|
|
|
83
90
|
modelStream<T>(input: ModelOptions, execute: () => ModelStreamReturn<T> | PromiseLike<ModelStreamReturn<T>>): Promise<T>;
|
|
84
91
|
memory: WrappedOperation<MemoryInput, MemoryOperation>;
|
|
85
92
|
}
|
|
93
|
+
/** A traced tool call. Start approvals, nested tool calls, and memory calls under it. */
|
|
86
94
|
export interface ToolOperation extends Operation {
|
|
87
95
|
approval: WrappedOperation<ApprovalInput, ApprovalOperation>;
|
|
88
96
|
/** Returns an open approval without starting one. Durable turns only. */
|
|
@@ -91,13 +99,19 @@ export interface ToolOperation extends Operation {
|
|
|
91
99
|
tool: WrappedOperation<ToolInput, ToolOperation>;
|
|
92
100
|
memory: WrappedOperation<MemoryInput, MemoryOperation>;
|
|
93
101
|
}
|
|
102
|
+
/** A traced model call, as returned by `AttemptOperation.modelCall` without a callback. */
|
|
94
103
|
export type ModelOperation = Operation;
|
|
104
|
+
/** A traced wait on a person, such as a tool approval or a sign-in. */
|
|
95
105
|
export type ApprovalOperation = Operation;
|
|
106
|
+
/** A traced memory search or write. */
|
|
96
107
|
export type MemoryOperation = Operation;
|
|
108
|
+
/** A traced call to a decision model, such as choosing a model for a turn. */
|
|
97
109
|
export type DecisionOperation = Operation;
|
|
110
|
+
/** What a `modelCall` callback returns: the call's `result` with its finish reason, usage, and optional response metadata and content. */
|
|
98
111
|
export interface ModelCallReturn<T> extends ModelResult {
|
|
99
112
|
readonly result: T;
|
|
100
113
|
}
|
|
114
|
+
/** What a `modelStream` callback returns: the stream as `result`, returned unchanged, and a `completion` promise that settles with the model result when the stream ends. */
|
|
101
115
|
export interface ModelStreamReturn<T> {
|
|
102
116
|
readonly result: T;
|
|
103
117
|
readonly completion: PromiseLike<ModelResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,SAAS,EACT,aAAa,EACb,YAAY,EACZ,WAAW,EACX,WAAW,EACX,eAAe,EACf,UAAU,EACV,cAAc,EACd,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAEzB,KAAK,UAAU,GAAG,aAAa,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC;AAC/E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,CAAC,CAAC;IACvD,UAAU,CAAC,UAAU,EAAE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AAM,cAAc,GAAG,SAAS,CAAC;AACvC,uEAAuE;AACvE,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAC1C,uCAAuC;AACvC,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC;AACxC,8EAA8E;AAC9E,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAC1C,0IAA0I;AAC1I,MAAM,WAAW,eAAe,CAAC,CAAC,CAAE,SAAQ,WAAW;IACrD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;CACpB;AACD,6KAA6K;AAC7K,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnB,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;CAC/C;AAWD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,EACrD,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAC/B,QAAQ,GAAE,UAAqC,EAC/C,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAsCxB;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,SAAS,EACf,OAAO,CAAC,EAAE,iBAAiB,GAC1B,aAAa,GAAG,gBAAgB,GAAG,aAAa,GAAG,SAAS,CA4K9D"}
|
package/dist/src/operations.js
CHANGED
|
@@ -168,7 +168,6 @@ export function operationHandle(runtime, data, onError) {
|
|
|
168
168
|
});
|
|
169
169
|
return common;
|
|
170
170
|
}
|
|
171
|
-
/** Tool calls can nest, so a call ID is searched through every open call of the turn. */
|
|
172
171
|
function findTool(parent, callId) {
|
|
173
172
|
for (const next of parent.children) {
|
|
174
173
|
if (next.type === "tool" && next.callId === callId)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/operations.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,CAAC,KAAK,CAAC,CAAC;oBAC3B,CAAC;oBAAC,OAAO,YAAY,EAAE,CAAC;wBACtB,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;oBAC5C,CAAC;oBACD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;SACkB,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QACtB,OAAO,IAAI,CAAC;YACV,GAAG,MAAM;YACT,MAAM;YACN,IAAI;YACJ,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;SAC1D,CAAC,CAAC;IACtB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,QAAQ,CAAC,MAAqB,EAAE,MAAc;IACrD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,IAAI,CAAC;QAChE,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACrC,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,KAAK,CAAC;QACxC,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/src/otel.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenTelemetry plumbing for hosts that run their own spans beside agent
|
|
3
|
-
* tracing: active-operation lookup, capture context, content bounds, and MCP
|
|
4
|
-
* enrichment. Agent tracing itself needs only the package root.
|
|
5
|
-
*/
|
|
6
1
|
export { activeTraceOperation, withErrorContent } from "./adapters/otel.js";
|
|
7
2
|
export { withCapture } from "./capture.js";
|
|
8
3
|
export { boundedPrincipalId, contentAttribute, telemetryByteLength, truncateTelemetryText, CONTENT_ATTRIBUTE_LIMIT, } from "./adapters/serialization.js";
|
package/dist/src/otel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../src/otel.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"otel.d.ts","sourceRoot":"","sources":["../../src/otel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/src/otel.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenTelemetry plumbing for hosts that run their own spans beside agent
|
|
3
|
-
* tracing: active-operation lookup, capture context, content bounds, and MCP
|
|
4
|
-
* enrichment. Agent tracing itself needs only the package root.
|
|
5
|
-
*/
|
|
6
1
|
export { activeTraceOperation, withErrorContent } from "./adapters/otel.js";
|
|
7
2
|
export { withCapture } from "./capture.js";
|
|
8
3
|
export { boundedPrincipalId, contentAttribute, telemetryByteLength, truncateTelemetryText, CONTENT_ATTRIBUTE_LIMIT, } from "./adapters/serialization.js";
|
package/dist/src/otel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel.js","sourceRoot":"","sources":["../../src/otel.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"otel.js","sourceRoot":"","sources":["../../src/otel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAA+B,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAqC,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -27,7 +27,6 @@ function agentTraceFetch(fetcher: typeof fetch, maxBytes: number): typeof fetch
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/** The host validates provenance; well-formed trace metadata is not authorization. */
|
|
31
30
|
function receiveAgentTrace<T>(
|
|
32
31
|
headers: Headers,
|
|
33
32
|
trusted: (handoff: AgentHandoff) => boolean,
|
|
@@ -9,6 +9,7 @@ interface Result {
|
|
|
9
9
|
content: readonly unknown[];
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/** Converts an AI SDK usage object into a {@link Usage}, for hosts that record model calls themselves. */
|
|
12
13
|
export function modelUsage(usage: Result["usage"]): Usage {
|
|
13
14
|
return Object.freeze({
|
|
14
15
|
inputTokens: usage.inputTokens,
|
|
@@ -20,6 +21,7 @@ export function modelUsage(usage: Result["usage"]): Usage {
|
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
/** Converts AI SDK result content into {@link ContentPart}s, keeping text, reasoning, and tool call, result, and error parts and dropping the rest. */
|
|
23
25
|
export function modelContent(content: Result["content"]): readonly ContentPart[] {
|
|
24
26
|
return content.flatMap((part): ContentPart[] => {
|
|
25
27
|
if (part === null || typeof part !== "object" || !("type" in part)) return [];
|
|
@@ -10,6 +10,7 @@ import { modelContent, modelUsage } from "./ai-sdk-payload.js";
|
|
|
10
10
|
|
|
11
11
|
type Event<K extends keyof Telemetry & `on${string}`> = Parameters<NonNullable<Telemetry[K]>>[0];
|
|
12
12
|
|
|
13
|
+
/** Options for `aiSdkTelemetry`. */
|
|
13
14
|
export interface AiSdkTelemetryOptions {
|
|
14
15
|
/** The turn a generation records. Called once per AI SDK call. */
|
|
15
16
|
readonly turn: TurnInput | ((call: { readonly callId: string }) => TurnInput);
|
|
@@ -167,7 +168,6 @@ export function aiSdkTelemetry(run: AgentRun, options: AiSdkTelemetryOptions): T
|
|
|
167
168
|
await finish(event.callId, (turn) => turn.complete({ outcome: "cancelled" }));
|
|
168
169
|
},
|
|
169
170
|
async onError(value: unknown) {
|
|
170
|
-
// Some agents report the bare error; it then belongs to every open call.
|
|
171
171
|
const { callId, error } =
|
|
172
172
|
value !== null && typeof value === "object" && "callId" in value && "error" in value
|
|
173
173
|
? (value as { callId: string; error: unknown })
|
|
@@ -3,13 +3,11 @@ import { boundedTraceError } from "./serialization.js";
|
|
|
3
3
|
import { truncateTelemetryText } from "./serialization.js";
|
|
4
4
|
import { contentAttribute, textContentAttribute } from "./serialization.js";
|
|
5
5
|
|
|
6
|
-
/** Call with policy-projected errors; undefined retains failure status without content. */
|
|
7
6
|
export function recordAgentSpanError(span: Span, error: unknown, errorType?: string): void {
|
|
8
7
|
span.setAttribute(
|
|
9
8
|
"error.type",
|
|
10
9
|
truncateTelemetryText(errorType ?? (error instanceof Error ? error.name : "_OTHER"), 128),
|
|
11
10
|
);
|
|
12
|
-
// A thrown Error keeps its own name; a wrapped value takes the error type.
|
|
13
11
|
const wrapped = error !== undefined && !(error instanceof Error);
|
|
14
12
|
if (wrapped) {
|
|
15
13
|
const serialized = contentAttribute(error);
|
package/src/adapters/otel.ts
CHANGED
|
@@ -28,7 +28,9 @@ import { withCapture } from "../capture.js";
|
|
|
28
28
|
type Context = OtelContext;
|
|
29
29
|
const ACTIVE_OPERATION = createContextKey("agent.tracing.active-operation");
|
|
30
30
|
const SUPPRESS_TRACING_KEY = createContextKey("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
|
|
31
|
+
const AGENT_RUNS_SCOPE = "vercel.ai.tracing";
|
|
31
32
|
|
|
33
|
+
/** Returns `context` with a capture decision that allows or declines recording error content, such as exception messages, for spans started under it. */
|
|
32
34
|
export function withErrorContent<T extends { setValue(key: symbol, value: unknown): T }>(
|
|
33
35
|
context: T,
|
|
34
36
|
allowed: boolean,
|
|
@@ -40,6 +42,11 @@ function suppressTracing(context: Context): Context {
|
|
|
40
42
|
return context.setValue(SUPPRESS_TRACING_KEY, true);
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Returns the agent tracing operation active in an OpenTelemetry context, defaulting to the current one,
|
|
47
|
+
* or `undefined` outside any operation. Use it to read the active span's reference and capture decision
|
|
48
|
+
* from spans the host runs itself.
|
|
49
|
+
*/
|
|
43
50
|
export function activeTraceOperation(
|
|
44
51
|
host: Pick<Context, "getValue"> = context.active(),
|
|
45
52
|
): ActiveOperation | undefined {
|
|
@@ -81,10 +88,6 @@ function mappedAttributes(
|
|
|
81
88
|
return mapping?.attributes(span, attributes) ?? attributes;
|
|
82
89
|
}
|
|
83
90
|
|
|
84
|
-
/**
|
|
85
|
-
* Applied when the host passes no mapping. On Vercel it adds the session ID
|
|
86
|
-
* Agent Runs uses to find a run's spans.
|
|
87
|
-
*/
|
|
88
91
|
const DEFAULT_MAPPING: OutputMapping = {
|
|
89
92
|
attributes(_span, attributes) {
|
|
90
93
|
const runId = attributes["agent.run.id"];
|
|
@@ -101,6 +104,7 @@ function onVercel(): boolean {
|
|
|
101
104
|
return env?.VERCEL_ENV !== undefined;
|
|
102
105
|
}
|
|
103
106
|
|
|
107
|
+
/** Options for `otelTelemetry`. */
|
|
104
108
|
export interface OtelTelemetryOptions {
|
|
105
109
|
/** Defaults to the global tracer provider. */
|
|
106
110
|
readonly provider?: TracerProvider;
|
|
@@ -116,6 +120,7 @@ export interface OtelTelemetryOptions {
|
|
|
116
120
|
) => boolean;
|
|
117
121
|
/** Replaces the default mapping, which adds `vercel.session_id` on Vercel. */
|
|
118
122
|
readonly mapping?: OutputMapping;
|
|
123
|
+
/** Defaults to `vercel.ai.tracing`, a scope Vercel Agent Runs reads. Another name keeps the spans out of Agent Runs. */
|
|
119
124
|
readonly tracerName?: string;
|
|
120
125
|
/** Recorded as the spans' instrumentation scope version. */
|
|
121
126
|
readonly tracerVersion?: string;
|
|
@@ -127,7 +132,7 @@ export interface OtelTelemetryOptions {
|
|
|
127
132
|
/** OpenTelemetry implementation of {@link AgentTelemetry}. */
|
|
128
133
|
export function otelTelemetry(options: OtelTelemetryOptions = {}): AgentTelemetry {
|
|
129
134
|
const provider = options.provider ?? trace.getTracerProvider();
|
|
130
|
-
const tracer = provider.getTracer(options.tracerName ??
|
|
135
|
+
const tracer = provider.getTracer(options.tracerName ?? AGENT_RUNS_SCOPE, options.tracerVersion);
|
|
131
136
|
const mapping = options.mapping ?? DEFAULT_MAPPING;
|
|
132
137
|
const idGenerator = options.idGenerator;
|
|
133
138
|
function lifecycle(method: "forceFlush" | "shutdown"): () => Promise<void> {
|
|
@@ -203,7 +208,6 @@ export function otelTelemetry(options: OtelTelemetryOptions = {}): AgentTelemetr
|
|
|
203
208
|
},
|
|
204
209
|
run(operation, execute, executionContext) {
|
|
205
210
|
let capture = intersectCapture(operation.capture, activeTraceOperation()?.capture);
|
|
206
|
-
// Retain baggage and host context while replacing the semantic parent span.
|
|
207
211
|
let active = trace.setSpan(
|
|
208
212
|
(executionContext as Context | undefined) ?? context.active(),
|
|
209
213
|
trace.wrapSpanContext(otelReference(operation.reference)),
|
|
@@ -27,10 +27,12 @@ const encoder = new TextEncoder();
|
|
|
27
27
|
const decoder = new TextDecoder();
|
|
28
28
|
const MARKER = "... [truncated]";
|
|
29
29
|
|
|
30
|
+
/** Returns the UTF-8 byte length of `text`. */
|
|
30
31
|
export function telemetryByteLength(text: string): number {
|
|
31
32
|
return encoder.encode(text).length;
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/** Truncates `text` to at most `maxBytes` UTF-8 bytes without splitting a character, ending it with a `... [truncated]` marker when it is cut. */
|
|
34
36
|
export function truncateTelemetryText(text: string, maxBytes: number): string {
|
|
35
37
|
const prefix = text.slice(0, maxBytes + 1);
|
|
36
38
|
const bytes = encoder.encode(prefix);
|
|
@@ -41,6 +43,7 @@ export function truncateTelemetryText(text: string, maxBytes: number): string {
|
|
|
41
43
|
return decoder.decode(bytes.subarray(0, end)) + marker;
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
/** Returns `value` when it is a non-empty string of at most 1024 characters and 1024 UTF-8 bytes, and `undefined` otherwise, so an identifier is safe to record on a span. */
|
|
44
47
|
export function boundedPrincipalId(value: unknown): string | undefined {
|
|
45
48
|
return typeof value === "string" &&
|
|
46
49
|
value.length > 0 &&
|
|
@@ -70,7 +73,6 @@ export function contentAttribute(value: unknown): string | undefined {
|
|
|
70
73
|
return textContentAttribute(json);
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
/** Serializes model messages using the OpenTelemetry GenAI message schema. */
|
|
74
76
|
export function genAiInputMessagesAttribute(
|
|
75
77
|
messages: unknown,
|
|
76
78
|
messageKind?: (value: unknown) => string | undefined,
|
|
@@ -87,8 +89,6 @@ export function genAiInputMessagesAttribute(
|
|
|
87
89
|
kind === undefined ? { parts, role: message.role } : { kind, parts, role: message.role },
|
|
88
90
|
];
|
|
89
91
|
});
|
|
90
|
-
// Drop the fewest oldest messages that fit: the fit is monotone in how many
|
|
91
|
-
// are dropped, so binary search it instead of stringifying every prefix.
|
|
92
92
|
let low = 0;
|
|
93
93
|
let high = formatted.length;
|
|
94
94
|
while (low < high) {
|
|
@@ -105,14 +105,12 @@ export function genAiInputMessagesAttribute(
|
|
|
105
105
|
return { json: "[]", omitted: formatted.length };
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/** Serializes the system prompt using the OpenTelemetry GenAI instruction schema. */
|
|
109
108
|
export function genAiSystemInstructionsAttribute(instructions: unknown): string | undefined {
|
|
110
109
|
const text = systemPromptText(instructions);
|
|
111
110
|
if (text === undefined) return undefined;
|
|
112
111
|
return fitSemanticText(text, (content) => [{ content, type: "text" }]);
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
/** Serializes one model response using the OpenTelemetry GenAI message schema. */
|
|
116
114
|
export function genAiOutputMessagesAttribute(
|
|
117
115
|
content: readonly unknown[],
|
|
118
116
|
finishReason: string,
|
|
@@ -122,7 +120,6 @@ export function genAiOutputMessagesAttribute(
|
|
|
122
120
|
const message = (messageParts: unknown) => [
|
|
123
121
|
{ finish_reason: reason, parts: messageParts, role: "assistant" },
|
|
124
122
|
];
|
|
125
|
-
// An oversized response keeps a truncated text form, as an oversized prompt does.
|
|
126
123
|
return (
|
|
127
124
|
semanticJsonAttribute(message(parts)) ??
|
|
128
125
|
fitSemanticText(
|
|
@@ -133,17 +130,10 @@ export function genAiOutputMessagesAttribute(
|
|
|
133
130
|
);
|
|
134
131
|
}
|
|
135
132
|
|
|
136
|
-
/** Serializes memory records using the OpenTelemetry GenAI memory-records schema. */
|
|
137
133
|
export function genAiMemoryRecordsAttribute(records: readonly unknown[]): string | undefined {
|
|
138
134
|
return semanticJsonAttribute(records);
|
|
139
135
|
}
|
|
140
136
|
|
|
141
|
-
/**
|
|
142
|
-
* Serializes provider-executed tool results, keeping the attribute valid
|
|
143
|
-
* JSON under the cap: when the full payload is too big, each entry's input
|
|
144
|
-
* and output collapse to capped text at progressively smaller budgets
|
|
145
|
-
* instead of cutting the JSON mid-string.
|
|
146
|
-
*/
|
|
147
137
|
export function toolResultsContentAttribute(
|
|
148
138
|
results: readonly Record<string, unknown>[],
|
|
149
139
|
): string | undefined {
|
|
@@ -168,7 +158,6 @@ function cappedToolResult(entry: Record<string, unknown>, cap: number): Record<s
|
|
|
168
158
|
return out;
|
|
169
159
|
}
|
|
170
160
|
|
|
171
|
-
/** Serializes tool definitions, dropping trailing entries to keep the JSON whole. */
|
|
172
161
|
export function genAiToolDefinitionsAttribute(tools: unknown): string | undefined {
|
|
173
162
|
if (!Array.isArray(tools)) return undefined;
|
|
174
163
|
const definitions = tools.flatMap((tool): Record<string, unknown>[] => {
|
|
@@ -193,7 +182,6 @@ export function genAiToolDefinitionsAttribute(tools: unknown): string | undefine
|
|
|
193
182
|
return `[${serialized.join(",")}]`;
|
|
194
183
|
}
|
|
195
184
|
|
|
196
|
-
/** Normalizes the AI SDK's `instructions` prompt to plain text. */
|
|
197
185
|
function systemPromptText(instructions: unknown): string | undefined {
|
|
198
186
|
if (typeof instructions === "string") return instructions.length === 0 ? undefined : instructions;
|
|
199
187
|
if (!isRecord(instructions) && !Array.isArray(instructions)) return undefined;
|
|
@@ -211,7 +199,6 @@ function systemPromptText(instructions: unknown): string | undefined {
|
|
|
211
199
|
return joined.length === 0 ? undefined : joined;
|
|
212
200
|
}
|
|
213
201
|
|
|
214
|
-
/** Caps plain text, marking the cut. */
|
|
215
202
|
export function textContentAttribute(text: string): string | undefined {
|
|
216
203
|
if (text.length === 0) return undefined;
|
|
217
204
|
return text.length <= CONTENT_ATTRIBUTE_LIMIT
|
|
@@ -258,9 +245,6 @@ function fitSemanticText(
|
|
|
258
245
|
const full = semanticJsonAttribute(wrap(text));
|
|
259
246
|
if (full !== undefined) return full;
|
|
260
247
|
}
|
|
261
|
-
// Binary search the largest cut that fits: each probe stringifies one
|
|
262
|
-
// candidate, so an attribute far over the cap costs a logarithmic number of
|
|
263
|
-
// encodes instead of re-encoding a near-full candidate every 256 characters.
|
|
264
248
|
const candidate = (length: number): string | undefined =>
|
|
265
249
|
semanticJsonAttribute(wrap(`${text.slice(0, length)}… [truncated]`));
|
|
266
250
|
let best: string | undefined;
|
package/src/agent-run.ts
CHANGED
|
@@ -27,6 +27,7 @@ import type {
|
|
|
27
27
|
TraceReference,
|
|
28
28
|
} from "./core/types.js";
|
|
29
29
|
|
|
30
|
+
/** Options for {@link createAgentRun}. */
|
|
30
31
|
export interface AgentRunOptions {
|
|
31
32
|
/** Span output and context propagation. Defaults to the global OpenTelemetry provider. */
|
|
32
33
|
readonly telemetry?: AgentTelemetry;
|
|
@@ -39,13 +40,16 @@ export interface AgentRunOptions {
|
|
|
39
40
|
readonly checkpointer?: TraceCheckpointer;
|
|
40
41
|
/** Defaults to the AI SDK content serializer. */
|
|
41
42
|
readonly serializer?: ContentSerializer;
|
|
43
|
+
/** Receives tracing failures, which never reach the traced work. See {@link TraceErrorHandler}. */
|
|
42
44
|
readonly onError?: TraceErrorHandler;
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
/** Describes one agent turn for `AgentRun.turn`: its run identity, sequence, and optional capture, lineage, and trace placement. */
|
|
45
48
|
export interface TurnInput {
|
|
46
49
|
readonly identity: RunIdentity;
|
|
47
50
|
/** Names the invocation span. Omit for an anonymous agent. */
|
|
48
51
|
readonly agentName?: string;
|
|
52
|
+
/** Position of this turn within the run. */
|
|
49
53
|
readonly sequence: number;
|
|
50
54
|
readonly framework?: FrameworkIdentity;
|
|
51
55
|
readonly capture?: CaptureDecision;
|
|
@@ -73,6 +77,7 @@ export interface TurnInput {
|
|
|
73
77
|
readonly context?: ExecutionContext;
|
|
74
78
|
}
|
|
75
79
|
|
|
80
|
+
/** Identifies a saved durable turn for `AgentRun.resume`. */
|
|
76
81
|
export interface ResumeInput {
|
|
77
82
|
readonly identity: RunIdentity;
|
|
78
83
|
readonly context?: ExecutionContext;
|
|
@@ -112,6 +117,10 @@ export interface DecisionInput {
|
|
|
112
117
|
readonly context?: ExecutionContext;
|
|
113
118
|
}
|
|
114
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Traces agent execution: start turns, resume saved durable turns, record memory and decision calls,
|
|
122
|
+
* and flush or shut down the telemetry. Create one with {@link createAgentRun}.
|
|
123
|
+
*/
|
|
115
124
|
export interface AgentRun {
|
|
116
125
|
turn: WrappedOperation<TurnInput, TurnOperation>;
|
|
117
126
|
/** Returns a saved durable turn, without starting one. */
|
|
@@ -121,6 +130,7 @@ export interface AgentRun {
|
|
|
121
130
|
forceFlush(): Promise<void>;
|
|
122
131
|
shutdown(): Promise<void>;
|
|
123
132
|
}
|
|
133
|
+
/** Records a memory search or write as one memory span around `execute`, under the active operation unless `parent` is given. */
|
|
124
134
|
export interface AgentMemoryTracing {
|
|
125
135
|
search<T>(data: MemoryInput<T>, execute: () => T | PromiseLike<T>): Promise<T>;
|
|
126
136
|
write<T>(data: MemoryInput<T>, execute: () => T | PromiseLike<T>): Promise<T>;
|
|
@@ -132,22 +142,18 @@ const LIVE_TURNS = 1000;
|
|
|
132
142
|
|
|
133
143
|
interface LiveTurn {
|
|
134
144
|
readonly root: LiveOperation;
|
|
135
|
-
/** Token of the last checkpoint this process wrote. */
|
|
136
145
|
revision: string | undefined;
|
|
137
|
-
/**
|
|
138
|
-
* Every checkpoint token this tree wrote. A checkpoint store scoped to an
|
|
139
|
-
* execution context (eve keeps it in the serialized workflow context) can
|
|
140
|
-
* hand a concurrent hook an older checkpoint of this same tree; that is not
|
|
141
|
-
* another process's write and must not fork the tree.
|
|
142
|
-
*/
|
|
143
146
|
readonly revisions: Set<string>;
|
|
144
|
-
/** Replaced by another process's checkpoint: the tree still records spans but no longer persists. */
|
|
145
147
|
retired: boolean;
|
|
146
148
|
writes: number;
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
const REVISIONS_PER_TURN = 10000;
|
|
150
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Creates an {@link AgentRun} that records agent turns, attempts, model calls, and tool calls as spans.
|
|
155
|
+
* Pass a `checkpointer` to make turns durable across processes.
|
|
156
|
+
*/
|
|
151
157
|
export function createAgentRun(input: AgentRunOptions): AgentRun {
|
|
152
158
|
const telemetry = input.telemetry ?? otelTelemetry();
|
|
153
159
|
const checkpointer = input.checkpointer;
|
|
@@ -166,8 +172,6 @@ export function createAgentRun(input: AgentRunOptions): AgentRun {
|
|
|
166
172
|
durable: checkpointer !== undefined,
|
|
167
173
|
onError: input.onError,
|
|
168
174
|
});
|
|
169
|
-
// Turns hydrated in this process, so concurrent hooks share one tree. The
|
|
170
|
-
// checkpoint stays authoritative: another process's write replaces the entry.
|
|
171
175
|
const live = new Map<string, Promise<LiveTurn | undefined>>();
|
|
172
176
|
|
|
173
177
|
function turnKey(identity: RunIdentity): string {
|
|
@@ -175,7 +179,6 @@ export function createAgentRun(input: AgentRunOptions): AgentRun {
|
|
|
175
179
|
return ["turn", identity.runId, identity.turnId].map(encodeURIComponent).join(":");
|
|
176
180
|
}
|
|
177
181
|
|
|
178
|
-
/** Writes are serialized so a slow store never persists an older tree last. */
|
|
179
182
|
function persistence(key: string, entry: () => LiveTurn | undefined) {
|
|
180
183
|
let queue = Promise.resolve();
|
|
181
184
|
return () => {
|
|
@@ -230,13 +233,9 @@ export function createAgentRun(input: AgentRunOptions): AgentRun {
|
|
|
230
233
|
(savedRevision !== undefined && cached.revisions.has(savedRevision)))
|
|
231
234
|
) {
|
|
232
235
|
if (context !== undefined) cached.root.useContext(context);
|
|
233
|
-
// A re-entry may decline content the cached turn was allowed to record.
|
|
234
236
|
if (capture !== undefined) cached.root.narrow(capture);
|
|
235
237
|
return cached;
|
|
236
238
|
}
|
|
237
|
-
// Another process wrote this checkpoint, so it replaces the cached tree.
|
|
238
|
-
// Callers may still hold the cached tree's operations; keep them from
|
|
239
|
-
// persisting their older view over the newer checkpoint.
|
|
240
239
|
if (cached !== undefined) cached.retired = true;
|
|
241
240
|
let entry: LiveTurn | undefined;
|
|
242
241
|
const onChange = persistence(key, () => entry);
|
|
@@ -380,17 +379,11 @@ export function createAgentRun(input: AgentRunOptions): AgentRun {
|
|
|
380
379
|
return value;
|
|
381
380
|
}
|
|
382
381
|
|
|
383
|
-
/**
|
|
384
|
-
* The active operation owns the decision. A span the host started inside it, in the same
|
|
385
|
-
* trace, nests the decision further; a span from another trace, such as a workflow step,
|
|
386
|
-
* does not.
|
|
387
|
-
*/
|
|
388
382
|
async function decision(data: DecisionInput): Promise<DecisionOperation> {
|
|
389
383
|
const active = telemetry.active();
|
|
390
384
|
const owner = active?.reference ?? data.parent;
|
|
391
385
|
const span = telemetry.activeSpan?.(data.context);
|
|
392
386
|
const parent = owner === undefined || span?.traceId === owner.traceId ? span : owner;
|
|
393
|
-
// A decision joins its parent's sampling decision whatever sampler the provider uses.
|
|
394
387
|
const sampled = parent === undefined || (parent.traceFlags & 1) !== 0;
|
|
395
388
|
const live = await scopes.start({
|
|
396
389
|
identity: {
|
package/src/ai-sdk.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AI SDK integration. `aiSdkTelemetry` records `generateText`, `streamText`,
|
|
3
|
-
* and AI SDK agents as turns; `modelUsage` and `modelContent` convert AI SDK
|
|
4
|
-
* payloads for hosts that record model calls themselves.
|
|
5
|
-
*/
|
|
6
1
|
export { aiSdkTelemetry, type AiSdkTelemetryOptions } from "./adapters/ai-sdk-telemetry.js";
|
|
7
2
|
export { modelUsage, modelContent } from "./adapters/ai-sdk-payload.js";
|
package/src/capture.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { context, createContextKey } from "@opentelemetry/api";
|
|
|
2
2
|
import type { CaptureDecision } from "./core/types.js";
|
|
3
3
|
|
|
4
4
|
const CAPTURE = createContextKey("agent.tracing.capture");
|
|
5
|
+
/** Returns the capture decision set on the active OpenTelemetry context, or `undefined` when none is set. */
|
|
5
6
|
export function currentCapture(): CaptureDecision | undefined {
|
|
6
7
|
return context.active().getValue(CAPTURE) as CaptureDecision | undefined;
|
|
7
8
|
}
|
|
9
|
+
/** Returns `host` with `capture` set as its capture decision, which {@link currentCapture} reads while it is active. */
|
|
8
10
|
export function withCapture<T extends { setValue(key: symbol, value: unknown): T }>(
|
|
9
11
|
host: T,
|
|
10
12
|
capture: CaptureDecision,
|
package/src/core/attributes.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AttributeValue, Attributes, FrameworkIdentity, RunIdentity, Usage } from "./types.js";
|
|
2
2
|
const TRACE_SCHEMA_VERSION = 4;
|
|
3
|
+
/** Span attribute names that usage cost and token counts are recorded under. */
|
|
3
4
|
export const USAGE_FIELDS = {
|
|
4
5
|
costUsd: "agent.usage.cost_usd",
|
|
5
6
|
inputTokens: "agent.usage.input_tokens",
|
|
@@ -29,7 +30,6 @@ export function frameworkAttributes(framework?: FrameworkIdentity): Attributes {
|
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
/** Invocation and model spans use GenAI token counts; structural spans use eve's. */
|
|
33
33
|
export function usageAttributes(usage: Usage, genAi = false): Attributes {
|
|
34
34
|
if (genAi)
|
|
35
35
|
return {
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Which span attributes carry conversation content, and in which direction.
|
|
3
|
-
*
|
|
4
|
-
* Two vocabularies land on the same spans: the ones the library sets on its own
|
|
5
|
-
* `agent.*` spans, and the ones the AI SDK's OpenTelemetry integration sets on
|
|
6
|
-
* the model-call spans beneath them. A destination that declined content has to
|
|
7
|
-
* be rid of both, so both are listed here rather than in the module that writes
|
|
8
|
-
* each.
|
|
9
|
-
*
|
|
10
|
-
* Listed by name rather than by prefix because the prefixes are shared with
|
|
11
|
-
* metadata that must survive: `ai.response.finish_reason` and
|
|
12
|
-
* `gen_ai.tool.name` say what happened, not what was said. The cost is that a
|
|
13
|
-
* new content attribute in a dependency is not covered until it is added here.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/** Prompts, instructions, tool arguments — what went in. */
|
|
17
1
|
const INPUT_CONTENT_ATTRIBUTES: ReadonlySet<string> = new Set([
|
|
18
2
|
"agent.channel.delivery.input",
|
|
19
3
|
"agent.session.title",
|
|
@@ -31,12 +15,6 @@ const INPUT_CONTENT_ATTRIBUTES: ReadonlySet<string> = new Set([
|
|
|
31
15
|
"gen_ai.tool.definitions",
|
|
32
16
|
]);
|
|
33
17
|
|
|
34
|
-
/**
|
|
35
|
-
* Responses, reasoning, tool results — what came out.
|
|
36
|
-
*
|
|
37
|
-
* `ai.toolCall.args` is here rather than above because the AI SDK gates it on
|
|
38
|
-
* `recordOutputs`; matching that is what keeps one destination's view coherent.
|
|
39
|
-
*/
|
|
40
18
|
const OUTPUT_CONTENT_ATTRIBUTES: ReadonlySet<string> = new Set([
|
|
41
19
|
"agent.approval.response",
|
|
42
20
|
"ai.embedding",
|
|
@@ -90,13 +68,6 @@ function exportedAttributeValue(
|
|
|
90
68
|
return value;
|
|
91
69
|
}
|
|
92
70
|
|
|
93
|
-
/**
|
|
94
|
-
* Re-applies the capture-policy attributes that a size-based content strip
|
|
95
|
-
* must not rewrite. Dropping content to fit a checkpoint budget is not the
|
|
96
|
-
* destination declining it, so `agent.trace.content.input` and
|
|
97
|
-
* `agent.trace.content.output` keep the record's real decision; otherwise a
|
|
98
|
-
* restored turn would report "omitted" although capture was on.
|
|
99
|
-
*/
|
|
100
71
|
export function preservingCapturePolicy(
|
|
101
72
|
attributes: Readonly<Record<string, unknown>>,
|
|
102
73
|
original: Readonly<Record<string, unknown>>,
|
package/src/core/context.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ActiveOperation, AgentTelemetry, ExecutionContext } from "./types.js";
|
|
2
2
|
|
|
3
|
-
/** Runs `execute` exactly once, even when the telemetry cannot enter the context. */
|
|
4
3
|
export function runTraceContext<T>(
|
|
5
4
|
telemetry: Pick<AgentTelemetry, "run" | "suppressed">,
|
|
6
5
|
operation: ActiveOperation,
|
package/src/core/delegation.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { context, createContextKey } from "@opentelemetry/api";
|
|
2
2
|
import type { CaptureDecision, TraceReference } from "./types.js";
|
|
3
3
|
|
|
4
|
+
/** Lineage a delegating tool call passes to the agent it calls: the caller's span, run, call, and capture ceiling. */
|
|
4
5
|
export interface AgentHandoff {
|
|
5
6
|
readonly caller: TraceReference;
|
|
6
7
|
readonly conversationId: string;
|
|
@@ -13,8 +14,10 @@ export interface AgentHandoff {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const HANDOFF = createContextKey("agent.tracing.handoff");
|
|
17
|
+
/** Returns the handoff active in the current context, or `undefined` outside a delegated call. */
|
|
16
18
|
export const currentAgentHandoff = () =>
|
|
17
19
|
context.active().getValue(HANDOFF) as AgentHandoff | undefined;
|
|
20
|
+
/** Runs `execute` with `handoff` active, so turns started inside it record the delegating call as their parent. */
|
|
18
21
|
export function withAgentHandoff<T>(handoff: AgentHandoff, execute: () => T): T {
|
|
19
22
|
return context.with(context.active().setValue(HANDOFF, handoff), execute);
|
|
20
23
|
}
|