UNPKG

@promptbook/remote-client

Version:

Promptbook: Create persistent AI agents that turn your company's scattered knowledge into action

105 lines (104 loc) 4.97 kB
import type { Promisable } from 'type-fest'; import type { AgentModelRequirements } from '../../book-2.0/agent-source/AgentModelRequirements'; import type { string_book } from '../../book-2.0/agent-source/string_book'; import type { ChatParticipant } from '../../book-components/Chat/types/ChatParticipant'; import type { AvailableModel } from '../../execution/AvailableModel'; import type { CallChatModelStreamOptions, LlmExecutionTools } from '../../execution/LlmExecutionTools'; import type { ChatPromptResult } from '../../execution/PromptResult'; import type { Prompt } from '../../types/Prompt'; import type { string_markdown, string_markdown_text } from '../../types/string_markdown'; import type { string_model_name } from '../../types/string_model_name'; import type { string_title } from '../../types/string_title'; import type { CreateAgentLlmExecutionToolsOptions } from './CreateAgentLlmExecutionToolsOptions'; /** * Execution Tools for calling LLM models with a predefined agent "soul" * This wraps underlying LLM execution tools and applies agent-specific system prompts and requirements * * Note: [🦖] There are several different things in Promptbook: * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using: * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements * - `OpenAiAssistantExecutionTools` - (Deprecated) which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities * - `OpenAiAgentKitExecutionTools` - which is a specific implementation of `LlmExecutionTools` backed by OpenAI AgentKit * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server * * @public exported from `@promptbook/core` */ export declare class AgentLlmExecutionTools implements LlmExecutionTools { protected readonly options: CreateAgentLlmExecutionToolsOptions; /** * Cached model requirements to avoid re-parsing the agent source. */ private _cachedModelRequirements; /** * Cached parsed agent information. */ private _cachedAgentInfo; /** * Optional server-precomputed model requirements reused until the source changes. */ private precomputedModelRequirements; /** * Dedicated prompt preparation facade used before backend dispatch. */ private readonly promptPreparer; /** * Dedicated OpenAI AgentKit runner used when the wrapped tools support AgentKit preparation. */ private readonly agentKitRunner; /** * Dedicated OpenAI Assistant runner used when the wrapped tools use Assistants. */ private readonly openAiAssistantRunner; /** * Creates new AgentLlmExecutionTools. * * @param options - The underlying LLM tools and agent source configuration. */ constructor(options: CreateAgentLlmExecutionToolsOptions); /** * Updates the agent source and clears the cache. * * @param agentSource - The new agent source string. */ protected updateAgentSource(agentSource: string_book): void; /** * Returns cached or parsed agent information. */ private getAgentInfo; /** * Returns cached or compiled agent model requirements. * * Note: [🐤] This is named `getModelRequirements` *(not `getAgentModelRequirements`)* because in future these two will be united. */ getModelRequirements(): Promise<AgentModelRequirements>; get title(): string_title & string_markdown_text; get description(): string_markdown; get profile(): ChatParticipant | undefined; checkConfiguration(): Promisable<void>; /** * Returns a virtual model name representing the agent behavior. */ get modelName(): string_model_name; listModels(): Promisable<ReadonlyArray<AvailableModel>>; /** * Calls the chat model with agent-specific system prompt and requirements. */ callChatModel(prompt: Prompt): Promise<ChatPromptResult>; /** * Calls the chat model with agent-specific system prompt and requirements with streaming. */ callChatModelStream(prompt: Prompt, onProgress: (chunk: ChatPromptResult) => void, options?: CallChatModelStreamOptions): Promise<ChatPromptResult>; /** * Dispatches one prepared agent prompt to the correct underlying LLM backend. */ private callPreparedChatModelStream; /** * Runs one prepared prompt through generic LLM tools that do not need special assistant preparation. */ private callGenericChatModelStream; /** * Applies the final agent-level content normalization to the underlying LLM result. */ private finalizeAgentResult; }