73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
/**
|
|
* Copyright (c) Microsoft Corporation.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
import type * as types from './types';
|
|
type PromiseOrValue<T> = T | Promise<T>;
|
|
export type LoopEvents = {
|
|
onBeforeTurn?: (params: {
|
|
conversation: types.Conversation;
|
|
totalUsage: types.Usage;
|
|
budgetTokens?: number;
|
|
}) => PromiseOrValue<void>;
|
|
onAfterTurn?: (params: {
|
|
assistantMessage: types.AssistantMessage;
|
|
totalUsage: types.Usage;
|
|
budgetTokens?: number;
|
|
}) => PromiseOrValue<void>;
|
|
onBeforeToolCall?: (params: {
|
|
assistantMessage: types.AssistantMessage;
|
|
toolCall: types.ToolCallContentPart;
|
|
}) => PromiseOrValue<'disallow' | void>;
|
|
onAfterToolCall?: (params: {
|
|
assistantMessage: types.AssistantMessage;
|
|
toolCall: types.ToolCallContentPart;
|
|
result: types.ToolResult;
|
|
}) => PromiseOrValue<'disallow' | void>;
|
|
onToolCallError?: (params: {
|
|
assistantMessage: types.AssistantMessage;
|
|
toolCall: types.ToolCallContentPart;
|
|
error: Error;
|
|
}) => PromiseOrValue<void>;
|
|
};
|
|
export type LoopOptions = types.CompletionOptions & LoopEvents & {
|
|
tools?: types.Tool[];
|
|
callTool?: types.ToolCallback;
|
|
maxTurns?: number;
|
|
maxToolCalls?: number;
|
|
maxToolCallRetries?: number;
|
|
cache?: types.ReplayCache;
|
|
cacheMode?: 'strict' | 'lax';
|
|
secrets?: Record<string, string>;
|
|
summarize?: boolean;
|
|
};
|
|
export declare class Loop {
|
|
private _provider;
|
|
private _loopOptions;
|
|
private _cacheOutput;
|
|
constructor(options: LoopOptions);
|
|
run(task: string, runOptions?: Omit<LoopOptions, 'model' | 'api' | 'apiKey'> & {
|
|
model?: string;
|
|
}): Promise<{
|
|
result?: types.ToolResult;
|
|
status: 'ok' | 'break' | 'error';
|
|
error?: string;
|
|
usage: types.Usage;
|
|
turns: number;
|
|
}>;
|
|
private _summarizeConversation;
|
|
cache(): types.ReplayCache;
|
|
}
|
|
export {};
|