@botbotgo/agent-harness 0.0.273 → 0.0.274
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/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/runtime/adapter/runtime-shell.d.ts +1 -0
- package/dist/runtime/adapter/runtime-shell.js +9 -5
- package/dist/runtime/parsing/output-parsing.d.ts +4 -0
- package/dist/runtime/parsing/output-parsing.js +28 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export declare const AGENT_HARNESS_VERSION = "0.0.273";
|
package/dist/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export const AGENT_HARNESS_VERSION = "0.0.273";
|
|
@@ -21,6 +21,7 @@ export declare function createModelFallbackRunnable(model: {
|
|
|
21
21
|
stream: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
|
|
22
22
|
};
|
|
23
23
|
export declare function applyStrictToolJsonInstruction(binding: CompiledAgentBinding): CompiledAgentBinding;
|
|
24
|
+
export declare function applyToolRecoveryInstruction(binding: CompiledAgentBinding, instruction: string): CompiledAgentBinding;
|
|
24
25
|
export declare function callRuntimeWithToolParseRecovery(input: {
|
|
25
26
|
binding: CompiledAgentBinding;
|
|
26
27
|
request: unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
2
|
-
import { extractVisibleOutput, isToolCallRecoveryFailure, STRICT_TOOL_JSON_INSTRUCTION } from "../parsing/output-parsing.js";
|
|
2
|
+
import { appendToolRecoveryInstruction, extractVisibleOutput, isToolCallRecoveryFailure, resolveToolCallRecoveryInstruction, STRICT_TOOL_JSON_INSTRUCTION, } from "../parsing/output-parsing.js";
|
|
3
3
|
import { readStreamDelta } from "../parsing/stream-event-parsing.js";
|
|
4
4
|
import { computeRemainingTimeoutMs, isRetryableProviderError, resolveProviderRetryPolicy } from "./resilience.js";
|
|
5
5
|
import { isDeepAgentBinding, isLangChainBinding, withUpdatedBindingExecutionParams, } from "../support/compiled-binding.js";
|
|
@@ -134,16 +134,19 @@ export function createModelFallbackRunnable(model) {
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
export function applyStrictToolJsonInstruction(binding) {
|
|
137
|
+
return applyToolRecoveryInstruction(binding, STRICT_TOOL_JSON_INSTRUCTION);
|
|
138
|
+
}
|
|
139
|
+
export function applyToolRecoveryInstruction(binding, instruction) {
|
|
137
140
|
if (isLangChainBinding(binding)) {
|
|
138
141
|
return withUpdatedBindingExecutionParams(binding, (params) => ({
|
|
139
142
|
...params,
|
|
140
|
-
systemPrompt: [params.systemPrompt,
|
|
143
|
+
systemPrompt: [params.systemPrompt, instruction].filter(Boolean).join("\n\n"),
|
|
141
144
|
}));
|
|
142
145
|
}
|
|
143
146
|
if (isDeepAgentBinding(binding)) {
|
|
144
147
|
return withUpdatedBindingExecutionParams(binding, (params) => ({
|
|
145
148
|
...params,
|
|
146
|
-
systemPrompt: [params.systemPrompt,
|
|
149
|
+
systemPrompt: [params.systemPrompt, instruction].filter(Boolean).join("\n\n"),
|
|
147
150
|
}));
|
|
148
151
|
}
|
|
149
152
|
return binding;
|
|
@@ -153,9 +156,10 @@ export async function callRuntimeWithToolParseRecovery(input) {
|
|
|
153
156
|
return await input.callRuntime(input.binding, input.request);
|
|
154
157
|
}
|
|
155
158
|
catch (error) {
|
|
156
|
-
|
|
159
|
+
const recoveryInstruction = resolveToolCallRecoveryInstruction(error);
|
|
160
|
+
if (input.resumePayload !== undefined || !recoveryInstruction || !isToolCallRecoveryFailure(error)) {
|
|
157
161
|
throw error;
|
|
158
162
|
}
|
|
159
|
-
return input.callRuntime(
|
|
163
|
+
return input.callRuntime(applyToolRecoveryInstruction(input.binding, recoveryInstruction), appendToolRecoveryInstruction(input.request, recoveryInstruction));
|
|
160
164
|
}
|
|
161
165
|
}
|
|
@@ -13,5 +13,9 @@ export declare function isToolCallParseFailure(error: unknown): boolean;
|
|
|
13
13
|
export declare function isToolCallValidationFailure(error: unknown): boolean;
|
|
14
14
|
export declare function isToolCallRecoveryFailure(error: unknown): boolean;
|
|
15
15
|
export declare const STRICT_TOOL_JSON_INSTRUCTION = "When calling tools, return only the tool call itself. The arguments must be a pure JSON object with no explanatory text before or after it.";
|
|
16
|
+
export declare const WRITE_TODOS_FULL_ENTRY_INSTRUCTION = "When calling write_todos, every todo item must include both content and status. Do not send status-only updates. Retry by resending the full todo entry with the original content preserved.";
|
|
17
|
+
export declare function isRepairableWriteTodosContentFailure(error: unknown): boolean;
|
|
18
|
+
export declare function resolveToolCallRecoveryInstruction(error: unknown): string | null;
|
|
19
|
+
export declare function appendToolRecoveryInstruction(input: unknown, instruction: string): unknown;
|
|
16
20
|
export declare function wrapResolvedModel<T>(value: T): T;
|
|
17
21
|
export declare function extractReasoningText(value: unknown): string;
|
|
@@ -509,20 +509,41 @@ export function isToolCallValidationFailure(error) {
|
|
|
509
509
|
if (Array.isArray(direct) && direct.length > 0 && direct.every((issue) => isStructuredValidationIssue(issue) && issue.path.length > 0)) {
|
|
510
510
|
return true;
|
|
511
511
|
}
|
|
512
|
-
|
|
512
|
+
if (/Invalid input:\s*expected .* received undefined/i.test(message) && /"path"\s*:\s*\[/.test(message)) {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
return /Received tool input did not match expected schema/i.test(message) && /(?:→\s*at|at)\s+[\w[\].]+/i.test(message);
|
|
513
516
|
}
|
|
514
517
|
export function isToolCallRecoveryFailure(error) {
|
|
515
518
|
return isToolCallParseFailure(error) || isToolCallValidationFailure(error);
|
|
516
519
|
}
|
|
517
520
|
export const STRICT_TOOL_JSON_INSTRUCTION = "When calling tools, return only the tool call itself. The arguments must be a pure JSON object with no explanatory text before or after it.";
|
|
518
|
-
|
|
521
|
+
export const WRITE_TODOS_FULL_ENTRY_INSTRUCTION = "When calling write_todos, every todo item must include both content and status. Do not send status-only updates. Retry by resending the full todo entry with the original content preserved.";
|
|
522
|
+
export function isRepairableWriteTodosContentFailure(error) {
|
|
523
|
+
if (!(error instanceof Error))
|
|
524
|
+
return false;
|
|
525
|
+
const message = error.message.trim();
|
|
526
|
+
if (!message)
|
|
527
|
+
return false;
|
|
528
|
+
return /write_todos/i.test(message) && /todos\[\d+\]\.content/i.test(message);
|
|
529
|
+
}
|
|
530
|
+
export function resolveToolCallRecoveryInstruction(error) {
|
|
531
|
+
if (isRepairableWriteTodosContentFailure(error)) {
|
|
532
|
+
return WRITE_TODOS_FULL_ENTRY_INSTRUCTION;
|
|
533
|
+
}
|
|
534
|
+
if (isToolCallRecoveryFailure(error)) {
|
|
535
|
+
return STRICT_TOOL_JSON_INSTRUCTION;
|
|
536
|
+
}
|
|
537
|
+
return null;
|
|
538
|
+
}
|
|
539
|
+
export function appendToolRecoveryInstruction(input, instruction) {
|
|
519
540
|
if (Array.isArray(input)) {
|
|
520
|
-
return [...input, { role: "system", content:
|
|
541
|
+
return [...input, { role: "system", content: instruction }];
|
|
521
542
|
}
|
|
522
543
|
if (typeof input === "object" && input && Array.isArray(input.messages)) {
|
|
523
544
|
return {
|
|
524
545
|
...input,
|
|
525
|
-
messages: [...(input.messages), { role: "system", content:
|
|
546
|
+
messages: [...(input.messages), { role: "system", content: instruction }],
|
|
526
547
|
};
|
|
527
548
|
}
|
|
528
549
|
return input;
|
|
@@ -540,11 +561,12 @@ export function wrapResolvedModel(value) {
|
|
|
540
561
|
return normalizeAgentMessage(await member.apply(currentTarget, args));
|
|
541
562
|
}
|
|
542
563
|
catch (error) {
|
|
543
|
-
|
|
564
|
+
const recoveryInstruction = resolveToolCallRecoveryInstruction(error);
|
|
565
|
+
if (!recoveryInstruction) {
|
|
544
566
|
throw error;
|
|
545
567
|
}
|
|
546
568
|
const retryArgs = [...args];
|
|
547
|
-
retryArgs[0] =
|
|
569
|
+
retryArgs[0] = appendToolRecoveryInstruction(retryArgs[0], recoveryInstruction);
|
|
548
570
|
return normalizeAgentMessage(await member.apply(currentTarget, retryArgs));
|
|
549
571
|
}
|
|
550
572
|
};
|