clanka 0.12.2 → 0.12.3
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/Agent.d.ts.map +1 -1
- package/dist/Agent.js +13 -7
- package/dist/Agent.js.map +1 -1
- package/dist/Agent.test.js +28 -12
- package/dist/Agent.test.js.map +1 -1
- package/dist/bin/cli.mjs +6 -4
- package/dist/bin/cli.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Agent.test.ts +31 -13
- package/src/Agent.ts +14 -7
package/package.json
CHANGED
package/src/Agent.test.ts
CHANGED
|
@@ -1342,17 +1342,15 @@ const reasoning = (content: string): Array<Response.StreamPartEncoded> => [
|
|
|
1342
1342
|
]
|
|
1343
1343
|
|
|
1344
1344
|
// Conversation mode ends the turn on a response without a tool call, so a
|
|
1345
|
-
// response that never finished or
|
|
1345
|
+
// response that never finished or failed must be retried instead.
|
|
1346
1346
|
describe("Agent incomplete responses", () => {
|
|
1347
1347
|
const cases: ReadonlyArray<{
|
|
1348
1348
|
readonly name: string
|
|
1349
1349
|
readonly response: ReadonlyArray<Response.StreamPartEncoded>
|
|
1350
|
-
readonly reportsError: boolean
|
|
1351
1350
|
}> = [
|
|
1352
1351
|
{
|
|
1353
1352
|
name: "a stream that ends without a finish part",
|
|
1354
1353
|
response: reasoning("Checking the parser"),
|
|
1355
|
-
reportsError: true,
|
|
1356
1354
|
},
|
|
1357
1355
|
{
|
|
1358
1356
|
name: "an error response",
|
|
@@ -1361,16 +1359,10 @@ describe("Agent incomplete responses", () => {
|
|
|
1361
1359
|
{ type: "error", error: { message: "upstream failed" } },
|
|
1362
1360
|
finish(100, "error"),
|
|
1363
1361
|
],
|
|
1364
|
-
reportsError: true,
|
|
1365
|
-
},
|
|
1366
|
-
{
|
|
1367
|
-
name: "a finished response with only reasoning",
|
|
1368
|
-
response: [...reasoning("Checking the parser"), finish(100, "stop")],
|
|
1369
|
-
reportsError: false,
|
|
1370
1362
|
},
|
|
1371
1363
|
]
|
|
1372
1364
|
|
|
1373
|
-
for (const { name, response
|
|
1365
|
+
for (const { name, response } of cases) {
|
|
1374
1366
|
it.live(`retries ${name} instead of ending the turn`, () =>
|
|
1375
1367
|
Effect.gen(function* () {
|
|
1376
1368
|
const { exit, calls, outputs } = yield* runAgentCollect({
|
|
@@ -1390,13 +1382,39 @@ describe("Agent incomplete responses", () => {
|
|
|
1390
1382
|
})
|
|
1391
1383
|
assert.strictEqual(calls.length, 2, "the model is called again")
|
|
1392
1384
|
assert.deepStrictEqual(exit, Exit.succeed("the answer"))
|
|
1393
|
-
|
|
1394
|
-
assert.strictEqual(outputsOfTag(outputs, "ErrorRetry").length, 1)
|
|
1395
|
-
}
|
|
1385
|
+
assert.strictEqual(outputsOfTag(outputs, "ErrorRetry").length, 1)
|
|
1396
1386
|
}),
|
|
1397
1387
|
)
|
|
1398
1388
|
}
|
|
1399
1389
|
|
|
1390
|
+
// An empty response is neither an answer nor a failure, so the loop starts
|
|
1391
|
+
// another turn without reporting an error.
|
|
1392
|
+
it.live("starts another turn after a finished response with no text", () =>
|
|
1393
|
+
Effect.gen(function* () {
|
|
1394
|
+
const { exit, calls, outputs } = yield* runAgentCollect({
|
|
1395
|
+
respond: (_call, index) => {
|
|
1396
|
+
switch (index) {
|
|
1397
|
+
case 0:
|
|
1398
|
+
return Stream.fromIterable([
|
|
1399
|
+
...reasoning("Nothing to do"),
|
|
1400
|
+
finish(100, "stop"),
|
|
1401
|
+
])
|
|
1402
|
+
case 1:
|
|
1403
|
+
return Stream.fromIterable([
|
|
1404
|
+
...text("the answer"),
|
|
1405
|
+
finish(100, "stop"),
|
|
1406
|
+
])
|
|
1407
|
+
default:
|
|
1408
|
+
return Stream.die(`unexpected model call #${index}`)
|
|
1409
|
+
}
|
|
1410
|
+
},
|
|
1411
|
+
})
|
|
1412
|
+
assert.strictEqual(calls.length, 2, "the model is called again")
|
|
1413
|
+
assert.deepStrictEqual(exit, Exit.succeed("the answer"))
|
|
1414
|
+
assert.strictEqual(outputsOfTag(outputs, "ErrorRetry").length, 0)
|
|
1415
|
+
}),
|
|
1416
|
+
)
|
|
1417
|
+
|
|
1400
1418
|
it.live("keeps a tool result when the response then reports an error", () =>
|
|
1401
1419
|
Effect.gen(function* () {
|
|
1402
1420
|
let executions = 0
|
package/src/Agent.ts
CHANGED
|
@@ -939,8 +939,10 @@ ${Compaction.capOutput(turn.output ?? "").output}
|
|
|
939
939
|
}
|
|
940
940
|
let reasoningStarted = false
|
|
941
941
|
let hadReasoningDelta = false
|
|
942
|
-
// A response that would end the turn must be
|
|
943
|
-
// failed, or
|
|
942
|
+
// A response that would end the turn must be complete. One that
|
|
943
|
+
// failed, or stopped before it finished with nothing to return, takes
|
|
944
|
+
// the retry path instead. A finished response with no text starts
|
|
945
|
+
// another turn below.
|
|
944
946
|
// Once a tool call is in the response its tool may have run, so the
|
|
945
947
|
// response is kept and the loop continues with the result.
|
|
946
948
|
const checkResponse = () => {
|
|
@@ -956,14 +958,16 @@ ${Compaction.capOutput(turn.output ?? "").output}
|
|
|
956
958
|
mailbox.messages.size === 0 &&
|
|
957
959
|
runningChildren().length === 0 &&
|
|
958
960
|
!hasUndelivered()
|
|
959
|
-
if (
|
|
961
|
+
if (
|
|
962
|
+
!endsTurn ||
|
|
963
|
+
finished ||
|
|
964
|
+
responseToSummary(response).trim() !== ""
|
|
965
|
+
) {
|
|
960
966
|
return Effect.void
|
|
961
967
|
}
|
|
962
968
|
return Effect.fail(
|
|
963
969
|
incompleteResponseError(
|
|
964
|
-
finished
|
|
965
|
-
? "The model response had no text and no tool call"
|
|
966
|
-
: "The model response ended before it finished",
|
|
970
|
+
"The model response ended before it finished",
|
|
967
971
|
),
|
|
968
972
|
)
|
|
969
973
|
}
|
|
@@ -1188,7 +1192,10 @@ ${Compaction.capOutput(turn.output ?? "").output}
|
|
|
1188
1192
|
yield* waitForActivity
|
|
1189
1193
|
continue
|
|
1190
1194
|
}
|
|
1191
|
-
|
|
1195
|
+
const summary = responseToSummary(response)
|
|
1196
|
+
// An empty response is not an answer, so ask the model again.
|
|
1197
|
+
if (summary.trim() === "") continue
|
|
1198
|
+
finalSummary = Option.some(summary)
|
|
1192
1199
|
}
|
|
1193
1200
|
}
|
|
1194
1201
|
}).pipe(
|