@coalex-ai/sdk 2.2.1 → 2.3.0-beta.686

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 CHANGED
@@ -110,6 +110,27 @@ Convenience functions to instrument a single library.
110
110
  instrumentOpenAI(); // returns boolean
111
111
  ```
112
112
 
113
+ ### LangChain.js
114
+
115
+ With `@arizeai/openinference-instrumentation-langchain` 4.x installed, `autoInstrument()` captures
116
+ LangChain.js 0.3 and 1.x (`@langchain/core`) in a CommonJS app: `LLM`, `CHAIN`, `PROMPT` and `TOOL`
117
+ spans. Call `register()` first, since the spans go to the globally registered provider and not to
118
+ a `tracerProvider` option, and instrument before the app first loads LangChain. On its first call
119
+ the result reads `langchain: "already_instrumented"` although the instrumentation is active.
120
+
121
+ In an ESM app neither `autoInstrument()` nor `autoInstrumentAsync()` captures LangChain yet. Hand
122
+ the instrumentor LangChain's callback manager instead, before your LangChain code runs:
123
+
124
+ ```typescript
125
+ import { LangChainInstrumentation } from "@arizeai/openinference-instrumentation-langchain";
126
+
127
+ register({ apiKey: process.env.COALEX_API_KEY, serviceName: "my-agent" });
128
+ new LangChainInstrumentation().manuallyInstrument(await import("@langchain/core/callbacks/manager"));
129
+ ```
130
+
131
+ Which lines are proven, and on which versions:
132
+ [Supported Frameworks](https://docs.coalex.ai/reference/supported-frameworks/).
133
+
113
134
  ### `coalexContext(options, fn)` / `coalexContextSync(options, fn)`
114
135
 
115
136
  Wrap a function in a traced Coalex invocation span.
@@ -147,6 +168,23 @@ await coalexContext(
147
168
  );
148
169
  ```
149
170
 
171
+ #### Several agents in one process
172
+
173
+ A context opened inside another agent's context belongs to the inner agent: its spans carry
174
+ `coalex.parent_agent_id` (the enclosing agent) and the enclosing `requestId` / `runId`, but not
175
+ the enclosing agent's version or prompt. `agentNode` wraps a LangGraph node function so each node
176
+ is its own agent, re-opened on every resume, and a LangGraph pause (`interrupt()`) ends the span
177
+ OK rather than as an error. `currentAgentId()`, `currentParentAgentId()`, `currentRequestId()`,
178
+ `currentRunId()` and `currentAgentVersion()` read the active context.
179
+
180
+ ```typescript
181
+ graph.addNode("rfq", agentNode("rfq-worker", rfqWorker, { version: "1.4.0" }));
182
+
183
+ await coalexContext({ agentId: "orchestrator", requestId, runId, version: "2.0.0" }, () =>
184
+ graph.compile({ checkpointer }).invoke(state, config),
185
+ );
186
+ ```
187
+
150
188
  ### `evaluate(options)`
151
189
 
152
190
  Submit an AI output for evaluation. Returns the governance decision.
package/dist/context.d.ts CHANGED
@@ -1,22 +1,53 @@
1
- /** Record the prompt version/type served by the most recent getPrompt() (COA-368). */
1
+ /**
2
+ * Everything the active coalexContext() says about the work in progress. One store for the whole
3
+ * context, so the propagator, evaluate() and the getters read the same values, and a concurrent
4
+ * invocation of another agent cannot see them.
5
+ */
6
+ interface ActiveContext {
7
+ agentId: string;
8
+ parentAgentId?: string;
9
+ requestId?: string;
10
+ runId?: string;
11
+ version?: string;
12
+ promptVersion?: number;
13
+ promptType?: string;
14
+ }
15
+ /** The active context, or undefined outside one. For the propagator; not exported publicly. */
16
+ export declare function activeContext(): Readonly<ActiveContext> | undefined;
17
+ /**
18
+ * Record the prompt version/type getPrompt() served: on the active context when there is one,
19
+ * otherwise as the process-wide startup prompt (COA-368).
20
+ */
2
21
  export declare function setLastPrompt(version: number, type: string): void;
3
- /** The prompt version/type from the most recent getPrompt(), or null. */
22
+ /** The prompt of the active context, or the startup prompt outside one, or null. */
4
23
  export declare function getLastPrompt(): {
5
24
  version: number;
6
25
  type: string;
7
26
  } | null;
