/** * The following code is modified based on * https://github.com/nanobrowser/nanobrowser/blob/master/chrome-extension/src/background/agent/agents/base.ts * * Apache-2.0 License * Copyright (c) 2024 alexchenzl * https://github.com/nanobrowser/nanobrowser/blob/master/LICENSE */ import type { z } from 'zod'; import type { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models'; import type { AgentContext, AgentOutput } from '../types'; import type { BasePrompt } from '../prompts/base'; import { type BaseMessage } from '@langchain/core/messages'; import type { Action } from '../actions/builder'; export type CallOptions = BaseChatModelCallOptions; export interface BaseAgentOptions { chatLLM: BaseChatModel; context: AgentContext; prompt: BasePrompt; } export interface ExtraAgentOptions { id?: string; toolCallingMethod?: string; callOptions?: Partial; } /** * Base class for all agents * @param T - The Zod schema for the model output * @param M - The type of the result field of the agent output */ export declare abstract class BaseAgent { protected id: string; protected chatLLM: BaseChatModel; protected prompt: BasePrompt; protected context: AgentContext; protected actions: Record; protected modelOutputSchema: T; protected toolCallingMethod: string | null; protected chatModelLibrary: string; protected modelName: string; protected withStructuredOutput: boolean; protected callOptions?: CallOptions; protected modelOutputToolName: string; ModelOutput: z.infer; constructor(modelOutputSchema: T, options: BaseAgentOptions, extraOptions?: Partial); private setModelNames; private setToolCallingMethod; private setWithStructuredOutput; protected removeThinkTags(text: string): string; invoke(inputMessages: BaseMessage[]): Promise; abstract execute(): Promise>; protected validateModelOutput(data: unknown): this['ModelOutput'] | undefined; protected addModelOutputToMemory(modelOutput: this['ModelOutput']): void; /** * Extract JSON from raw string model output, handling both plain JSON and code-block-wrapped JSON. * * some models not supporting tool calls well like deepseek-reasoner, so we need to extract the JSON from the output * @param content - The content of the model output * @returns The JSON object */ protected extractJsonFromModelOutput(content: string): unknown; } //# sourceMappingURL=base.d.ts.map