feat(agent): add provider options passthrough, tool call records, and completion validation retries

This commit is contained in:
2026-05-07 10:26:45 +00:00
parent 0dde716109
commit b08cb3689e
10 changed files with 901 additions and 603 deletions
+21 -1
View File
@@ -1,4 +1,13 @@
import type { ToolSet, ModelMessage, LanguageModelV3 } from './plugins.js';
import type { ToolSet, ModelMessage, LanguageModelV3, ProviderOptions } from './plugins.js';
export type { ProviderOptions };
export interface IAgentToolCallRecord {
toolName: string;
input: unknown;
output?: unknown;
error?: string;
}
export interface IAgentRunOptions {
/** The LanguageModelV3 to use — from smartai.getModel() */
@@ -9,6 +18,8 @@ export interface IAgentRunOptions {
system?: string;
/** Tools available to the agent */
tools?: ToolSet;
/** Provider-specific AI SDK request options passed through to streamText() */
providerOptions?: ProviderOptions;
/**
* Maximum number of LLM↔tool round trips.
* Each step may execute multiple tools in parallel.
@@ -23,6 +34,13 @@ export interface IAgentRunOptions {
onToolCall?: (toolName: string, input: unknown) => void;
/** Called when a tool call completes */
onToolResult?: (toolName: string, result: unknown) => void;
/**
* Validate the completed run. Return a string to reject the run and reprompt,
* or return void to accept the result.
*/
validateCompletion?: (result: IAgentRunResult) => Promise<string | void> | string | void;
/** Number of validation-triggered reprompts allowed. Default: 0 */
maxValidationRetries?: number;
/**
* Called when total token usage approaches the model's context limit.
* Receives the full message history and must return a compacted replacement.
@@ -44,6 +62,8 @@ export interface IAgentRunResult {
finishReason: string;
/** Accumulated token usage across all steps */
usage: { inputTokens: number; outputTokens: number; totalTokens: number };
/** Tool calls observed during the run, including inputs and outputs/errors when available */
toolCalls: IAgentToolCallRecord[];
}
export class ContextOverflowError extends Error {