@cubicecho/agent-core 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/retry.d.ts +4 -2
- package/dist/retry.js +21 -6
- package/dist/side-task.d.ts +5 -0
- package/dist/side-task.js +1 -1
- package/package.json +1 -1
package/dist/retry.d.ts
CHANGED
|
@@ -33,8 +33,10 @@ export declare const compact: (tokens: number) => string;
|
|
|
33
33
|
* built the entire transcript into a string on every call and threw it away having read nothing
|
|
34
34
|
* but its `.length` — against a transcript that grows by a turn each turn, and one the SDK is
|
|
35
35
|
* about to serialise again to send. What the walk misses is JSON's own punctuation and the keys,
|
|
36
|
-
* which
|
|
37
|
-
*
|
|
36
|
+
* which the envelope constants put back — one per key rather than one per message, since the
|
|
37
|
+
* three keys only some shapes carry are most of what a tool-using transcript is made of. What
|
|
38
|
+
* is left is a message's escaping, which is not a constant and is small against an estimate
|
|
39
|
+
* that is already characters over four.
|
|
38
40
|
*
|
|
39
41
|
* @param body The request as it will be sent, tools included.
|
|
40
42
|
*/
|
package/dist/retry.js
CHANGED
|
@@ -29,9 +29,20 @@ export const compact = (tokens) => tokens >= 1000 ? `${(tokens / 1000).toFixed(1
|
|
|
29
29
|
const ENVELOPE = 25;
|
|
30
30
|
/** The same for `{"id":"","type":"function","function":{"name":"","arguments":""}},` in a call. */
|
|
31
31
|
const CALL_ENVELOPE = 66;
|
|
32
|
+
// `ENVELOPE` is the two keys every message has. These are the three that only some do, and each
|
|
33
|
+
// is the key with its punctuation and the comma after the value it holds — the value's own
|
|
34
|
+
// length is counted where the value is read. Applying `ENVELOPE` alone to these shapes left the
|
|
35
|
+
// keys out, which cost 4.5 tokens on every tool result: the message a tool-using run has most
|
|
36
|
+
// of, and short in the direction that lets an overflow through the guard meant to catch it.
|
|
37
|
+
/** What `"name":"",` costs around a message's name. */
|
|
38
|
+
const NAME_KEY = 10;
|
|
39
|
+
/** The same for `"tool_call_id":"",` around a tool result's call id. */
|
|
40
|
+
const TOOL_CALL_ID_KEY = 18;
|
|
41
|
+
/** The same for `"tool_calls":[]` around the calls; each call's own comma is in `CALL_ENVELOPE`. */
|
|
42
|
+
const TOOL_CALLS_KEY = 15;
|
|
32
43
|
/** The divisor behind `estimateTokens`, applied here to a character count rather than a string. */
|
|
33
44
|
const CHARS_PER_TOKEN = 4;
|
|
34
|
-
/** How many characters one message is worth
|
|
45
|
+
/** How many characters one message is worth: its keys, and its content in whichever shape. */
|
|
35
46
|
function messageChars(message) {
|
|
36
47
|
let chars = message.role.length + ENVELOPE;
|
|
37
48
|
const { content } = message;
|
|
@@ -47,15 +58,17 @@ function messageChars(message) {
|
|
|
47
58
|
chars += part.refusal.length;
|
|
48
59
|
}
|
|
49
60
|
if ("name" in message && typeof message.name === "string")
|
|
50
|
-
chars += message.name.length;
|
|
61
|
+
chars += NAME_KEY + message.name.length;
|
|
51
62
|
if ("tool_call_id" in message && typeof message.tool_call_id === "string")
|
|
52
|
-
chars += message.tool_call_id.length;
|
|
53
|
-
if ("tool_calls" in message && Array.isArray(message.tool_calls))
|
|
63
|
+
chars += TOOL_CALL_ID_KEY + message.tool_call_id.length;
|
|
64
|
+
if ("tool_calls" in message && Array.isArray(message.tool_calls)) {
|
|
65
|
+
chars += TOOL_CALLS_KEY;
|
|
54
66
|
for (const call of message.tool_calls) {
|
|
55
67
|
chars += CALL_ENVELOPE + call.id.length;
|
|
56
68
|
if (call.type === "function")
|
|
57
69
|
chars += call.function.name.length + call.function.arguments.length;
|
|
58
70
|
}
|
|
71
|
+
}
|
|
59
72
|
return chars;
|
|
60
73
|
}
|
|
61
74
|
/**
|
|
@@ -92,8 +105,10 @@ function toolsCost(tools) {
|
|
|
92
105
|
* built the entire transcript into a string on every call and threw it away having read nothing
|
|
93
106
|
* but its `.length` — against a transcript that grows by a turn each turn, and one the SDK is
|
|
94
107
|
* about to serialise again to send. What the walk misses is JSON's own punctuation and the keys,
|
|
95
|
-
* which
|
|
96
|
-
*
|
|
108
|
+
* which the envelope constants put back — one per key rather than one per message, since the
|
|
109
|
+
* three keys only some shapes carry are most of what a tool-using transcript is made of. What
|
|
110
|
+
* is left is a message's escaping, which is not a constant and is small against an estimate
|
|
111
|
+
* that is already characters over four.
|
|
97
112
|
*
|
|
98
113
|
* @param body The request as it will be sent, tools included.
|
|
99
114
|
*/
|
package/dist/side-task.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface SideTaskOptions {
|
|
|
12
12
|
/**
|
|
13
13
|
* Told what was given up on, the same way `runTurn` and `negotiate` tell a caller.
|
|
14
14
|
*
|
|
15
|
+
* The one notice `ask` raises itself opens with the model's name, as `negotiate`'s do for the
|
|
16
|
+
* refusals that are the model's: what it announces is latched on the (endpoint, model) pair,
|
|
17
|
+
* so on a consumer reaching several models through one base URL the name is the only thing
|
|
18
|
+
* separating one announcement from the next.
|
|
19
|
+
*
|
|
15
20
|
* There is no default, and nothing is printed without one. A library that writes to the
|
|
16
21
|
* console decides for its consumer where operator text goes — which a server embedding this
|
|
17
22
|
* cannot then route to its own logger, attach to the run it belongs to, or silence in tests.
|
package/dist/side-task.js
CHANGED
|
@@ -125,7 +125,7 @@ export async function ask(config, model, system, user, { maxTokens = 512, temper
|
|
|
125
125
|
// does not offer as `none`.
|
|
126
126
|
if (!hints || !rejectedTheRequest(error))
|
|
127
127
|
throw error;
|
|
128
|
-
onNotice?.(
|
|
128
|
+
onNotice?.(`${model} rejected the no-thinking hints; retrying without them`);
|
|
129
129
|
noHints.add(key);
|
|
130
130
|
response = await attempt(false);
|
|
131
131
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubicecho/agent-core",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
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",
|