UNPKG

@promptbook/remote-server

Version:

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

115 lines (114 loc) 4.77 kB
import { Agent as AgentFromKit } from '@openai/agents'; import type { CallChatModelStreamOptions, LlmExecutionTools } from '../../execution/LlmExecutionTools'; import type { ChatPromptResult } from '../../execution/PromptResult'; import type { ModelRequirements } from '../../types/ModelRequirements'; import type { Prompt } from '../../types/Prompt'; import type { string_markdown, string_markdown_text } from '../../types/string_markdown'; import type { string_title } from '../../types/string_title'; import type { OpenAiAgentKitExecutionToolsOptions } from './OpenAiAgentKitExecutionToolsOptions'; import { OpenAiAgentKitExecutionToolsOutputTypeMapper } from './OpenAiAgentKitExecutionToolsOutputTypeMapper'; import { OpenAiVectorStoreHandler } from './OpenAiVectorStoreHandler'; /** * Alias for OpenAI AgentKit agent to avoid naming confusion with Promptbook agents. */ type OpenAiAgentKitAgent = AgentFromKit; /** * Prepared AgentKit agent details. */ type OpenAiAgentKitPreparedAgent = { readonly agent: OpenAiAgentKitAgent; readonly vectorStoreId?: string; }; /** * AgentKit output type returned by the dedicated response-format mapper. */ type OpenAiAgentKitAgentOutputType = ReturnType<typeof OpenAiAgentKitExecutionToolsOutputTypeMapper.mapResponseFormatToAgentOutputType>; /** * Execution tools for OpenAI AgentKit (Agents SDK). * * @public exported from `@promptbook/openai` */ export declare class OpenAiAgentKitExecutionTools extends OpenAiVectorStoreHandler implements LlmExecutionTools { private preparedAgentKitAgent; private readonly agentKitModelName; private readonly inputBuilder; private readonly toolBuilder; /** * Creates OpenAI AgentKit execution tools. */ constructor(options: OpenAiAgentKitExecutionToolsOptions); get title(): string_title & string_markdown_text; get description(): string_markdown; /** * Calls OpenAI AgentKit with a chat prompt (non-streaming). */ callChatModel(prompt: Prompt): Promise<ChatPromptResult>; /** * Calls OpenAI AgentKit with a chat prompt (streaming). */ callChatModelStream(prompt: Prompt, onProgress: (chunk: ChatPromptResult) => void, options?: CallChatModelStreamOptions): Promise<ChatPromptResult>; /** * Returns a prepared AgentKit agent when the server wants to manage caching externally. */ getPreparedAgentKitAgent(): OpenAiAgentKitPreparedAgent | null; /** * Stores a prepared AgentKit agent for later reuse by external cache managers. */ setPreparedAgentKitAgent(preparedAgent: OpenAiAgentKitPreparedAgent): void; /** * Creates a new tools instance bound to a prepared AgentKit agent. */ getPreparedAgentTools(preparedAgent: OpenAiAgentKitPreparedAgent): OpenAiAgentKitExecutionTools; /** * Prepares an AgentKit agent with optional knowledge sources and tool definitions. */ prepareAgentKitAgent(options: { readonly name: string_title; readonly instructions: string_markdown; readonly knowledgeSources?: ReadonlyArray<string>; readonly tools?: ModelRequirements['tools']; readonly vectorStoreId?: string; readonly storeAsPrepared?: boolean; }): Promise<OpenAiAgentKitPreparedAgent>; /** * Runs a prepared AgentKit agent and streams results back to the caller. */ callChatModelStreamWithPreparedAgent(options: { readonly openAiAgentKitAgent: OpenAiAgentKitAgent; readonly prompt: Prompt; readonly rawPromptContent?: string; readonly onProgress: (chunk: ChatPromptResult & { isFinished?: boolean; }) => void; readonly responseFormatOutputType?: OpenAiAgentKitAgentOutputType; /** * Optional abort signal propagated from chat surfaces so stream generation can be cancelled. */ readonly signal?: AbortSignal; }): Promise<ChatPromptResult>; /** * Ensures the AgentKit SDK is wired to the OpenAI client and API key. */ private ensureAgentKitDefaults; /** * Builds the tool list for AgentKit while keeping the public facade small. */ private buildAgentKitTools; /** * Returns AgentKit-specific options. */ private get agentKitOptions(); /** * Formats raw prompt content with the AgentKit model injected. */ private templatePromptContent; /** * Discriminant for type guards. */ protected get discriminant(): string; /** * Type guard to check if given `LlmExecutionTools` are instanceof `OpenAiAgentKitExecutionTools`. */ static isOpenAiAgentKitExecutionTools(llmExecutionTools: LlmExecutionTools): llmExecutionTools is OpenAiAgentKitExecutionTools; } export {};