8
- /** Reset the prompt fallback. Used by coalexContext() to restore the prior value on exit. */
27
+ /** Forget the prompt: the active context's, or the startup prompt outside one. */
9
28
  export declare function clearLastPrompt(): void;
10
29
  /**
11
- * Return the agentId of the active coalexContext(), or undefined outside one.
12
- * Lets evaluate() propagate the agentId for mid-run escalations that fire before
13
- * the trace ingests, so the server resolves the agent instead of forcing health=0
14
- * (COA-1076).
30
+ * Return the agentId of the active coalexContext(), or undefined outside one. evaluate() reads it
31
+ * so a mid-run escalation names its agent before the trace is ingested.
15
32
  */
16
33
  export declare function currentAgentId(): string | undefined;
34
+ /** The requestId of the active coalexContext(), given or carried from an outer one. */
35
+ export declare function currentRequestId(): string | undefined;
36
+ /** The runId of the active coalexContext(), given or carried from an outer one. */
37
+ export declare function currentRunId(): string | undefined;
38
+ /** The agent version of the active coalexContext(), or undefined when it has none. */
39
+ export declare function currentAgentVersion(): string | undefined;
40
+ /** The agent whose context the active one opened inside, or undefined for a top-level agent. */
41
+ export declare function currentParentAgentId(): string | undefined;
17
42
  export interface CoalexContextOptions {
18
43
  agentId: string;
44
+ /** The customer's correlation key for one unit of business work. Carried from an enclosing context when omitted. */
19
45
  requestId?: string;
46
+ /**
47
+ * One execution of an agent graph, across interrupts and resumes. Carried from an enclosing
48
+ * context when omitted. Never derive it from a framework's thread or session id.
49
+ */
50
+ runId?: string;
20
51
  /**
21
52
  * The build this invocation is running. Optional today, and omitting it logs a warning once
22
53
  * per agent per process (COA-2636): a trace with no version cannot be attributed to a build,
@@ -53,6 +84,40 @@ export interface CoalexContextOptions {
53
84
  export declare function missingVersionGuidance(agentId: string): string;
54
85
  /** Forget which agents have been warned about. For tests; the registry is process-global. */
55
86
  export declare function resetVersionWarnings(): void;
87
+ /** The `coalex.*` attributes a context puts on its spans, in the propagator's order. */
88
+ export declare function contextAttributes(ctx: Readonly<ActiveContext>): Record<string, string | number>;
89
+ /**
90
+ * The LangGraph errors that carry a pause or a hand-off up through a node, not a failure.
91
+ * Recognised by name on the error and on every class of its prototype chain, so this SDK never
92
+ * imports LangGraph, a subclass (`NodeInterrupt`) is recognised, and so is a bundled copy whose
93
+ * class names were minified (LangGraph sets `name` on each).
94
+ */
95
+ export declare const PAUSE_ERROR_NAMES: ReadonlySet<string>;
96
+ export declare function isPause(e: unknown): boolean;
97
+ /**
98
+ * Run `fn` inside a `coalex.invocation` span for `options.agentId`; every span started inside it
99
+ * carries the context's `coalex.*` attributes.
100
+ *
101
+ * Nested inside another agent's context it sets `coalex.parent_agent_id` to that agent, carries
102
+ * `requestId` and `runId`, and inherits neither version nor prompt; inside the same agent it
103
+ * inherits everything. A LangGraph pause (`GraphBubbleUp`, `GraphInterrupt`, `ParentCommand`)
104
+ * ends the span OK and is re-thrown; any other error ends it ERROR.
105
+ */
56
106
  export declare function coalexContext<T>(options: CoalexContextOptions, fn: () => Promise<T> | T): Promise<T>;
57
107
  export declare function coalexContextSync<T>(options: CoalexContextOptions, fn: () => T): T;
108
+ /**
109
+ * Wrap a LangGraph node function so everything it does belongs to `agentId`.
110
+ *
111
+ * Wrap the **node function**, not the graph's `invoke`: LangGraph re-executes the node from the
112
+ * top on every resume (`new Command({ resume })`), so the context opens again for the resumed work
113
+ * and the node's checkpoint namespace is unchanged. The context carries the enclosing `requestId`
114
+ * and `runId`, names the enclosing agent as `coalex.parent_agent_id`, and a pause (`interrupt()`)
115
+ * leaves its span OK. Every argument (`state`, `config`) is passed through.
116
+ *
117
+ * graph.addNode("w1_rfq", agentNode("rfq-worker", rfqWorker, { version: "1.4.0" }));
118
+ */
119
+ export declare function agentNode<A extends unknown[], R>(agentId: string, fn: (...args: A) => Promise<R> | R, options?: {
120
+ version?: string;
121
+ }): (...args: A) => Promise<R>;
122
+ export {};
58
123
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAgBA,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjE;AAED,yEAAyE;AACzE,wBAAgB,aAAa,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAExE;AAED,6FAA6F;AAC7F,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG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,GAAG,OAAO,CAQ3C;AAYD;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAmBZ;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,MAAM,CAAC,GACV,CAAC,CAmBH;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC9C,OAAO,EAAE,MAAM,EACf,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAClC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GACjC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAK5B"}
package/dist/context.js CHANGED
@@ -1,36 +1,73 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { trace, SpanStatusCode } from "@opentelemetry/api";
3
3
  import { log } from "./logger.js";
4
- const agentIdStore = new AsyncLocalStorage();
4
+ const contextStore = new AsyncLocalStorage();
5
+ /** The active context, or undefined outside one. For the propagator; not exported publicly. */
6
+ export function activeContext() {
7
+ return contextStore.getStore();
8
+ }
5
9
  /**
6
- * The prompt version + type last fetched via getPrompt(), used as a fallback so spans can be
7
- * attributed to a prompt version even when getPrompt() ran at startup outside any span (COA-368).
8
- *
9
- * This is process-global (not async-context-scoped) so it survives a startup fetch into later
10
- * request spans — the common case. Under concurrent getPrompt() calls for *different* versions in
11
- * the same process the last write wins; the Python SDK's contextvar is the more precise analogue.
10
+ * The prompt version + type fetched via getPrompt() outside any coalexContext() (a startup fetch),
11
+ * so later invocations of that agent and spans outside any context are still attributed (COA-368).
12
+ * Inside a context, getPrompt() writes to that context instead, so concurrent invocations of
13
+ * different agents never see each other's prompt.
14
+ */
15
+ let _startupPrompt = null;
16
+ /**
17
+ * Record the prompt version/type getPrompt() served: on the active context when there is one,
18
+ * otherwise as the process-wide startup prompt (COA-368).
12
19
  */
13
- let _lastPrompt = null;
14
- /** Record the prompt version/type served by the most recent getPrompt() (COA-368). */
15
20
  export function setLastPrompt(version, type) {
16
- _lastPrompt = { version, type };
21
+ const active = contextStore.getStore();
22
+ if (active) {
23
+ active.promptVersion = version;
24
+ active.promptType = type;
25
+ return;
26
+ }
27
+ _startupPrompt = { version, type };
17
28
  }
18
- /** The prompt version/type from the most recent getPrompt(), or null. */
29
+ /** The prompt of the active context, or the startup prompt outside one, or null. */
19
30
  export function getLastPrompt() {
20
- return _lastPrompt;
31
+ const active = contextStore.getStore();
32
+ if (active) {
33
+ return active.promptVersion === undefined
34
+ ? null
35
+ : { version: active.promptVersion, type: active.promptType ?? "system" };
36
+ }
37
+ return _startupPrompt;
21
38
  }
22
- /** Reset the prompt fallback. Used by coalexContext() to restore the prior value on exit. */
39
+ /** Forget the prompt: the active context's, or the startup prompt outside one. */
23
40
  export function clearLastPrompt() {
24
- _lastPrompt = null;
41
+ const active = contextStore.getStore();
42
+ if (active) {
43
+ active.promptVersion = undefined;
44
+ active.promptType = undefined;
45
+ return;
46
+ }
47
+ _startupPrompt = null;
25
48
  }
26
49
  /**
27
- * Return the agentId of the active coalexContext(), or undefined outside one.
28
- * Lets evaluate() propagate the agentId for mid-run escalations that fire before
29
- * the trace ingests, so the server resolves the agent instead of forcing health=0
30
- * (COA-1076).
50
+ * Return the agentId of the active coalexContext(), or undefined outside one. evaluate() reads it
51
+ * so a mid-run escalation names its agent before the trace is ingested.
31
52
  */
32
53
  export function currentAgentId() {
33
- return agentIdStore.getStore();
54
+ return contextStore.getStore()?.agentId;
55
+ }
56
+ /** The requestId of the active coalexContext(), given or carried from an outer one. */
57
+ export function currentRequestId() {
58
+ return contextStore.getStore()?.requestId;
59
+ }
60
+ /** The runId of the active coalexContext(), given or carried from an outer one. */
61
+ export function currentRunId() {
62
+ return contextStore.getStore()?.runId;
63
+ }
64
+ /** The agent version of the active coalexContext(), or undefined when it has none. */
65
+ export function currentAgentVersion() {
66
+ return contextStore.getStore()?.version;
67
+ }
68
+ /** The agent whose context the active one opened inside, or undefined for a top-level agent. */
69
+ export function currentParentAgentId() {
70
+ return contextStore.getStore()?.parentAgentId;
34
71
  }
35
72
  /**
36
73
  * COA-2636, under COA-2634. An agent that does not say which version it is, is an agent whose
@@ -85,10 +122,14 @@ export function resetVersionWarnings() {
85
122
  * Through `log.warn`, never a bare `console.warn`: COA-2192 made every diagnostic in this SDK
86
123
  * routable into the host's own logging and silenceable with `register({ logger: null })`, and a
87
124
  * library that writes unconditionally to a production service's stderr is a defect on its own.
125
+ * A context nested in the same agent inherits that agent's version, so it is not warned about.
88
126
  */
89
127
  function warnMissingVersion(options) {
90
128
  if (options.version !== undefined)
91
129
  return;
130
+ const outer = contextStore.getStore();
131
+ if (outer?.agentId === options.agentId && outer.version !== undefined)
132
+ return;
92
133
  if (warnedMissingVersion.has(options.agentId))
93
134
  return;
94
135
  if (warnedMissingVersion.size >= MISSING_VERSION_WARNING_CAP)
@@ -96,87 +137,149 @@ function warnMissingVersion(options) {
96
137
  warnedMissingVersion.add(options.agentId);
97
138
  log.warn(missingVersionGuidance(options.agentId));
98
139
  }
99
- function buildInvocationAttributes(options) {
100
- const attrs = { "coalex.agent_id": options.agentId };
101
- if (options.requestId !== undefined) {
102
- attrs["coalex.request_id"] = options.requestId;
103
- }
104
- if (options.version !== undefined) {
105
- attrs["coalex.agent_version"] = options.version;
140
+ /**
141
+ * The context an invocation opens, resolved against the one it opens inside.
142
+ *
143
+ * An inner context wins for every value it is given. Inside a *different* agent it names that
144
+ * agent as its parent, carries `requestId` and `runId`, and inherits neither the version nor the
145
+ * prompt: those belong to the outer agent. Inside the *same* agent it inherits everything and names
146
+ * no parent. A top-level context starts from the startup prompt, if getPrompt() fetched one.
147
+ */
148
+ function resolveContext(options) {
149
+ const outer = contextStore.getStore();
150
+ const sameAgent = outer !== undefined && outer.agentId === options.agentId;
151
+ let inherited;
152
+ if (outer === undefined) {
153
+ inherited = { promptVersion: _startupPrompt?.version, promptType: _startupPrompt?.type };
106
154
  }
107
- if (options.promptVersion !== undefined) {
108
- attrs["coalex.prompt_version"] = options.promptVersion;
155
+ else if (sameAgent) {
156
+ inherited = outer;
109
157
  }
110
- if (options.promptType !== undefined) {
111
- attrs["coalex.prompt_type"] = options.promptType;
158
+ else {
159
+ inherited = { parentAgentId: outer.agentId };
112
160
  }
161
+ const promptGiven = options.promptVersion !== undefined;
162
+ return {
163
+ agentId: options.agentId,
164
+ parentAgentId: inherited.parentAgentId,
165
+ requestId: options.requestId ?? outer?.requestId,
166
+ runId: options.runId ?? outer?.runId,
167
+ version: options.version ?? inherited.version,
168
+ promptVersion: promptGiven ? options.promptVersion : inherited.promptVersion,
169
+ promptType: options.promptType ?? inherited.promptType ?? (promptGiven ? "system" : undefined),
170
+ };
171
+ }
172
+ /** The `coalex.*` attributes a context puts on its spans, in the propagator's order. */
173
+ export function contextAttributes(ctx) {
174
+ const attrs = { "coalex.agent_id": ctx.agentId };
175
+ if (ctx.parentAgentId !== undefined)
176
+ attrs["coalex.parent_agent_id"] = ctx.parentAgentId;
177
+ if (ctx.requestId !== undefined)
178
+ attrs["coalex.request_id"] = ctx.requestId;
179
+ if (ctx.runId !== undefined)
180
+ attrs["coalex.run_id"] = ctx.runId;
181
+ if (ctx.version !== undefined)
182
+ attrs["coalex.agent_version"] = ctx.version;
183
+ if (ctx.promptVersion !== undefined)
184
+ attrs["coalex.prompt_version"] = ctx.promptVersion;
185
+ if (ctx.promptType !== undefined)
186
+ attrs["coalex.prompt_type"] = ctx.promptType;
113
187
  return attrs;
114
188
  }
115
189
  /**
116
- * When a prompt version is supplied, update the process-global fallback the propagator reads, so
117
- * spans that escape the invocation-span parent chain (e.g. auto-instrumentor root spans with their
118
- * own trace) are still attributed — the mirror of the Python contextvar. Returns a restore fn so a
119
- * request's version doesn't leak into a later invocation that passes none. Process-global: under
120
- * concurrent invocations with *different* versions the last write wins (same caveat as getPrompt()).
190
+ * The LangGraph errors that carry a pause or a hand-off up through a node, not a failure.
191
+ * Recognised by name on the error and on every class of its prototype chain, so this SDK never
192
+ * imports LangGraph, a subclass (`NodeInterrupt`) is recognised, and so is a bundled copy whose
193
+ * class names were minified (LangGraph sets `name` on each).
121
194
  */
122
- function applyPromptFallback(options) {
123
- if (options.promptVersion === undefined) {
124
- return () => { };
195
+ export const PAUSE_ERROR_NAMES = new Set([
196
+ "GraphBubbleUp",
197
+ "GraphInterrupt",
198
+ "ParentCommand",
199
+ ]);
200
+ export function isPause(e) {
201
+ if (typeof e !== "object" || e === null)
202
+ return false;
203
+ if (PAUSE_ERROR_NAMES.has(String(e.name)))
204
+ return true;
205
+ for (let proto = Object.getPrototypeOf(e); proto !== null; proto = Object.getPrototypeOf(proto)) {
206
+ const ctor = proto.constructor;
207
+ if (ctor && PAUSE_ERROR_NAMES.has(String(ctor.name)))
208
+ return true;
209
+ }
210
+ return false;
211
+ }
212
+ /** A pause ends the span OK with no exception event; anything else ends it ERROR. */
213
+ function endOnError(span, e) {
214
+ if (isPause(e)) {
215
+ span.setStatus({ code: SpanStatusCode.OK });
216
+ return;
125
217
  }
126
- const prev = getLastPrompt();
127
- setLastPrompt(options.promptVersion, options.promptType ?? prev?.type ?? "system");
128
- return () => (prev ? setLastPrompt(prev.version, prev.type) : clearLastPrompt());
218
+ span.setStatus({ code: SpanStatusCode.ERROR, message: String(e) });
219
+ span.recordException(e instanceof Error ? e : new Error(String(e)));
129
220
  }
221
+ /**
222
+ * Run `fn` inside a `coalex.invocation` span for `options.agentId`; every span started inside it
223
+ * carries the context's `coalex.*` attributes.
224
+ *
225
+ * Nested inside another agent's context it sets `coalex.parent_agent_id` to that agent, carries
226
+ * `requestId` and `runId`, and inherits neither version nor prompt; inside the same agent it
227
+ * inherits everything. A LangGraph pause (`GraphBubbleUp`, `GraphInterrupt`, `ParentCommand`)
228
+ * ends the span OK and is re-thrown; any other error ends it ERROR.
229
+ */
130
230
  export async function coalexContext(options, fn) {
131
231
  const tracer = trace.getTracer("coalex");
132
232
  warnMissingVersion(options);
133
- const attrs = buildInvocationAttributes(options);
134
- const restorePrompt = applyPromptFallback(options);
135
- try {
136
- return await agentIdStore.run(options.agentId, () => tracer.startActiveSpan("coalex.invocation", { attributes: attrs }, async (span) => {
137
- try {
138
- const result = await fn();
139
- span.setStatus({ code: SpanStatusCode.OK });
140
- return result;
141
- }
142
- catch (e) {
143
- span.setStatus({ code: SpanStatusCode.ERROR, message: String(e) });
144
- span.recordException(e instanceof Error ? e : new Error(String(e)));
145
- throw e;
146
- }
147
- finally {
148
- span.end();
149
- }
150
- }));
151
- }
152
- finally {
153
- restorePrompt();
154
- }
233
+ const ctx = resolveContext(options);
234
+ return contextStore.run(ctx, () => tracer.startActiveSpan("coalex.invocation", { attributes: contextAttributes(ctx) }, async (span) => {
235
+ try {
236
+ const result = await fn();
237
+ span.setStatus({ code: SpanStatusCode.OK });
238
+ return result;
239
+ }
240
+ catch (e) {
241
+ endOnError(span, e);
242
+ throw e;
243
+ }
244
+ finally {
245
+ span.end();
246
+ }
247
+ }));
155
248
  }
156
249
  export function coalexContextSync(options, fn) {
157
250
  const tracer = trace.getTracer("coalex");
158
251
  warnMissingVersion(options);
159
- const attrs = buildInvocationAttributes(options);
160
- const restorePrompt = applyPromptFallback(options);
161
- try {
162
- return agentIdStore.run(options.agentId, () => tracer.startActiveSpan("coalex.invocation", { attributes: attrs }, (span) => {
163
- try {
164
- const result = fn();
165
- span.setStatus({ code: SpanStatusCode.OK });
166
- return result;
167
- }
168
- catch (e) {
169
- span.setStatus({ code: SpanStatusCode.ERROR, message: String(e) });
170
- span.recordException(e instanceof Error ? e : new Error(String(e)));
171
- throw e;
172
- }
173
- finally {
174
- span.end();
175
- }
176
- }));
177
- }
178
- finally {
179
- restorePrompt();
180
- }
252
+ const ctx = resolveContext(options);
253
+ return contextStore.run(ctx, () => tracer.startActiveSpan("coalex.invocation", { attributes: contextAttributes(ctx) }, (span) => {
254
+ try {
255
+ const result = fn();
256
+ span.setStatus({ code: SpanStatusCode.OK });
257
+ return result;
258
+ }
259
+ catch (e) {
260
+ endOnError(span, e);
261
+ throw e;
262
+ }
263
+ finally {
264
+ span.end();
265
+ }
266
+ }));
267
+ }
268
+ /**
269
+ * Wrap a LangGraph node function so everything it does belongs to `agentId`.
270
+ *
271
+ * Wrap the **node function**, not the graph's `invoke`: LangGraph re-executes the node from the
272
+ * top on every resume (`new Command({ resume })`), so the context opens again for the resumed work
273
+ * and the node's checkpoint namespace is unchanged. The context carries the enclosing `requestId`
274
+ * and `runId`, names the enclosing agent as `coalex.parent_agent_id`, and a pause (`interrupt()`)
275
+ * leaves its span OK. Every argument (`state`, `config`) is passed through.
276
+ *
277
+ * graph.addNode("w1_rfq", agentNode("rfq-worker", rfqWorker, { version: "1.4.0" }));
278
+ */
279
+ export function agentNode(agentId, fn, options = {}) {
280
+ const { version } = options;
281
+ // Warned when the node is built, where the caller can act on it, not on every execution.
282
+ warnMissingVersion({ agentId, version });
283
+ return (...args) => coalexContext({ agentId, version }, () => fn(...args));
181
284
  }
182
285
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,MAAM,YAAY,GAAG,IAAI,iBAAiB,EAAU,CAAC;AAErD;;;;;;;GAOG;AACH,IAAI,WAAW,GAA6C,IAAI,CAAC;AAEjE,sFAAsF;AACtF,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,IAAY;IACzD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;;GAUG;AACH,MAAM,UAAU,SAAS,CACvB,OAAe,EACf,EAAkC,EAClC,UAAgC,EAAE;IAElC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,yFAAyF;IACzF,kBAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,IAAO,EAAE,EAAE,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAChF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { CoalexConfig } from "./config.js";
2
2
  import type { AgentInventory } from "./inventory.js";
3
3
  import { type CoalexLogger } from "./logger.js";
4
4
  export type { CoalexConfig } from "./config.js";
5
- export { coalexContext, coalexContextSync, currentAgentId } from "./context.js";
5
+ export { agentNode, coalexContext, coalexContextSync, currentAgentId, currentAgentVersion, currentParentAgentId, currentRequestId, currentRunId, } from "./context.js";
6
6
  export type { CoalexContextOptions } from "./context.js";
7
7
  export { evaluate, KNOWN_METRICS } from "./evaluate.js";
8
8
  export type { EvaluateOptions, EvaluationDecision } from "./evaluate.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAKhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3D,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAChF,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MA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AClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAuCxD;AAED,0CAA0C;AAC1C,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC"}
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { FilteringSpanExporter } from "./filtering-exporter.js";
9
9
  import { CoalexAttributePropagator } from "./span-processor.js";
10
10
  import { declareInventory } from "./inventory.js";
11
11
  import { setLogger } from "./logger.js";
12
- export { coalexContext, coalexContextSync, currentAgentId } from "./context.js";
12
+ export { agentNode, coalexContext, coalexContextSync, currentAgentId, currentAgentVersion, currentParentAgentId, currentRequestId, currentRunId, } from "./context.js";
13
13
  export { evaluate, KNOWN_METRICS } from "./evaluate.js";
14
14
  export { resolve, VALID_DECISIONS } from "./resolve.js";
15
15
  // What ran while the platform was unreachable (COA-2394). Python has had this since COA-2197 and
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAGxE,O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AAgB,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;IAChG,CAAC;AACH,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,gBAAgB;IAC9B,OAAO,GAAG,IAAI,CAAC;IACf,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC"}
@@ -1,5 +1,17 @@
1
1
  import type { Context } from "@opentelemetry/api";
2
2
  import type { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
3
+ export declare const ATTRIBUTES_TO_PROPAGATE: readonly ["coalex.agent_id", "coalex.parent_agent_id", "coalex.request_id", "coalex.run_id", "coalex.agent_version", "coalex.prompt_version", "coalex.prompt_type"];
4
+ /**
5
+ * Puts the `coalex.*` attributes of the active coalexContext() on every span it starts.
6
+ *
7
+ * Each attribute comes from the **active Coalex context first**, and from the parent span only when
8
+ * no Coalex context is active. The parent span is not trusted over the context: a framework
9
+ * instrumentor (OpenInference LangChain) parents its spans on its own run tree, so a worker's LLM
10
+ * span can have the orchestrator's span as its parent. Inside a context, an attribute the context
11
+ * does not hold is left unset, so a worker never carries its orchestrator's version or prompt.
12
+ * Outside any context, a startup getPrompt() still attributes spans no parent attributes. A value
13
+ * the span already carries is never overwritten.
14
+ */
3
15
  export declare class CoalexAttributePropagator implements SpanProcessor {
4
16
  onStart(span: Span, parentContext: Context): void;
5
17
  onEnd(span: ReadableSpan): void;
@@ -1 +1 @@
1
- {"version":3,"file":"span-processor.d.ts","sourceRoot":"","sources":["../src/span-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAYvF,qBAAa,yBAA0B,YAAW,aAAa;IAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI;IAgCjD,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAG/B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAGzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
1
+ {"version":3,"file":"span-processor.d.ts","sourceRoot":"","sources":["../src/span-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAIvF,eAAO,MAAM,uBAAuB,qKAQ1B,CAAC;AAEX;;;;;;;;;;GAUG;AACH,qBAAa,yBAA0B,YAAW,aAAa;IAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,GAAG,IAAI;IA+BjD,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAG/B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAGzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
@@ -1,13 +1,26 @@
1
1
  import { trace } from "@opentelemetry/api";
2
2
  import { spanContextBridge } from "./ext/context-bridge.js";
3
- import { getLastPrompt } from "./context.js";
4
- const ATTRIBUTES_TO_PROPAGATE = [
3
+ import { activeContext, contextAttributes, getLastPrompt } from "./context.js";
4
+ export const ATTRIBUTES_TO_PROPAGATE = [
5
5
  "coalex.agent_id",
6
+ "coalex.parent_agent_id",
6
7
  "coalex.request_id",
8
+ "coalex.run_id",
7
9
  "coalex.agent_version",
8
10
  "coalex.prompt_version",
9
11
  "coalex.prompt_type",
10
12
  ];
13
+ /**
14
+ * Puts the `coalex.*` attributes of the active coalexContext() on every span it starts.
15
+ *
16
+ * Each attribute comes from the **active Coalex context first**, and from the parent span only when
17
+ * no Coalex context is active. The parent span is not trusted over the context: a framework
18
+ * instrumentor (OpenInference LangChain) parents its spans on its own run tree, so a worker's LLM
19
+ * span can have the orchestrator's span as its parent. Inside a context, an attribute the context
20
+ * does not hold is left unset, so a worker never carries its orchestrator's version or prompt.
21
+ * Outside any context, a startup getPrompt() still attributes spans no parent attributes. A value
22
+ * the span already carries is never overwritten.
23
+ */
11
24
  export class CoalexAttributePropagator {
12
25
  onStart(span, parentContext) {
13
26
  // Track ALL spans in the context bridge for ext wrapper parenting.
@@ -15,25 +28,26 @@ export class CoalexAttributePropagator {
15
28
  // and sets openinference.span.kind only at onEnd time. So we track all
16
29
  // spans — the bridge returns the most recently active span in the trace.
17
30
  spanContextBridge.push(span, parentContext);
18
- // Propagate coalex attributes from parent to child.
19
- const parentSpan = trace.getSpan(parentContext);
20
- const parentAttrs = parentSpan ? parentSpan.attributes : undefined;
21
- for (const attrName of ATTRIBUTES_TO_PROPAGATE) {
22
- const parentValue = parentAttrs?.[attrName];
23
- if (parentValue !== undefined) {
24
- span.setAttribute(attrName, parentValue);
25
- }
31
+ const own = span.attributes ?? {};
32
+ const active = activeContext();
33
+ let values;
34
+ if (active) {
35
+ values = contextAttributes(active);
26
36
  }
27
- // Fallback: attribute spans to the last prompt fetched via getPrompt() when no parent
28
- // carries it (e.g. a root span after a startup getPrompt()) — mirrors the Python contextvar
29
- // fallback (COA-368).
30
- const prompt = getLastPrompt();
31
- if (prompt) {
32
- if (parentAttrs?.["coalex.prompt_version"] === undefined) {
33
- span.setAttribute("coalex.prompt_version", prompt.version);
37
+ else {
38
+ const parentSpan = trace.getSpan(parentContext);
39
+ const parentAttrs = parentSpan ? parentSpan.attributes : undefined;
40
+ values = { ...parentAttrs };
41
+ const prompt = getLastPrompt();
42
+ if (prompt) {
43
+ values["coalex.prompt_version"] ??= prompt.version;
44
+ values["coalex.prompt_type"] ??= prompt.type;
34
45
  }
35
- if (parentAttrs?.["coalex.prompt_type"] === undefined) {
36
- span.setAttribute("coalex.prompt_type", prompt.type);
46
+ }
47
+ for (const attrName of ATTRIBUTES_TO_PROPAGATE) {
48
+ const value = values[attrName];
49
+ if (value !== undefined && own[attrName] === undefined) {
50
+ span.setAttribute(attrName, value);
37
51
  }
38
52
  }
39
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"span-processor.js","sourceRoot":"","sources":["../src/span-processor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,uBAAuB,GAAG;IAC9B,iBAAiB;IACjB,mBAAmB;IACnB,sBAAsB;IACtB,uBAAuB;IACvB,oBAAoB;CACZ,CAAC;AAEX,MAAM,OAAO,yBAAyB;IACpC,OAAO,CAAC,IAAU,EAAE,aAAsB;QACxC,mEAAmE;QACnE,0EAA0E;QAC1E,uEAAuE;QACvE,yEAAyE;QACzE,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAE5C,oDAAoD;QACpD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAChD,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAE,UAAsC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;QAEhG,KAAK,MAAM,QAAQ,IAAI,uBAAuB,EAAE,CAAC;YAC/C,MAAM,WAAW,GAAG,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC;YAC5C,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;gBAC9B,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;QAED,sFAAsF;QACtF,4FAA4F;QAC5F,sBAAsB;QACtB,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;QAC/B,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,WAAW,EAAE,CAAC,uBAAuB,CAAC,KAAK,SAAS,EAAE,C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IAAI,MAA+B,CAAC;QACpC,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YAChD,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAE,UAAsC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;YAChG,MAAM,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;YAC/B,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,uBAAuB,CAAC,KAAK,MAAM,CAAC,OAAO,CAAC;gBACnD,MAAM,CAAC,oBAAoB,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,KAAK,MAAM,QAAQ,IAAI,uBAAuB,EAAE,CAAC;YAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC/B,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;gBACvD,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAwB,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAkB;QACtB,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,QAAQ;QACN,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,UAAU;QACR,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.2.1";
1
+ export declare const VERSION = "2.3.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // SDK version, sent in the X-SDK-Version header so the platform can see which
2
2
  // SDK releases customers run before removing a deprecated field (COA-261).
3
3
  // Keep in sync with package.json "version".
4
- export const VERSION = "2.2.1";
4
+ export const VERSION = "2.3.0";
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coalex-ai/sdk",
3
- "version": "2.2.1",
3
+ "version": "2.3.0-beta.686",
4
4
  "description": "Coalex TypeScript SDK for AI governance observability",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {