@promptbook/remote-server 0.105.0-26 → 0.105.0-30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import { createOpenAiAssistantExecutionTools } from '../llm-providers/openai/cre
3
3
  import { createOpenAiCompatibleExecutionTools } from '../llm-providers/openai/createOpenAiCompatibleExecutionTools';
4
4
  import { createOpenAiExecutionTools } from '../llm-providers/openai/createOpenAiExecutionTools';
5
5
  import { OPENAI_MODELS } from '../llm-providers/openai/openai-models';
6
+ import { OpenAiAgentExecutionTools } from '../llm-providers/openai/OpenAiAgentExecutionTools';
6
7
  import { OpenAiAssistantExecutionTools } from '../llm-providers/openai/OpenAiAssistantExecutionTools';
7
8
  import type { OpenAiAssistantExecutionToolsOptions } from '../llm-providers/openai/OpenAiAssistantExecutionToolsOptions';
8
9
  import { OpenAiCompatibleExecutionTools } from '../llm-providers/openai/OpenAiCompatibleExecutionTools';
@@ -19,6 +20,7 @@ export { createOpenAiAssistantExecutionTools };
19
20
  export { createOpenAiCompatibleExecutionTools };
20
21
  export { createOpenAiExecutionTools };
21
22
  export { OPENAI_MODELS };
23
+ export { OpenAiAgentExecutionTools };
22
24
  export { OpenAiAssistantExecutionTools };
23
25
  export type { OpenAiAssistantExecutionToolsOptions };
24
26
  export { OpenAiCompatibleExecutionTools };
@@ -136,6 +136,7 @@ import type { AzureOpenAiExecutionToolsOptions } from '../llm-providers/azure-op
136
136
  import type { DeepseekExecutionToolsOptions } from '../llm-providers/deepseek/DeepseekExecutionToolsOptions';
137
137
  import type { GoogleExecutionToolsOptions } from '../llm-providers/google/GoogleExecutionToolsOptions';
138
138
  import type { OllamaExecutionToolsOptions } from '../llm-providers/ollama/OllamaExecutionToolsOptions';
139
+ import type { OpenAiAgentExecutionToolsOptions } from '../llm-providers/openai/OpenAiAgentExecutionTools';
139
140
  import type { OpenAiAssistantExecutionToolsOptions } from '../llm-providers/openai/OpenAiAssistantExecutionToolsOptions';
140
141
  import type { OpenAiCompatibleExecutionToolsOptions } from '../llm-providers/openai/OpenAiCompatibleExecutionToolsOptions';
141
142
  import type { OpenAiCompatibleExecutionToolsNonProxiedOptions } from '../llm-providers/openai/OpenAiCompatibleExecutionToolsOptions';
@@ -530,6 +531,7 @@ export type { AzureOpenAiExecutionToolsOptions };
530
531
  export type { DeepseekExecutionToolsOptions };
531
532
  export type { GoogleExecutionToolsOptions };
532
533
  export type { OllamaExecutionToolsOptions };
534
+ export type { OpenAiAgentExecutionToolsOptions };
533
535
  export type { OpenAiAssistantExecutionToolsOptions };
534
536
  export type { OpenAiCompatibleExecutionToolsOptions };
535
537
  export type { OpenAiCompatibleExecutionToolsNonProxiedOptions };
@@ -0,0 +1,11 @@
1
+ import { ChatParticipant } from '../types/ChatParticipant';
2
+ /**
3
+ * Resolves the URL for a citation source by looking up KNOWLEDGE commitments in the agent's source code.
4
+ *
5
+ * @param source - The source filename (e.g. "document.pdf")
6
+ * @param participants - List of chat participants to search in
7
+ * @returns The resolved URL if found, or null
8
+ *
9
+ * @private utility of <Chat/> component
10
+ */
11
+ export declare function resolveCitationUrl(source: string, participants: ReadonlyArray<ChatParticipant>): string | null;
@@ -14,7 +14,8 @@ import type { AgentOptions } from './AgentOptions';
14
14
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
15
15
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
16
16
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
17
- * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
17
+ * - `OpenAiAgentExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with agent capabilities (using Responses API), recommended for usage in `Agent` or `AgentLlmExecutionTools`
18
+ * - `OpenAiAssistantExecutionTools` - (Deprecated) which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities
18
19
  * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
19
20
  *
20
21
  * @public exported from `@promptbook/core`
@@ -16,7 +16,8 @@ import type { CreateAgentLlmExecutionToolsOptions } from './CreateAgentLlmExecut
16
16
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
17
17
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
18
18
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
19
- * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
19
+ * - `OpenAiAgentExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with agent capabilities (using Responses API), recommended for usage in `Agent` or `AgentLlmExecutionTools`
20
+ * - `OpenAiAssistantExecutionTools` - (Deprecated) which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities
20
21
  * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
21
22
  *
22
23
  * @public exported from `@promptbook/core`
@@ -27,6 +28,10 @@ export declare class AgentLlmExecutionTools implements LlmExecutionTools {
27
28
  * Cache of OpenAI assistants to avoid creating duplicates
28
29
  */
29
30
  private static assistantCache;
31
+ /**
32
+ * Cache of OpenAI vector stores to avoid creating duplicates
33
+ */
34
+ private static vectorStoreCache;
30
35
  /**
31
36
  * Cached model requirements to avoid re-parsing the agent source
32
37
  */
@@ -0,0 +1,43 @@
1
+ import OpenAI from 'openai';
2
+ import type { LlmExecutionTools } from '../../execution/LlmExecutionTools';
3
+ import type { ChatPromptResult } from '../../execution/PromptResult';
4
+ import type { Prompt } from '../../types/Prompt';
5
+ import type { string_markdown, string_markdown_text, string_title } from '../../types/typeAliases';
6
+ import type { OpenAiCompatibleExecutionToolsNonProxiedOptions } from './OpenAiCompatibleExecutionToolsOptions';
7
+ import { OpenAiExecutionTools } from './OpenAiExecutionTools';
8
+ /**
9
+ * Options for OpenAiAgentExecutionTools
10
+ */
11
+ export type OpenAiAgentExecutionToolsOptions = OpenAiCompatibleExecutionToolsNonProxiedOptions & {
12
+ /**
13
+ * ID of the vector store to use for file search
14
+ */
15
+ readonly vectorStoreId?: string;
16
+ };
17
+ /**
18
+ * Execution Tools for calling OpenAI API using the Responses API (Agents)
19
+ *
20
+ * @public exported from `@promptbook/openai`
21
+ */
22
+ export declare class OpenAiAgentExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
23
+ readonly vectorStoreId?: string;
24
+ constructor(options: OpenAiAgentExecutionToolsOptions);
25
+ get title(): string_title & string_markdown_text;
26
+ get description(): string_markdown;
27
+ /**
28
+ * Calls OpenAI API to use a chat model with streaming.
29
+ */
30
+ callChatModelStream(prompt: Prompt, onProgress: (chunk: ChatPromptResult) => void): Promise<ChatPromptResult>;
31
+ /**
32
+ * Creates a vector store from knowledge sources
33
+ */
34
+ static createVectorStore(client: OpenAI, name: string, knowledgeSources: ReadonlyArray<string>): Promise<string>;
35
+ /**
36
+ * Discriminant for type guards
37
+ */
38
+ protected get discriminant(): string;
39
+ /**
40
+ * Type guard to check if given `LlmExecutionTools` are instanceof `OpenAiAgentExecutionTools`
41
+ */
42
+ static isOpenAiAgentExecutionTools(llmExecutionTools: LlmExecutionTools): llmExecutionTools is OpenAiAgentExecutionTools;
43
+ }
@@ -18,6 +18,7 @@ import { OpenAiExecutionTools } from './OpenAiExecutionTools';
18
18
  * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
19
19
  *
20
20
  * @public exported from `@promptbook/openai`
21
+ * @deprecated Use `OpenAiAgentExecutionTools` instead which uses the new OpenAI Responses API
21
22
  */
