@caupulican/pi-adaptative 0.81.13 → 0.81.15
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/CHANGELOG.md +8 -0
- package/dist/bundled-resources/skills/tool-call-repair/SKILL.md +13 -11
- package/dist/bundled-resources/skills/tool-call-repair/references/failure-grammar.md +16 -10
- package/dist/core/agent-session.d.ts +2 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +40 -7
- package/dist/core/agent-session.js.map +1 -1
- package/docs/tool-repair.md +2 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -151,6 +151,7 @@ export class AgentSession {
|
|
|
151
151
|
_repairModeSessionCounts = new Map();
|
|
152
152
|
_textProtocolParseFailures = new Map();
|
|
153
153
|
_textProtocolParseObservedThisTurn = false;
|
|
154
|
+
_textProtocolValidationOutcomeThisTurn;
|
|
154
155
|
/** Assembles the session's base system prompt from live session state (see
|
|
155
156
|
* system-prompt-builder.ts); owns the paired _baseSystemPromptOptions. */
|
|
156
157
|
_systemPromptBuilder;
|
|
@@ -507,6 +508,7 @@ export class AgentSession {
|
|
|
507
508
|
previousToolArgumentValidation?.(taggedEvent);
|
|
508
509
|
this._analytics.recordToolArgumentValidation(taggedEvent);
|
|
509
510
|
this._recordToolValidationBounce(taggedEvent);
|
|
511
|
+
this._handleTextToolProtocolValidationOutcome(taggedEvent);
|
|
510
512
|
this._handleModelAdaptationTelemetry(taggedEvent);
|
|
511
513
|
};
|
|
512
514
|
this._treeNavigator = new SessionTreeNavigator({
|
|
@@ -837,7 +839,6 @@ export class AgentSession {
|
|
|
837
839
|
return {
|
|
838
840
|
systemPrompt: `${primer}\n\n${instruction}`,
|
|
839
841
|
messages: [{ role: "user", content: [{ type: "text", text: instruction }], timestamp: Date.now() }],
|
|
840
|
-
tools: [TEXT_TOOL_PROTOCOL_ECHO_TOOL],
|
|
841
842
|
};
|
|
842
843
|
}
|
|
843
844
|
_messageHasEchoProbe(message, token) {
|
|
@@ -850,17 +851,17 @@ export class AgentSession {
|
|
|
850
851
|
systemPrompt: instruction,
|
|
851
852
|
messages: [{ role: "user", content: [{ type: "text", text: instruction }], timestamp: Date.now() }],
|
|
852
853
|
tools: [TEXT_TOOL_PROTOCOL_ECHO_TOOL],
|
|
853
|
-
}, { textToolCallProtocol: false, maxRetries: 0 });
|
|
854
|
+
}, { textToolCallProtocol: false, maxRetries: 0, temperature: 0, maxTokens: 256 });
|
|
854
855
|
return this._messageHasEchoProbe(await stream.result(), token);
|
|
855
856
|
}
|
|
856
857
|
async _runTextProtocolTrial(model, variant, token) {
|
|
857
858
|
const stream = await this._streamForToolProbe(model, this._textProtocolCalibrationContext(variant, token), {
|
|
858
859
|
textToolCallProtocol: false,
|
|
859
860
|
maxRetries: 0,
|
|
861
|
+
temperature: 0,
|
|
862
|
+
maxTokens: 256,
|
|
860
863
|
});
|
|
861
864
|
const message = await stream.result();
|
|
862
|
-
if (this._messageHasEchoProbe(message, token))
|
|
863
|
-
return true;
|
|
864
865
|
const text = message.content
|
|
865
866
|
.filter((block) => block.type === "text")
|
|
866
867
|
.map((block) => block.text)
|
|
@@ -1007,10 +1008,8 @@ export class AgentSession {
|
|
|
1007
1008
|
_handleTextToolProtocolParse(event) {
|
|
1008
1009
|
this._textProtocolParseObservedThisTurn = true;
|
|
1009
1010
|
const modelKey = `${event.provider}/${event.model}`;
|
|
1010
|
-
if (event.status === "parsed")
|
|
1011
|
-
this._textProtocolParseFailures.delete(modelKey);
|
|
1011
|
+
if (event.status === "parsed")
|
|
1012
1012
|
return;
|
|
1013
|
-
}
|
|
1014
1013
|
const signature = `${event.variant}:${event.reason ?? "failed"}`;
|
|
1015
1014
|
const previous = this._textProtocolParseFailures.get(modelKey);
|
|
1016
1015
|
const repeats = previous?.signature === signature ? previous.repeats + 1 : 1;
|
|
@@ -1024,7 +1023,40 @@ export class AgentSession {
|
|
|
1024
1023
|
}
|
|
1025
1024
|
this._textProtocolParseFailures.delete(modelKey);
|
|
1026
1025
|
}
|
|
1026
|
+
_handleTextToolProtocolValidationOutcome(event) {
|
|
1027
|
+
if (event.source !== "text-protocol")
|
|
1028
|
+
return;
|
|
1029
|
+
const protocol = this.agent.textToolCallProtocol;
|
|
1030
|
+
const variant = protocol === true ? "tool-tag" : protocol ? protocol.variant : undefined;
|
|
1031
|
+
if (!variant)
|
|
1032
|
+
return;
|
|
1033
|
+
const status = event.outcome === "bounced" ? "failed" : "parsed";
|
|
1034
|
+
if (this._textProtocolValidationOutcomeThisTurn?.status === "parsed" && status === "failed")
|
|
1035
|
+
return;
|
|
1036
|
+
this._textProtocolValidationOutcomeThisTurn = {
|
|
1037
|
+
provider: event.provider ?? this.agent.state.model.provider,
|
|
1038
|
+
model: event.model ?? this.agent.state.model.id,
|
|
1039
|
+
variant,
|
|
1040
|
+
status,
|
|
1041
|
+
callCount: 1,
|
|
1042
|
+
textLength: 0,
|
|
1043
|
+
...(status === "failed" && {
|
|
1044
|
+
reason: event.errorKeywords?.includes("unknown_tool") ? "unknown-tool" : "validation-failed",
|
|
1045
|
+
}),
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1027
1048
|
_recordTextToolProtocolParseOutcomeFromLastAssistant() {
|
|
1049
|
+
const validationOutcome = this._textProtocolValidationOutcomeThisTurn;
|
|
1050
|
+
this._textProtocolValidationOutcomeThisTurn = undefined;
|
|
1051
|
+
if (validationOutcome?.status === "parsed") {
|
|
1052
|
+
this._textProtocolParseObservedThisTurn = true;
|
|
1053
|
+
this._textProtocolParseFailures.delete(`${validationOutcome.provider}/${validationOutcome.model}`);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (validationOutcome) {
|
|
1057
|
+
this._handleTextToolProtocolParse(validationOutcome);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1028
1060
|
if (this._textProtocolParseObservedThisTurn)
|
|
1029
1061
|
return;
|
|
1030
1062
|
const protocol = this.agent.textToolCallProtocol;
|
|
@@ -2181,6 +2213,7 @@ export class AgentSession {
|
|
|
2181
2213
|
}
|
|
2182
2214
|
preflightResult?.(true);
|
|
2183
2215
|
this._textProtocolParseObservedThisTurn = false;
|
|
2216
|
+
this._textProtocolValidationOutcomeThisTurn = undefined;
|
|
2184
2217
|
await this._modelRouter.runRoutedTurn(messages, routedTurnModel, routedTurnRouteDecision);
|
|
2185
2218
|
this._recordTextToolProtocolParseOutcomeFromLastAssistant();
|
|
2186
2219
|
// R4: score whether the agent actually used the recalled context, so the recall gate can adapt.
|