mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
fix(ai): preserve active turn context ownership
Avoid aliasing Agent state into the Pi loop, which duplicated finalization messages. 避免将 Agent 状态数组交回 Pi 循环,防止终局消息被重复写入。
This commit is contained in:
1 parent
758b0667fc
commit
90bf3b6400
2 files changed
+13
-6
No files matched your search
@@ -309,13 +309,21 @@ describe('runAgentCore runtime contract', () => {
|
||||
assert.equal(result.toolRounds, 1)
|
||||
assert.deepEqual(finalContext?.tools, [])
|
||||
assert.equal(
|
||||
finalContext?.messages.some(
|
||||
finalContext?.messages.filter(
|
||||
(message) =>
|
||||
message.role === 'user' &&
|
||||
Array.isArray(message.content) &&
|
||||
message.content.some((block) => block.type === 'text' && block.text === 'Finish now.')
|
||||
),
|
||||
true
|
||||
).length,
|
||||
1
|
||||
)
|
||||
assert.equal(
|
||||
result.finalMessages.filter(
|
||||
(message) =>
|
||||
message.role === 'assistant' &&
|
||||
message.content.some((block) => block.type === 'text' && block.text === 'Done')
|
||||
).length,
|
||||
1
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -127,12 +127,11 @@ export async function runAgentCore(options: AgentCoreOptions): Promise<AgentCore
|
||||
onConvertToLlm?.(filtered)
|
||||
return filtered
|
||||
},
|
||||
prepareNextTurn: () =>
|
||||
prepareNextTurnWithContext: ({ context }) =>
|
||||
hasReachedToolRoundLimit
|
||||
? {
|
||||
context: {
|
||||
systemPrompt,
|
||||
messages: coreAgent.state.messages,
|
||||
...context,
|
||||
tools: [],
|
||||
},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user