22
23
  export declare class OpenAiAssistantExecutionTools extends OpenAiExecutionTools implements LlmExecutionTools {
23
24
  readonly assistantId: string_token;
@@ -73,7 +73,7 @@ export declare abstract class OpenAiCompatibleExecutionTools implements LlmExecu
73
73
  /**
74
74
  * Calls OpenAI compatible API to use a image generation model
75
75
  */
76
- callImageGenerationModel(prompt: Pick<Prompt, 'content' | 'parameters' | 'modelRequirements'>): Promise<ImagePromptResult>;
76
+ callImageGenerationModel(prompt: Prompt): Promise<ImagePromptResult>;
77
77
  /**
78
78
  * Internal method that handles parameter retry for image generation model calls
79
79
  */
@@ -129,6 +129,12 @@ export type CommonModelRequirements = {
129
129
  * Note: [🚉] This is fully serializable as JSON
130
130
  */
131
131
  readonly tools?: LlmToolDefinition[];
132
+ /**
133
+ * Optional list of knowledge source links that the model can use
134
+ *
135
+ * Note: [🚉] This is fully serializable as JSON
136
+ */
137
+ readonly knowledgeSources?: string[];
132
138
  };
133
139
  /**
134
140
  * TODO: [🧠][🈁] `seed` should maybe be somewhere else (not in `ModelRequirements`) (similar that `user` identification is not here)
@@ -72,6 +72,14 @@ export type ImagePrompt = CommonPrompt & {
72
72
  * Requirements for image generation model
73
73
  */
74
74
  modelRequirements: ImageGenerationModelRequirements;
75
+ /**
76
+ * Optional file attachments
77
+ */
78
+ attachments?: Array<{
79
+ name: string;
80
+ type: string;
81
+ url: string;
82
+ }>;
75
83
  };
76
84
  /**
77
85
  * Embedding prompt
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.105.0-25`).
18
+ * It follows semantic versioning (e.g., `0.105.0-28`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.105.0-26",
3
+ "version": "0.105.0-30",
4
4
  "description": "Promptbook: Turn your company's scattered knowledge into AI ready books",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -95,7 +95,7 @@
95
95
  "module": "./esm/index.es.js",
96
96
  "typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
97
97
  "peerDependencies": {
98
- "@promptbook/core": "0.105.0-26"
98
+ "@promptbook/core": "0.105.0-30"
99
99
  },
100
100
  "dependencies": {
101
101
  "@mozilla/readability": "0.6.0",
package/umd/index.umd.js CHANGED
@@ -50,7 +50,7 @@
50
50
  * @generated
51
51
  * @see https://github.com/webgptorg/promptbook
52
52
  */
53
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-26';
53
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-30';
54
54
  /**
55
55
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
56
56
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -19175,7 +19175,11 @@
19175
19175
  quality: currentModelRequirements.quality,
19176
19176
  style: currentModelRequirements.style,
19177
19177
  };
19178
- const rawPromptContent = templateParameters(content, { ...parameters, modelName });
19178
+ let rawPromptContent = templateParameters(content, { ...parameters, modelName });
19179
+ if ('attachments' in prompt && Array.isArray(prompt.attachments) && prompt.attachments.length > 0) {
19180
+ rawPromptContent +=
19181
+ '\n\n' + prompt.attachments.map((attachment) => `Image attachment: ${attachment.url}`).join('\n');
19182
+ }
19179
19183
  const rawRequest = {
19180
19184
  ...modelSettings,
19181
19185
  prompt: rawPromptContent,
@@ -19468,6 +19472,207 @@
19468
19472
  }
19469
19473
  }
19470
19474
 
19475
+ /**
19476
+ * Execution Tools for calling OpenAI API using the Responses API (Agents)
19477
+ *
19478
+ * @public exported from `@promptbook/openai`
19479
+ */
19480
+ class OpenAiAgentExecutionTools extends OpenAiExecutionTools {
19481
+ constructor(options) {
19482
+ super(options);
19483
+ this.vectorStoreId = options.vectorStoreId;
19484
+ }
19485
+ get title() {
19486
+ return 'OpenAI Agent';
19487
+ }
19488
+ get description() {
19489
+ return 'Use OpenAI Responses API (Agentic)';
19490
+ }
19491
+ /**
19492
+ * Calls OpenAI API to use a chat model with streaming.
19493
+ */
19494
+ async callChatModelStream(prompt, onProgress) {
19495
+ if (this.options.isVerbose) {
19496
+ console.info('💬 OpenAI Agent callChatModel call', { prompt });
19497
+ }
19498
+ const { content, parameters, modelRequirements } = prompt;
19499
+ const client = await this.getClient();
19500
+ if (modelRequirements.modelVariant !== 'CHAT') {
19501
+ throw new PipelineExecutionError('Use callChatModel only for CHAT variant');
19502
+ }
19503
+ const rawPromptContent = templateParameters(content, {
19504
+ ...parameters,
19505
+ modelName: 'agent',
19506
+ });
19507
+ // Build input items
19508
+ const input = []; // TODO: Type properly when OpenAI types are updated
19509
+ // Add previous messages from thread (if any)
19510
+ if ('thread' in prompt && Array.isArray(prompt.thread)) {
19511
+ const previousMessages = prompt.thread.map((msg) => ({
19512
+ role: msg.sender === 'assistant' ? 'assistant' : 'user',
19513
+ content: msg.content,
19514
+ }));
19515
+ input.push(...previousMessages);
19516
+ }
19517
+ // Add current user message
19518
+ input.push({
19519
+ role: 'user',
19520
+ content: rawPromptContent,
19521
+ });
19522
+ // Prepare tools
19523
+ const tools = modelRequirements.tools ? mapToolsToOpenAi(modelRequirements.tools) : undefined;
19524
+ // Add file_search if vector store is present
19525
+ const agentTools = tools ? [...tools] : [];
19526
+ let toolResources = undefined;
19527
+ if (this.vectorStoreId) {
19528
+ agentTools.push({ type: 'file_search' });
19529
+ toolResources = {
19530
+ file_search: {
19531
+ vector_store_ids: [this.vectorStoreId],
19532
+ },
19533
+ };
19534
+ }
19535
+ // Add file_search also if knowledgeSources are present in the prompt (passed via AgentLlmExecutionTools)
19536
+ if (modelRequirements.knowledgeSources &&
19537
+ modelRequirements.knowledgeSources.length > 0 &&
19538
+ !this.vectorStoreId) {
19539
+ // Note: Vector store should have been created by AgentLlmExecutionTools and passed via options.
19540
+ // If we are here, it means we have knowledge sources but no vector store ID.
19541
+ // We can't easily create one here without persisting it.
19542
+ console.warn('Knowledge sources provided but no vector store ID. Creating temporary vector store is not implemented in callChatModelStream.');
19543
+ }
19544
+ const start = $getCurrentDate();
19545
+ // Construct the request
19546
+ const rawRequest = {
19547
+ // TODO: Type properly as OpenAI.Responses.CreateResponseParams
19548
+ model: modelRequirements.modelName || 'gpt-4o',
19549
+ input,
19550
+ instructions: modelRequirements.systemMessage,
19551
+ tools: agentTools.length > 0 ? agentTools : undefined,
19552
+ tool_resources: toolResources,
19553
+ store: false, // Stateless by default as we pass full history
19554
+ };
19555
+ if (this.options.isVerbose) {
19556
+ console.info(colors__default["default"].bgWhite('rawRequest (Responses API)'), JSON.stringify(rawRequest, null, 4));
19557
+ }
19558
+ // Call Responses API
19559
+ // Note: Using any cast because types might not be updated yet
19560
+ const response = await client.responses.create(rawRequest);
19561
+ if (this.options.isVerbose) {
19562
+ console.info(colors__default["default"].bgWhite('rawResponse'), JSON.stringify(response, null, 4));
19563
+ }
19564
+ const complete = $getCurrentDate();
19565
+ let resultContent = '';
19566
+ const toolCalls = [];
19567
+ // Parse output items
19568
+ if (response.output) {
19569
+ for (const item of response.output) {
19570
+ if (item.type === 'message' && item.role === 'assistant') {
19571
+ for (const contentPart of item.content) {
19572
+ if (contentPart.type === 'output_text') {
19573
+ // "output_text" based on migration guide, or "text"? Guide says "output_text" in example.
19574
+ resultContent += contentPart.text;
19575
+ }
19576
+ else if (contentPart.type === 'text') {
19577
+ resultContent += contentPart.text.value || contentPart.text;
19578
+ }
19579
+ }
19580
+ }
19581
+ else if (item.type === 'function_call') ;
19582
+ }
19583
+ }
19584
+ // Use output_text helper if available (mentioned in guide)
19585
+ if (response.output_text) {
19586
+ resultContent = response.output_text;
19587
+ }
19588
+ // TODO: Handle tool calls properly (Requires clearer docs or experimentation)
19589
+ onProgress({
19590
+ content: resultContent,
19591
+ modelName: response.model || 'agent',
19592
+ timing: { start, complete },
19593
+ usage: UNCERTAIN_USAGE,
19594
+ rawPromptContent,
19595
+ rawRequest,
19596
+ rawResponse: response,
19597
+ });
19598
+ return exportJson({
19599
+ name: 'promptResult',
19600
+ message: `Result of \`OpenAiAgentExecutionTools.callChatModelStream\``,
19601
+ order: [],
19602
+ value: {
19603
+ content: resultContent,
19604
+ modelName: response.model || 'agent',
19605
+ timing: { start, complete },
19606
+ usage: UNCERTAIN_USAGE,
19607
+ rawPromptContent,
19608
+ rawRequest,
19609
+ rawResponse: response,
19610
+ toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
19611
+ },
19612
+ });
19613
+ }
19614
+ /**
19615
+ * Creates a vector store from knowledge sources
19616
+ */
19617
+ static async createVectorStore(client, name, knowledgeSources) {
19618
+ // Create a vector store
19619
+ const vectorStore = await client.beta.vectorStores.create({
19620
+ name: `${name} Knowledge Base`,
19621
+ });
19622
+ const vectorStoreId = vectorStore.id;
19623
+ // Upload files from knowledge sources to the vector store
19624
+ const fileStreams = [];
19625
+ for (const source of knowledgeSources) {
19626
+ try {
19627
+ // Check if it's a URL
19628
+ if (source.startsWith('http://') || source.startsWith('https://')) {
19629
+ // Download the file
19630
+ const response = await fetch(source);
19631
+ if (!response.ok) {
19632
+ console.error(`Failed to download ${source}: ${response.statusText}`);
19633
+ continue;
19634
+ }
19635
+ const buffer = await response.arrayBuffer();
19636
+ const filename = source.split('/').pop() || 'downloaded-file';
19637
+ const blob = new Blob([buffer]);
19638
+ const file = new File([blob], filename);
19639
+ fileStreams.push(file);
19640
+ }
19641
+ else {
19642
+ // Local files not supported in browser env easily, same as before
19643
+ }
19644
+ }
19645
+ catch (error) {
19646
+ console.error(`Error processing knowledge source ${source}:`, error);
19647
+ }
19648
+ }
19649
+ // Batch upload files to the vector store
19650
+ if (fileStreams.length > 0) {
19651
+ try {
19652
+ await client.beta.vectorStores.fileBatches.uploadAndPoll(vectorStoreId, {
19653
+ files: fileStreams,
19654
+ });
19655
+ }
19656
+ catch (error) {
19657
+ console.error('Error uploading files to vector store:', error);
19658
+ }
19659
+ }
19660
+ return vectorStoreId;
19661
+ }
19662
+ /**
19663
+ * Discriminant for type guards
19664
+ */
19665
+ get discriminant() {
19666
+ return 'OPEN_AI_AGENT';
19667
+ }
19668
+ /**
19669
+ * Type guard to check if given `LlmExecutionTools` are instanceof `OpenAiAgentExecutionTools`
19670
+ */
19671
+ static isOpenAiAgentExecutionTools(llmExecutionTools) {
19672
+ return llmExecutionTools.discriminant === 'OPEN_AI_AGENT';
19673
+ }
19674
+ }
19675
+
19471
19676
  /**
19472
19677
  * Uploads files to OpenAI and returns their IDs
19473
19678
  *
@@ -19502,6 +19707,7 @@
19502
19707
  * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
19503
19708
  *
19504
19709
  * @public exported from `@promptbook/openai`
19710
+ * @deprecated Use `OpenAiAgentExecutionTools` instead which uses the new OpenAI Responses API
19505
19711
  */
19506
19712
  class OpenAiAssistantExecutionTools extends OpenAiExecutionTools {
19507
19713
  /**
@@ -20142,7 +20348,8 @@
20142
20348
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
20143
20349
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
20144
20350
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
20145
- * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
20351
+ * - `OpenAiAgentExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with agent capabilities (using Responses API), recommended for usage in `Agent` or `AgentLlmExecutionTools`
20352
+ * - `OpenAiAssistantExecutionTools` - (Deprecated) which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities
20146
20353
  * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
20147
20354
  *
20148
20355
  * @public exported from `@promptbook/core`
@@ -20270,15 +20477,78 @@
20270
20477
  ...modelRequirements,
20271
20478
  // Spread tools to convert readonly array to mutable
20272
20479
  tools: modelRequirements.tools ? [...modelRequirements.tools] : chatPrompt.modelRequirements.tools,
20480
+ // Spread knowledgeSources to convert readonly array to mutable
20481
+ knowledgeSources: modelRequirements.knowledgeSources
20482
+ ? [...modelRequirements.knowledgeSources]
20483
+ : undefined,
20273
20484
  // Prepend agent system message to existing system message
20274
20485
  systemMessage: modelRequirements.systemMessage +
20275
20486
  (chatPrompt.modelRequirements.systemMessage
20276
20487
  ? `\n\n${chatPrompt.modelRequirements.systemMessage}`
20277
20488
  : ''),
20278
- },
20489
+ }, // Cast to avoid readonly mismatch from spread
20279
20490
  };
20280
20491
  console.log('!!!! promptWithAgentModelRequirements:', promptWithAgentModelRequirements);
20281
- if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
20492
+ if (OpenAiAgentExecutionTools.isOpenAiAgentExecutionTools(this.options.llmTools)) {
20493
+ const requirementsHash = cryptoJs.SHA256(JSON.stringify(modelRequirements)).toString();
20494
+ const cached = AgentLlmExecutionTools.vectorStoreCache.get(this.title);
20495
+ let agentTools;
20496
+ if (cached && cached.requirementsHash === requirementsHash) {
20497
+ if (this.options.isVerbose) {
20498
+ console.log(`1️⃣ Using cached OpenAI Agent Vector Store for agent ${this.title}...`);
20499
+ }
20500
+ // Create new instance with cached vectorStoreId
20501
+ // We need to access options from the original tool.
20502
+ // We assume isOpenAiAgentExecutionTools implies it has options we can clone.
20503
+ // But protected options are not accessible.
20504
+ // We can cast to access options if they were public, or use a method to clone.
20505
+ // OpenAiAgentExecutionTools doesn't have a clone method.
20506
+ // However, we can just assume the passed tool *might* not have the vector store yet, or we are replacing it.
20507
+ // Actually, if the passed tool IS OpenAiAgentExecutionTools, we should use it as a base.
20508
+ // TODO: [🧠] This is a bit hacky, accessing protected options or recreating tools.
20509
+ // Ideally OpenAiAgentExecutionTools should have a method `withVectorStoreId`.
20510
+ agentTools = new OpenAiAgentExecutionTools({
20511
+ ...this.options.llmTools.options,
20512
+ vectorStoreId: cached.vectorStoreId,
20513
+ });
20514
+ }
20515
+ else {
20516
+ if (this.options.isVerbose) {
20517
+ console.log(`1️⃣ Creating/Updating OpenAI Agent Vector Store for agent ${this.title}...`);
20518
+ }
20519
+ let vectorStoreId;
20520
+ if (modelRequirements.knowledgeSources && modelRequirements.knowledgeSources.length > 0) {
20521
+ const client = await this.options.llmTools.getClient();
20522
+ vectorStoreId = await OpenAiAgentExecutionTools.createVectorStore(client, this.title, modelRequirements.knowledgeSources);
20523
+ }
20524
+ if (vectorStoreId) {
20525
+ AgentLlmExecutionTools.vectorStoreCache.set(this.title, {
20526
+ vectorStoreId,
20527
+ requirementsHash,
20528
+ });
20529
+ }
20530
+ agentTools = new OpenAiAgentExecutionTools({
20531
+ ...this.options.llmTools.options,
20532
+ vectorStoreId,
20533
+ });
20534
+ }
20535
+ // Create modified chat prompt with agent system message specific to OpenAI Agent
20536
+ // Note: Unlike Assistants API, Responses API expects instructions (system message) to be passed in the call.
20537
+ // So we use promptWithAgentModelRequirements which has the system message prepended.
20538
+ // But we need to make sure we pass knowledgeSources in modelRequirements so OpenAiAgentExecutionTools can fallback to warning if vectorStoreId is missing (though we just handled it).
20539
+ const promptForAgent = {
20540
+ ...promptWithAgentModelRequirements,
20541
+ modelRequirements: {
20542
+ ...promptWithAgentModelRequirements.modelRequirements,
20543
+ knowledgeSources: modelRequirements.knowledgeSources
20544
+ ? [...modelRequirements.knowledgeSources]
20545
+ : undefined, // Pass knowledge sources explicitly
20546
+ },
20547
+ };
20548
+ underlyingLlmResult = await agentTools.callChatModelStream(promptForAgent, onProgress);
20549
+ }
20550
+ else if (OpenAiAssistantExecutionTools.isOpenAiAssistantExecutionTools(this.options.llmTools)) {
20551
+ // ... deprecated path ...
20282
20552
  const requirementsHash = cryptoJs.SHA256(JSON.stringify(modelRequirements)).toString();
20283
20553
  const cached = AgentLlmExecutionTools.assistantCache.get(this.title);
20284
20554
  let assistant;
@@ -20373,6 +20643,10 @@
20373
20643
  * Cache of OpenAI assistants to avoid creating duplicates
20374
20644
  */
20375
20645
  AgentLlmExecutionTools.assistantCache = new Map();
20646
+ /**
20647
+ * Cache of OpenAI vector stores to avoid creating duplicates
20648
+ */
20649
+ AgentLlmExecutionTools.vectorStoreCache = new Map();
20376
20650
  /**
20377
20651
  * TODO: [🍚] Implement Destroyable pattern to free resources
20378
20652
  * TODO: [🧠] Adding parameter substitution support (here or should be responsibility of the underlying LLM Tools)
@@ -20386,7 +20660,8 @@
20386
20660
  * - `Agent` - which represents an AI Agent with its source, memories, actions, etc. Agent is a higher-level abstraction which is internally using:
20387
20661
  * - `LlmExecutionTools` - which wraps one or more LLM models and provides an interface to execute them
20388
20662
  * - `AgentLlmExecutionTools` - which is a specific implementation of `LlmExecutionTools` that wraps another LlmExecutionTools and applies agent-specific system prompts and requirements
20389
- * - `OpenAiAssistantExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities, recommended for usage in `Agent` or `AgentLlmExecutionTools`
20663
+ * - `OpenAiAgentExecutionTools` - which is a specific implementation of `LlmExecutionTools` for OpenAI models with agent capabilities (using Responses API), recommended for usage in `Agent` or `AgentLlmExecutionTools`
20664
+ * - `OpenAiAssistantExecutionTools` - (Deprecated) which is a specific implementation of `LlmExecutionTools` for OpenAI models with assistant capabilities
20390
20665
  * - `RemoteAgent` - which is an `Agent` that connects to a Promptbook Agents Server
20391
20666
  *
20392
20667
  * @public exported from `@promptbook/core`