@xandreed/sdk 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
package/dist/agent.adapter.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface AgentConfig {
|
|
|
42
42
|
readonly workspace?: string;
|
|
43
43
|
/**
|
|
44
44
|
* Defaults for every run; a turn's policy overrides them. Its loop
|
|
45
|
-
* protection (`degenerate`, `malformedLimit`) is decoded here
|
|
45
|
+
* protection (`degenerate`, `malformedLimit`, `invalidCalls`) is decoded here
|
|
46
46
|
* (`config.limits`), and a run's merged limits again (`turn.limits`).
|
|
47
47
|
*/
|
|
48
48
|
readonly limits?: Partial<LoopLimits>;
|
package/dist/agent.adapter.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
CurrentTraceContent,
|
|
4
4
|
DrainActivity,
|
|
5
5
|
WaitingInput,
|
|
6
|
+
BackgroundWorkers,
|
|
6
7
|
CapabilitiesLive,
|
|
7
8
|
DEFAULT_SHUTDOWN_DEADLINE,
|
|
8
9
|
Capabilities,
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
harnessDefectsAsFailures,
|
|
12
13
|
HarnessError,
|
|
13
14
|
LoopProtection,
|
|
15
|
+
notifyCommittedTurn,
|
|
14
16
|
isBudgetTokens,
|
|
15
17
|
normalizeUserMessage,
|
|
16
18
|
PluginInstanceId,
|
|
@@ -74,7 +76,7 @@ const failure = (code, message) => new HarnessError({ code, message }), missing
|
|
|
74
76
|
}, []), makeAgent = (config) => Effect.gen(function* () {
|
|
75
77
|
if (config.budgetTokens !== void 0 && !isBudgetTokens(config.budgetTokens))
|
|
76
78
|
return yield* Effect.fail(failure("config.budget", `budgetTokens must be an integer of at least 1, not ${config.budgetTokens}`));
|
|
77
|
-
yield* Schema.decodeUnknownEffect(LoopProtection)(config.limits ?? {}).pipe(Effect.mapError((cause) => new HarnessError({ code: "config.limits", message: "the agent's limits carry a degenerate policy or
|
|
79
|
+
yield* Schema.decodeUnknownEffect(LoopProtection)(config.limits ?? {}).pipe(Effect.mapError((cause) => new HarnessError({ code: "config.limits", message: "the agent's limits carry a degenerate policy, malformedLimit or invalidCalls that does not decode", cause })));
|
|
78
80
|
const parent = yield* Effect.scope, entries = config.plugins.map(entryOf), hosted = config.capabilities ?? [], host = hostCapabilities(hosted), withHost = hosted.length > 0, plugins = [...withHost ? [host] : [], ...entries.map((entry) => entry.plugin)], harness = {
|
|
79
81
|
version: 1,
|
|
80
82
|
plugins: [
|
|
@@ -123,16 +125,17 @@ const failure = (code, message) => new HarnessError({ code, message }), missing
|
|
|
123
125
|
if (!own)
|
|
124
126
|
return yield* exit;
|
|
125
127
|
if (Exit.isFailure(exit)) {
|
|
126
|
-
yield* writer.end(turnEndingOf(exit)).pipe(Effect.catchTag("TurnClosed", (closed) => Effect.logDebug(`the failed turn's end was not stored: the turn was ${closed.reason}`)), Effect.catch((error) => Effect.logWarning(`the failed turn's end was not stored: ${reasonOf(Cause.fail(error))}`)));
|
|
128
|
+
yield* writer.end(turnEndingOf(exit)).pipe(Effect.tap(() => notifyCommittedTurn({ session: writer.admitted.session, runId: writer.admitted.runId, turn: writer.admitted.turn }).pipe(Effect.provide(context))), Effect.catchTag("TurnClosed", (closed) => Effect.logDebug(`the failed turn's end was not stored: the turn was ${closed.reason}`)), Effect.catch((error) => Effect.logWarning(`the failed turn's end was not stored: ${reasonOf(Cause.fail(error))}`)));
|
|
127
129
|
return yield* Effect.failCause(exit.cause);
|
|
128
130
|
}
|
|
129
131
|
const { pending } = yield* writer.end(turnEndingOf(exit));
|
|
132
|
+
yield* notifyCommittedTurn({ session: writer.admitted.session, runId: writer.admitted.runId, turn: writer.admitted.turn }).pipe(Effect.provide(context));
|
|
130
133
|
return { ...exit.value, pending };
|
|
131
134
|
}).pipe(Effect.annotateLogs(turnAttributes(writer.admitted)), measureTurn, traceTurn(writer, { spanMeta: config.spanMeta ?? [] }));
|
|
132
135
|
}))), runtimeProbes = (effect) => effect.pipe(Effect.updateContext((current) => {
|
|
133
|
-
const probes = Context.merge(Context.omit(TurnActivity, TaskActivity, TurnShutdown, WaitingInput, DrainActivity)(current), Context.pick(TurnActivity, TaskActivity, TurnShutdown, WaitingInput, DrainActivity)(runtime)), drains = Option.orElse(Context.getOption(runtime, DrainActivity), () => Context.getOption(current, DrainActivity));
|
|
136
|
+
const probes = Context.merge(Context.omit(TurnActivity, TaskActivity, TurnShutdown, WaitingInput, DrainActivity, BackgroundWorkers)(current), Context.pick(TurnActivity, TaskActivity, TurnShutdown, WaitingInput, DrainActivity, BackgroundWorkers)(runtime)), drains = Option.orElse(Context.getOption(runtime, DrainActivity), () => Context.getOption(current, DrainActivity));
|
|
134
137
|
return Option.match(drains, { onNone: () => probes, onSome: (probe) => Context.add(probes, DrainActivity, probe) });
|
|
135
|
-
})), activity = runtimeProbes(processActivity), shutdown = (options) => runtimeProbes(shutdownGracefully(options ?? config.shutdown ?? { deadline: DEFAULT_SHUTDOWN_DEADLINE })).pipe(Effect.tap((report) => report.left.inFlight ? Effect.logWarning(`the agent stopped with ${report.left.openTurns.length + report.left.beginningTurns} turns and ${report.left.runningTasks} tasks still in flight`) : Effect.void)), configured = config.shutdown;
|
|
138
|
+
})), activity = runtimeProbes(processActivity), shutdown = (options) => runtimeProbes(shutdownGracefully(options ?? config.shutdown ?? { deadline: DEFAULT_SHUTDOWN_DEADLINE })).pipe(Effect.tap((report) => report.left.inFlight ? Effect.logWarning(`the agent stopped with ${report.left.openTurns.length + report.left.beginningTurns} turns and ${report.left.runningTasks} tasks${report.left.runningWorkers === void 0 ? "" : ` and ${report.left.runningWorkers} worker jobs`} still in flight`) : Effect.void)), configured = config.shutdown;
|
|
136
139
|
if (configured !== void 0)
|
|
137
140
|
yield* Effect.addFinalizer(() => shutdown(configured).pipe(Effect.asVoid));
|
|
138
141
|
return { fingerprint: graphFingerprint(graph), activity, shutdown, turn };
|
|
@@ -55,7 +55,7 @@ export const schemaTokens = (tools, active) => active.reduce((sum, name) => {
|
|
|
55
55
|
return tool === void 0 ? sum : sum + estimateTokens(`${tool.description ?? ""}${canonicalJson(toolParametersSchema(tool))}`);
|
|
56
56
|
}, 0), cacheKeyOf = (prefix, conversation) => Option.map(Option.filter(Option.some(prefix), (value) => value.length > 0), (value) => `${value}:${conversation}`), stepRequestOf = Effect.fnUntraced(function* (policy, options = {}) {
|
|
57
57
|
const runServices = Context.omit(CurrentToolResultReceipt)(replayableContext(yield* Effect.context())), memory = yield* TurnMemory, prompt = yield* TurnPrompt, events = yield* TurnEvents, tasks = yield* TurnTasks, tools = yield* (yield* TurnToolbox).tools, session = memory.session, run = yield* memory.startRun, inRun = (effect, step = Option.none()) => effect.pipe(Effect.provideService(CurrentAgentRun, Option.some(run)), Effect.provideService(CurrentAgentStep, step), Effect.provide(runServices)), defaultModel = Context.getOption(runServices, LanguageModel.LanguageModel), limits = { ...defaultLimits, ...options.limits, ...policy.limits };
|
|
58
|
-
yield* Schema.decodeUnknownEffect(LoopProtection)(limits).pipe(Effect.mapError((cause) => new HarnessError({ code: "turn.limits", message: "the run's limits carry a degenerate policy or
|
|
58
|
+
yield* Schema.decodeUnknownEffect(LoopProtection)(limits).pipe(Effect.mapError((cause) => new HarnessError({ code: "turn.limits", message: "the run's limits carry a degenerate policy, malformedLimit or invalidCalls that does not decode", cause })));
|
|
59
59
|
const budget = policy.budgetTokens ?? options.budgetTokens ?? defaultBudgetTokens;
|
|
60
60
|
if (!isBudgetTokens(budget))
|
|
61
61
|
return yield* Effect.fail(failure("turn.budget", `budgetTokens must be an integer of at least 1, not ${budget}`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xandreed/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=24",
|
|
6
6
|
"bun": ">=1.3.0"
|
|
@@ -18,12 +18,13 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@xandreed/runtime": "^0.
|
|
21
|
+
"@xandreed/runtime": "^0.16.0"
|
|
22
22
|
},
|
|
23
|
+
"gitHead": "7eb972d259e80a0c88a99d81e84e9440aed884f0",
|
|
23
24
|
"private": false,
|
|
24
25
|
"types": "./dist/index.d.ts",
|
|
25
26
|
"peerDependencies": {
|
|
26
|
-
"@xandreed/core": "^0.
|
|
27
|
+
"@xandreed/core": "^0.16.0",
|
|
27
28
|
"effect": "^4.0.7"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|