BREAKING CHANGE(api): Migrate public API to ai-sdk v6 and refactor core agent architecture: replace class-based DualAgent/Driver/Guardian with a single runAgent function; introduce ts_tools factories for tools, a compactMessages compaction subpath, and truncateOutput utility; simplify ToolRegistry to return ToolSet and remove legacy BaseToolWrapper/tool classes; update package exports and dependencies and bump major version.

This commit is contained in:
2026-03-06 11:39:01 +00:00
parent 903de44644
commit f9a9c9fb48
36 changed files with 3928 additions and 6586 deletions

View File

@@ -0,0 +1,51 @@
import * as plugins from './plugins.js';
const COMPACTION_PROMPT = `Provide a detailed prompt for continuing our conversation above.
Focus on information that would be helpful for continuing the conversation, including what we did, what we're doing, which files we're working on, and what we're going to do next.
The summary that you construct will be used so that another agent can read it and continue the work.
When constructing the summary, try to stick to this template:
---
## Goal
[What goal(s) is the user trying to accomplish?]
## Instructions
- [What important instructions did the user give you that are relevant]
## Discoveries
[What notable things were learned during this conversation that would be useful for the next agent to know]
## Accomplished
[What work has been completed, what work is still in progress, and what work is left?]
## Relevant files / directories
[A structured list of relevant files that have been read, edited, or created]
---`;
/**
* Compacts a message history into a summary.
* Pass this as the onContextOverflow handler in IAgentRunOptions.
*
* @param model The same model used by runAgent, or a cheaper small model
* @param messages The full message history that overflowed
* @returns A minimal ModelMessage[] containing the summary as context
*/
export async function compactMessages(
model: plugins.LanguageModelV3,
messages: plugins.ModelMessage[],
): Promise<plugins.ModelMessage[]> {
const result = await plugins.generateText({
model,
messages: [
...messages,
{ role: 'user', content: COMPACTION_PROMPT },
],
});
return [
{
role: 'user',
content: `[Previous conversation summary]\n\n${result.text}\n\n[End of summary. Continue from here.]`,
},
];
}