@cubicecho/agent-core 2.11.0 → 2.13.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 +169 -5
- package/dist/agent-loop.d.ts +30 -6
- package/dist/agent-loop.js +150 -31
- package/dist/calibration.d.ts +33 -0
- package/dist/calibration.js +87 -0
- package/dist/capabilities.d.ts +8 -0
- package/dist/capabilities.js +1 -0
- package/dist/compaction.d.ts +130 -16
- package/dist/compaction.js +137 -32
- package/dist/continuation.d.ts +59 -0
- package/dist/continuation.js +159 -0
- package/dist/events.d.ts +112 -1
- package/dist/events.js +111 -11
- package/dist/hooks.d.ts +49 -3
- package/dist/hooks.js +59 -4
- package/dist/index.d.ts +7 -5
- package/dist/index.js +7 -5
- package/dist/reset.d.ts +7 -6
- package/dist/reset.js +9 -6
- package/dist/retry.d.ts +36 -3
- package/dist/retry.js +49 -16
- package/dist/run-turn.d.ts +4 -0
- package/dist/run-turn.js +19 -3
- package/dist/snapshot.d.ts +5 -0
- package/dist/snapshot.js +5 -0
- package/dist/stream.d.ts +74 -2
- package/dist/stream.js +45 -5
- package/dist/tool-loading.d.ts +29 -4
- package/dist/tool-loading.js +33 -4
- package/llms.txt +33 -1
- package/package.json +1 -1
package/dist/tool-loading.js
CHANGED
|
@@ -107,10 +107,9 @@ const flatten = (catalog) => catalog.flatMap((server) => server.tools);
|
|
|
107
107
|
/**
|
|
108
108
|
* A tool array with newly loaded definitions appended, in the order they were loaded.
|
|
109
109
|
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* a prefix of the new array.
|
|
110
|
+
* Appended and never rebuilt from a set, so what a load adds is decided by the load and not by
|
|
111
|
+
* the shape of whatever collection the definitions came out of. Where the appended array ends up
|
|
112
|
+
* in the request is `orderTools`' business, which the loop applies after this.
|
|
114
113
|
*
|
|
115
114
|
* @param previous What the last request declared, `load_tools` included. Not written to.
|
|
116
115
|
* @param matched The definitions to add. Ones whose name is already declared, here or earlier in
|
|
@@ -129,6 +128,36 @@ export function loadedTools(previous, matched) {
|
|
|
129
128
|
}
|
|
130
129
|
return tools;
|
|
131
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* The tool array in a stable order, so the same set of tools renders the same way twice.
|
|
133
|
+
*
|
|
134
|
+
* A chat template renders the declared tools ahead of the system prompt, which makes the tool
|
|
135
|
+
* array the first thing a prompt cache has to match — and an array assembled from a map, from
|
|
136
|
+
* database rows, or from the order servers happened to connect in changes between processes and
|
|
137
|
+
* between reconnects. Every such change costs the cache for the whole transcript rather than for
|
|
138
|
+
* the tools alone, and nothing about the request the model sees is different. Ordering by name
|
|
139
|
+
* makes the array a property of the set instead of of how it was built, at the price of a load
|
|
140
|
+
* inserting rather than appending. Definitions come back by identity, so `sanitizeTools` still
|
|
141
|
+
* finds each one in its cache.
|
|
142
|
+
*
|
|
143
|
+
* `false` is for a caller that means its order: the model reads the array top to bottom, and a
|
|
144
|
+
* host may be putting what it wants reached for first at the front.
|
|
145
|
+
*
|
|
146
|
+
* @param tools The definitions to order. Not written to.
|
|
147
|
+
* @param order `true` for name order, `false` to leave it alone, or a comparator over the names.
|
|
148
|
+
* A tool that is not a function orders as the empty name.
|
|
149
|
+
* @returns `tools` itself when it is already in that order, so the common case copies nothing.
|
|
150
|
+
*/
|
|
151
|
+
export function orderTools(tools, order = true) {
|
|
152
|
+
if (order === false)
|
|
153
|
+
return tools;
|
|
154
|
+
const nameOf = (tool) => tool.type === "function" ? tool.function.name : "";
|
|
155
|
+
// Code-unit order rather than `localeCompare`, whose answer depends on the host's locale —
|
|
156
|
+
// which is the kind of instability this exists to remove.
|
|
157
|
+
const compare = typeof order === "function" ? order : (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
158
|
+
const sorted = [...tools].sort((a, b) => compare(nameOf(a), nameOf(b)));
|
|
159
|
+
return sorted.some((tool, at) => tool !== tools[at]) ? sorted : tools;
|
|
160
|
+
}
|
|
132
161
|
/**
|
|
133
162
|
* The most a single `load_tools` call may pull in.
|
|
134
163
|
*
|
package/llms.txt
CHANGED
|
@@ -24,6 +24,14 @@ The loop above a turn: send, run the tools the model asked for, send again, unti
|
|
|
24
24
|
- `ToolCallOutcome` (type) — What one tool call did, in the order the model asked.
|
|
25
25
|
- `ToolCallRequest` (type) — One call the model made, as `dispatch` is handed it.
|
|
26
26
|
|
|
27
|
+
### calibration
|
|
28
|
+
|
|
29
|
+
How many characters a token is worth on one model, learned from what its endpoint reports.
|
|
30
|
+
|
|
31
|
+
- `calibrate` — Takes one reading from a request that was answered, so the next one to this model is sized by it.
|
|
32
|
+
- `charsPerTokenFor` — The characters per token to size a request to this model with, `CHARS_PER_TOKEN` until a turn has reported one.
|
|
33
|
+
- `resetCalibration` — Forgets every reading, so the next request is sized at `CHARS_PER_TOKEN` again.
|
|
34
|
+
|
|
27
35
|
### capabilities
|
|
28
36
|
|
|
29
37
|
What an endpoint turned out not to support, and answering it when it says so.
|
|
@@ -63,14 +71,19 @@ The contract between whatever holds the tools and the loop that offers them to a
|
|
|
63
71
|
|
|
64
72
|
Keeping a long run inside its window: stale tool results cleared, and the oldest stretch folded into a summary the model writes itself.
|
|
65
73
|
|
|
74
|
+
- `applyCompaction` — The transcript as the server should see it: the folded head replaced by its summary.
|
|
66
75
|
- `COMPACT_AT` — The fraction of the window in use before a summary is worth its own round trip.
|
|
67
76
|
- `CompactionOptions` (type) — What `planCompaction` takes.
|
|
68
77
|
- `CompactionPlan` (type) — Where to cut, as `compactTranscript` takes it.
|
|
78
|
+
- `CompactionRecord` (type) — One fold, as a host that keeps its transcript append-only stores it.
|
|
79
|
+
- `CompactionRunOptions` (type) — What `runCompaction` and `compactTranscript` take beside the plan.
|
|
69
80
|
- `compactTranscript` — The transcript with the plan's stretch replaced by one system message holding its summary.
|
|
70
81
|
- `KEEP_RATIO` — The fraction of the window the kept tail may fill, leaving room for the run to grow again.
|
|
71
82
|
- `PruneOptions` (type) — What `pruneToolResults` takes.
|
|
72
83
|
- `planCompaction` — Where to fold a transcript that has grown into its window, or `undefined` when it should not be.
|
|
73
84
|
- `pruneToolResults` — The transcript with every tool result but the latest few replaced by a one-line stub.
|
|
85
|
+
- `requestIndex` — Where a stored index sits in the request `applyCompaction` builds, once a fold has shifted everything after it.
|
|
86
|
+
- `runCompaction` — The hooks and the summariser for a plan, as a record to store rather than a transcript to send.
|
|
74
87
|
- `SUMMARY_LEAD` — How a summary message opens, which is also how `planCompaction` knows one from a system prompt.
|
|
75
88
|
- `SUMMARY_PROMPT` — The summariser's instruction when the caller gives none.
|
|
76
89
|
- `summariser` — A summariser that asks `model` with `SUMMARY_PROMPT`, for `compactTranscript`.
|
|
@@ -86,6 +99,14 @@ What this package needs to know about a caller's configuration.
|
|
|
86
99
|
- `RetryPolicy` (type) — How many times a lost or refused request is worth sending again.
|
|
87
100
|
- `ToolPolicy` (type) — How tools reach the model, and how long it may keep calling them.
|
|
88
101
|
|
|
102
|
+
### continuation
|
|
103
|
+
|
|
104
|
+
Picking up an answer the token ceiling cut off, instead of keeping half of it.
|
|
105
|
+
|
|
106
|
+
- `ContinueTurnOptions` (type) — What `continueTurn` takes besides what `runTurn` does.
|
|
107
|
+
- `continueTurn` — Carries on an answer the token ceiling cut off, by sending the transcript again with the answer so far as a trailing assistant message, and joins the pieces into one turn.
|
|
108
|
+
- `isContinuable` — Whether a turn is one a continuation can finish: cut off at the ceiling, with an answer begun and no tool call in it.
|
|
109
|
+
|
|
89
110
|
### errors
|
|
90
111
|
|
|
91
112
|
- `errorMessage` — What went wrong, as a string.
|
|
@@ -103,8 +124,12 @@ What a run is doing, while it is doing it.
|
|
|
103
124
|
- `RunEvent` (type) — One thing that happened in a run, as a watcher receives it.
|
|
104
125
|
- `RunEventInput` (type) — What `emit` is given: the run and the sequence are the bus's to assign.
|
|
105
126
|
- `RunEventKind` (type) — Which kind of thing happened, and what `text`, `name`, `ok` and `usage` carry for it.
|
|
127
|
+
- `RunMetrics` (type) — A run summed and derived from its events: what it cost, where the time went, and why.
|
|
128
|
+
- `RunMetricsOptions` (type) — What `runMetrics` takes besides the events.
|
|
106
129
|
- `RunUsage` (type) — What a run has spent, counted from the start of the run rather than for the turn that carried it: a client draws the latest one it has seen and needs no arithmetic of its own, and one lost to the backlog cap costs nothing because the next supersedes it.
|
|
107
130
|
- `resetEvents` — Test seam: forget every run, so one test's events cannot be read by the next.
|
|
131
|
+
- `runMetrics` — A run's totals, timings and cache findings, derived from the events it emitted.
|
|
132
|
+
- `TurnReport` (type) — One turn's usage and measurements as a `usage` event carries them.
|
|
108
133
|
- `watch` — Everything that has happened on a run, then everything that happens next, until it ends.
|
|
109
134
|
|
|
110
135
|
### hooks
|
|
@@ -113,6 +138,7 @@ Lifecycle hooks, from the host's side: what a session looks like to them, where
|
|
|
113
138
|
|
|
114
139
|
- `assembleContext` — Builds the context a set of outcomes adds and the notes that go with it.
|
|
115
140
|
- `configureHooks` — Changes what hooks are held to, for a process whose windows are not the size these defaults were chosen for, or whose host wants its own name above the context.
|
|
141
|
+
- `consult` — Runs an event's hooks and waits for their say, for a host that will hold off when one of them vetoes.
|
|
116
142
|
- `Gathered` (type) — The context a set of outcomes adds to a request, and a note for each hook worth mentioning.
|
|
117
143
|
- `gather` — Runs the hooks ahead of a request and builds what they add to it.
|
|
118
144
|
- `HOOK_CONTEXT_TOKENS` — The most context all of a request's hooks add between them by default, in estimated tokens.
|
|
@@ -143,6 +169,7 @@ Lifecycle hooks, from the host's side: what a session looks like to them, where
|
|
|
143
169
|
Everything about a request failing that is not about what the request said.
|
|
144
170
|
|
|
145
171
|
- `backoffMs` — Exponential, with jitter so several tasks failing at once do not return in lockstep.
|
|
172
|
+
- `CHARS_PER_TOKEN` — The divisor behind `estimateTokens`, applied here to a character count rather than a string.
|
|
146
173
|
- `ContextOverflow` — The request was bigger than the model will read.
|
|
147
174
|
- `compact` — 1234 → "1.2k".
|
|
148
175
|
- `EndpointSilent` — The endpoint stopped answering mid-request.
|
|
@@ -152,9 +179,12 @@ Everything about a request failing that is not about what the request said.
|
|
|
152
179
|
- `LOADING_POLL_MS` — How long to wait between asking a loading server again.
|
|
153
180
|
- `LOADING_TIMEOUT_MS` — How long `runTurn` waits for a model to load unless told otherwise.
|
|
154
181
|
- `messageTokens` — One message's estimated tokens, by the same count `requestTokens` sums for a whole request.
|
|
182
|
+
- `requestChars` — How many characters a request is worth: the walk `requestTokens` divides, without the division.
|
|
155
183
|
- `requestTokens` — What this request will cost the window, in tokens, near enough.
|
|
156
184
|
- `SMALLEST_LIKELY_WINDOW` — The smallest window worth believing in, and the floor under `runTurn`'s guard.
|
|
157
185
|
- `sleep` — A delay an abort cuts short, rejecting rather than resolving early.
|
|
186
|
+
- `TokenEstimateOptions` (type) — What the two token estimates below take besides what they measure.
|
|
187
|
+
- `toolsChars` — How many characters a tool array is worth, measured once per array.
|
|
158
188
|
|
|
159
189
|
### run-turn
|
|
160
190
|
|
|
@@ -205,7 +235,7 @@ Reading one streamed turn back into a message.
|
|
|
205
235
|
- `StreamTurnOptions` (type) — What `streamTurn` takes besides the request body.
|
|
206
236
|
- `streamTurn` — Runs one turn as a stream, reporting tokens as they arrive and assembling them back into a message.
|
|
207
237
|
- `Turn` (type) — One streamed turn, put back together into the shape a loop and a transcript work with.
|
|
208
|
-
- `TurnUsage` (type) — What a turn cost.
|
|
238
|
+
- `TurnUsage` (type) — What a turn cost, and how it went.
|
|
209
239
|
|
|
210
240
|
### thinking
|
|
211
241
|
|
|
@@ -246,9 +276,11 @@ Reading what a model meant by a tool call when it did not write one cleanly.
|
|
|
246
276
|
- `loadResult` — What `load_tools` reports back: the descriptions, now that they are worth their tokens.
|
|
247
277
|
- `MAX_CARRIED` — The most a conversation carries between turns.
|
|
248
278
|
- `MAX_PER_LOAD` — The most a single `load_tools` call may pull in.
|
|
279
|
+
- `orderTools` — The tool array in a stable order, so the same set of tools renders the same way twice.
|
|
249
280
|
- `PRESELECT_SCHEMA` — The shape a preselector's answer is held to where the server takes a schema: `{ tools: [...] }`.
|
|
250
281
|
- `PRESELECT_SYSTEM` — The preselection system prompt at the default cap, for a caller that never changes it.
|
|
251
282
|
- `preselectInput` — The user message for a preselection call: the catalogue, then the request.
|
|
252
283
|
- `preselection` — Resolves a preselection against the catalogue: unknown names dropped, count capped.
|
|
253
284
|
- `preselectSystem` — The system prompt a preselector is given, holding it to the cap its answer will be held to.
|
|
254
285
|
- `requestedNames` — `load_tools` arguments, defensively — a model may send a bare string or a nested object.
|
|
286
|
+
- `ToolOrder` (type) — How a tool array is ordered before it is sent: `true` by name, `false` as the caller built it, or a comparator over the two names.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubicecho/agent-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"description": "The endpoint-agnostic half of an OpenAI-compatible agent loop: tool-schema compatibility, on-demand tool loading, one-shot side tasks, run events, and a pooled client.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openai",
|