praisonai 1.3.5 → 1.4.0

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.
Files changed (157) hide show
  1. package/dist/agent/context.d.ts +6 -0
  2. package/dist/agent/context.js +24 -3
  3. package/dist/agent/enhanced.d.ts +6 -0
  4. package/dist/agent/enhanced.js +32 -6
  5. package/dist/agent/image.d.ts +6 -0
  6. package/dist/agent/image.js +28 -5
  7. package/dist/agent/prompt-expander.d.ts +3 -0
  8. package/dist/agent/prompt-expander.js +18 -3
  9. package/dist/agent/query-rewriter.d.ts +3 -0
  10. package/dist/agent/query-rewriter.js +18 -3
  11. package/dist/agent/research.d.ts +3 -0
  12. package/dist/agent/research.js +20 -4
  13. package/dist/agent/simple.d.ts +1 -1
  14. package/dist/agent/simple.js +3 -2
  15. package/dist/ai/agent-loop.d.ts +177 -0
  16. package/dist/ai/agent-loop.js +313 -0
  17. package/dist/ai/devtools.d.ts +74 -0
  18. package/dist/ai/devtools.js +216 -0
  19. package/dist/ai/embed.d.ts +71 -0
  20. package/dist/ai/embed.js +154 -0
  21. package/dist/ai/generate-image.d.ts +66 -0
  22. package/dist/ai/generate-image.js +138 -0
  23. package/dist/ai/generate-object.d.ts +132 -0
  24. package/dist/ai/generate-object.js +206 -0
  25. package/dist/ai/generate-text.d.ts +201 -0
  26. package/dist/ai/generate-text.js +253 -0
  27. package/dist/ai/index.d.ts +27 -0
  28. package/dist/ai/index.js +140 -0
  29. package/dist/ai/mcp.d.ts +181 -0
  30. package/dist/ai/mcp.js +234 -0
  31. package/dist/ai/middleware.d.ts +110 -0
  32. package/dist/ai/middleware.js +186 -0
  33. package/dist/ai/models.d.ts +67 -0
  34. package/dist/ai/models.js +249 -0
  35. package/dist/ai/multimodal.d.ts +125 -0
  36. package/dist/ai/multimodal.js +270 -0
  37. package/dist/ai/nextjs.d.ts +122 -0
  38. package/dist/ai/nextjs.js +218 -0
  39. package/dist/ai/server.d.ts +126 -0
  40. package/dist/ai/server.js +336 -0
  41. package/dist/ai/speech.d.ts +135 -0
  42. package/dist/ai/speech.js +296 -0
  43. package/dist/ai/telemetry.d.ts +162 -0
  44. package/dist/ai/telemetry.js +311 -0
  45. package/dist/ai/tool-approval.d.ts +225 -0
  46. package/dist/ai/tool-approval.js +407 -0
  47. package/dist/ai/tools.d.ts +93 -0
  48. package/dist/ai/tools.js +89 -0
  49. package/dist/ai/types.d.ts +47 -0
  50. package/dist/ai/types.js +5 -0
  51. package/dist/ai/ui-message.d.ts +218 -0
  52. package/dist/ai/ui-message.js +291 -0
  53. package/dist/auto/index.d.ts +6 -0
  54. package/dist/auto/index.js +24 -3
  55. package/dist/cli/commands/approval.d.ts +10 -0
  56. package/dist/cli/commands/approval.js +274 -0
  57. package/dist/cli/commands/chat.js +2 -2
  58. package/dist/cli/commands/observability.d.ts +7 -0
  59. package/dist/cli/commands/observability.js +202 -12
  60. package/dist/cli/commands/providers.d.ts +5 -2
  61. package/dist/cli/commands/providers.js +204 -5
  62. package/dist/cli/commands/tools.d.ts +11 -1
  63. package/dist/cli/commands/tools.js +450 -64
  64. package/dist/cli/output/errors.d.ts +1 -0
  65. package/dist/cli/output/errors.js +1 -0
  66. package/dist/cli/spec/cli-spec.js +17 -0
  67. package/dist/guardrails/llm-guardrail.d.ts +6 -0
  68. package/dist/guardrails/llm-guardrail.js +24 -3
  69. package/dist/index.d.ts +12 -1
  70. package/dist/index.js +233 -19
  71. package/dist/integrations/computer-use.d.ts +182 -0
  72. package/dist/integrations/computer-use.js +356 -0
  73. package/dist/integrations/postgres.d.ts +162 -0
  74. package/dist/integrations/postgres.js +396 -0
  75. package/dist/integrations/slack.d.ts +145 -0
  76. package/dist/integrations/slack.js +270 -0
  77. package/dist/llm/providers/ai-sdk/types.d.ts +49 -3
  78. package/dist/llm/providers/ai-sdk/types.js +169 -15
  79. package/dist/observability/adapters/console.d.ts +33 -0
  80. package/dist/observability/adapters/console.js +71 -0
  81. package/dist/observability/adapters/external/arize.d.ts +20 -0
  82. package/dist/observability/adapters/external/arize.js +22 -0
  83. package/dist/observability/adapters/external/axiom.d.ts +20 -0
  84. package/dist/observability/adapters/external/axiom.js +22 -0
  85. package/dist/observability/adapters/external/braintrust.d.ts +20 -0
  86. package/dist/observability/adapters/external/braintrust.js +22 -0
  87. package/dist/observability/adapters/external/helicone.d.ts +20 -0
  88. package/dist/observability/adapters/external/helicone.js +22 -0
  89. package/dist/observability/adapters/external/laminar.d.ts +20 -0
  90. package/dist/observability/adapters/external/laminar.js +22 -0
  91. package/dist/observability/adapters/external/langfuse.d.ts +28 -0
  92. package/dist/observability/adapters/external/langfuse.js +186 -0
  93. package/dist/observability/adapters/external/langsmith.d.ts +21 -0
  94. package/dist/observability/adapters/external/langsmith.js +83 -0
  95. package/dist/observability/adapters/external/langwatch.d.ts +20 -0
  96. package/dist/observability/adapters/external/langwatch.js +22 -0
  97. package/dist/observability/adapters/external/maxim.d.ts +20 -0
  98. package/dist/observability/adapters/external/maxim.js +22 -0
  99. package/dist/observability/adapters/external/patronus.d.ts +20 -0
  100. package/dist/observability/adapters/external/patronus.js +22 -0
  101. package/dist/observability/adapters/external/scorecard.d.ts +20 -0
  102. package/dist/observability/adapters/external/scorecard.js +22 -0
  103. package/dist/observability/adapters/external/signoz.d.ts +20 -0
  104. package/dist/observability/adapters/external/signoz.js +22 -0
  105. package/dist/observability/adapters/external/traceloop.d.ts +20 -0
  106. package/dist/observability/adapters/external/traceloop.js +22 -0
  107. package/dist/observability/adapters/external/weave.d.ts +20 -0
  108. package/dist/observability/adapters/external/weave.js +22 -0
  109. package/dist/observability/adapters/index.d.ts +19 -0
  110. package/dist/observability/adapters/index.js +289 -0
  111. package/dist/observability/adapters/memory.d.ts +41 -0
  112. package/dist/observability/adapters/memory.js +190 -0
  113. package/dist/observability/adapters/noop.d.ts +25 -0
  114. package/dist/observability/adapters/noop.js +64 -0
  115. package/dist/observability/index.d.ts +39 -78
  116. package/dist/observability/index.js +99 -150
  117. package/dist/observability/types.d.ts +165 -0
  118. package/dist/observability/types.js +165 -0
  119. package/dist/tools/builtins/airweave.d.ts +32 -0
  120. package/dist/tools/builtins/airweave.js +119 -0
  121. package/dist/tools/builtins/bedrock-agentcore.d.ts +62 -0
  122. package/dist/tools/builtins/bedrock-agentcore.js +233 -0
  123. package/dist/tools/builtins/code-execution.d.ts +36 -0
  124. package/dist/tools/builtins/code-execution.js +136 -0
  125. package/dist/tools/builtins/code-mode.d.ts +54 -0
  126. package/dist/tools/builtins/code-mode.js +167 -0
  127. package/dist/tools/builtins/custom.d.ts +42 -0
  128. package/dist/tools/builtins/custom.js +195 -0
  129. package/dist/tools/builtins/exa.d.ts +53 -0
  130. package/dist/tools/builtins/exa.js +112 -0
  131. package/dist/tools/builtins/firecrawl.d.ts +56 -0
  132. package/dist/tools/builtins/firecrawl.js +158 -0
  133. package/dist/tools/builtins/index.d.ts +45 -0
  134. package/dist/tools/builtins/index.js +180 -0
  135. package/dist/tools/builtins/parallel.d.ts +30 -0
  136. package/dist/tools/builtins/parallel.js +113 -0
  137. package/dist/tools/builtins/perplexity.d.ts +32 -0
  138. package/dist/tools/builtins/perplexity.js +113 -0
  139. package/dist/tools/builtins/superagent.d.ts +66 -0
  140. package/dist/tools/builtins/superagent.js +187 -0
  141. package/dist/tools/builtins/tavily.d.ts +99 -0
  142. package/dist/tools/builtins/tavily.js +285 -0
  143. package/dist/tools/builtins/valyu.d.ts +65 -0
  144. package/dist/tools/builtins/valyu.js +193 -0
  145. package/dist/tools/index.d.ts +4 -0
  146. package/dist/tools/index.js +10 -2
  147. package/dist/tools/registry/index.d.ts +9 -0
  148. package/dist/tools/registry/index.js +28 -0
  149. package/dist/tools/registry/middleware.d.ts +43 -0
  150. package/dist/tools/registry/middleware.js +220 -0
  151. package/dist/tools/registry/registry.d.ts +92 -0
  152. package/dist/tools/registry/registry.js +280 -0
  153. package/dist/tools/registry/types.d.ts +217 -0
  154. package/dist/tools/registry/types.js +49 -0
  155. package/dist/tools/tools.d.ts +74 -0
  156. package/dist/tools/tools.js +133 -0
  157. package/package.json +4 -1
@@ -24,12 +24,18 @@ export declare class ContextAgent {
24
24
  readonly name: string;
25
25
  readonly instructions: string;
26
26
  private provider;
27
+ private providerPromise;
28
+ private llmModel;
27
29
  private knowledgeBase?;
28
30
  private contextWindow;
29
31
  private maxContextTokens;
30
32
  private messages;
31
33
  private verbose;
32
34
  constructor(config: ContextAgentConfig);
35
+ /**
36
+ * Get the LLM provider (lazy initialization with AI SDK backend)
37
+ */
38
+ private getProvider;
33
39
  /**
34
40
  * Chat with context awareness
35
41
  */
@@ -5,21 +5,41 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ContextAgent = void 0;
7
7
  exports.createContextAgent = createContextAgent;
8
- const providers_1 = require("../llm/providers");
8
+ const backend_resolver_1 = require("../llm/backend-resolver");
9
9
  /**
10
10
  * Context Agent - Agent with RAG and context management
11
11
  */
12
12
  class ContextAgent {
13
13
  constructor(config) {
14
+ this.provider = null;
15
+ this.providerPromise = null;
14
16
  this.messages = [];
15
17
  this.name = config.name || `ContextAgent_${Math.random().toString(36).substr(2, 9)}`;
16
18
  this.instructions = config.instructions;
17
- this.provider = (0, providers_1.createProvider)(config.llm || 'gpt-4o-mini');
19
+ this.llmModel = config.llm || 'openai/gpt-4o-mini';
18
20
  this.knowledgeBase = config.knowledgeBase;
19
21
  this.contextWindow = config.contextWindow ?? 10;
20
22
  this.maxContextTokens = config.maxContextTokens ?? 4000;
21
23
  this.verbose = config.verbose ?? false;
22
24
  }
25
+ /**
26
+ * Get the LLM provider (lazy initialization with AI SDK backend)
27
+ */
28
+ async getProvider() {
29
+ if (this.provider) {
30
+ return this.provider;
31
+ }
32
+ if (!this.providerPromise) {
33
+ this.providerPromise = (async () => {
34
+ const result = await (0, backend_resolver_1.resolveBackend)(this.llmModel, {
35
+ attribution: { agentId: this.name },
36
+ });
37
+ this.provider = result.provider;
38
+ return result.provider;
39
+ })();
40
+ }
41
+ return this.providerPromise;
42
+ }
23
43
  /**
24
44
  * Chat with context awareness
25
45
  */
@@ -51,7 +71,8 @@ class ContextAgent {
51
71
  ...this.getRecentMessages()
52
72
  ];
53
73
  // Generate response
54
- const result = await this.provider.generateText({ messages });
74
+ const provider = await this.getProvider();
75
+ const result = await provider.generateText({ messages });
55
76
  // Add assistant message
56
77
  this.messages.push({
57
78
  role: 'assistant',
@@ -50,6 +50,8 @@ export declare class EnhancedAgent {
50
50
  readonly instructions: string;
51
51
  readonly sessionId: string;
52
52
  private provider;
53
+ private providerPromise;
54
+ private llmModel;
53
55
  private session;
54
56
  private toolRegistry;
55
57
  private verbose;
@@ -59,6 +61,10 @@ export declare class EnhancedAgent {
59
61
  private maxTokens?;
60
62
  private outputSchema?;
61
63
  constructor(config: EnhancedAgentConfig);
64
+ /**
65
+ * Get the LLM provider (lazy initialization with AI SDK backend)
66
+ */
67
+ private getProvider;
62
68
  private registerTools;
63
69
  /**
64
70
  * Add a tool to the agent
@@ -4,7 +4,7 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.EnhancedAgent = void 0;
7
- const providers_1 = require("../llm/providers");
7
+ const backend_resolver_1 = require("../llm/backend-resolver");
8
8
  const session_1 = require("../session");
9
9
  const decorator_1 = require("../tools/decorator");
10
10
  const logger_1 = require("../utils/logger");
@@ -13,6 +13,8 @@ const logger_1 = require("../utils/logger");
13
13
  */
14
14
  class EnhancedAgent {
15
15
  constructor(config) {
16
+ this.provider = null;
17
+ this.providerPromise = null;
16
18
  this.name = config.name || `Agent_${Math.random().toString(36).substr(2, 9)}`;
17
19
  this.instructions = config.instructions;
18
20
  this.verbose = config.verbose ?? true;
@@ -21,8 +23,8 @@ class EnhancedAgent {
21
23
  this.temperature = config.temperature ?? 0.7;
22
24
  this.maxTokens = config.maxTokens;
23
25
  this.outputSchema = config.outputSchema;
24
- // Initialize provider
25
- this.provider = (0, providers_1.createProvider)(config.llm || 'gpt-4o-mini');
26
+ // Store model string for lazy provider initialization
27
+ this.llmModel = config.llm || 'openai/gpt-4o-mini';
26
28
  // Initialize session
27
29
  if (config.session) {
28
30
  this.session = config.session;
@@ -41,6 +43,27 @@ class EnhancedAgent {
41
43
  }
42
44
  logger_1.Logger.setVerbose(this.verbose);
43
45
  }
46
+ /**
47
+ * Get the LLM provider (lazy initialization with AI SDK backend)
48
+ */
49
+ async getProvider() {
50
+ if (this.provider) {
51
+ return this.provider;
52
+ }
53
+ if (!this.providerPromise) {
54
+ this.providerPromise = (async () => {
55
+ const result = await (0, backend_resolver_1.resolveBackend)(this.llmModel, {
56
+ attribution: {
57
+ agentId: this.name,
58
+ sessionId: this.sessionId,
59
+ },
60
+ });
61
+ this.provider = result.provider;
62
+ return result.provider;
63
+ })();
64
+ }
65
+ return this.providerPromise;
66
+ }
44
67
  registerTools(tools) {
45
68
  if (!tools)
46
69
  return;
@@ -118,7 +141,8 @@ class EnhancedAgent {
118
141
  iterations++;
119
142
  if (options.stream && !tools && options.onToken) {
120
143
  // Streaming without tools
121
- const stream = await this.provider.streamText({
144
+ const provider = await this.getProvider();
145
+ const stream = await provider.streamText({
122
146
  messages,
123
147
  temperature: options.temperature ?? this.temperature,
124
148
  maxTokens: options.maxTokens ?? this.maxTokens,
@@ -140,7 +164,8 @@ class EnhancedAgent {
140
164
  }
141
165
  else if (options.outputSchema) {
142
166
  // Structured output
143
- const objResult = await this.provider.generateObject({
167
+ const provider = await this.getProvider();
168
+ const objResult = await provider.generateObject({
144
169
  messages,
145
170
  schema: options.outputSchema ?? this.outputSchema,
146
171
  temperature: options.temperature ?? this.temperature,
@@ -156,7 +181,8 @@ class EnhancedAgent {
156
181
  }
157
182
  else {
158
183
  // Regular generation with potential tool calls
159
- result = await this.provider.generateText({
184
+ const provider = await this.getProvider();
185
+ result = await provider.generateText({
160
186
  messages,
161
187
  temperature: options.temperature ?? this.temperature,
162
188
  maxTokens: options.maxTokens ?? this.maxTokens,
@@ -25,9 +25,15 @@ export interface ImageAgentConfig {
25
25
  export declare class ImageAgent {
26
26
  readonly name: string;
27
27
  private provider;
28
+ private providerPromise;
29
+ private llmModel;
28
30
  private imageModel;
29
31
  private verbose;
30
32
  constructor(config?: ImageAgentConfig);
33
+ /**
34
+ * Get the LLM provider (lazy initialization with AI SDK backend)
35
+ */
36
+ private getProvider;
31
37
  /**
32
38
  * Analyze an image
33
39
  */
@@ -5,17 +5,37 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ImageAgent = void 0;
7
7
  exports.createImageAgent = createImageAgent;
8
- const providers_1 = require("../llm/providers");
8
+ const backend_resolver_1 = require("../llm/backend-resolver");
9
9
  /**
10
10
  * ImageAgent - Agent for image generation and analysis
11
11
  */
12
12
  class ImageAgent {
13
13
  constructor(config = {}) {
14
+ this.provider = null;
15
+ this.providerPromise = null;
14
16
  this.name = config.name || `ImageAgent_${Math.random().toString(36).substr(2, 9)}`;
15
- this.provider = (0, providers_1.createProvider)(config.llm || 'openai/gpt-4o-mini');
17
+ this.llmModel = config.llm || 'openai/gpt-4o-mini';
16
18
  this.imageModel = config.imageModel || 'dall-e-3';
17
19
  this.verbose = config.verbose ?? false;
18
20
  }
21
+ /**
22
+ * Get the LLM provider (lazy initialization with AI SDK backend)
23
+ */
24
+ async getProvider() {
25
+ if (this.provider) {
26
+ return this.provider;
27
+ }
28
+ if (!this.providerPromise) {
29
+ this.providerPromise = (async () => {
30
+ const result = await (0, backend_resolver_1.resolveBackend)(this.llmModel, {
31
+ attribution: { agentId: this.name },
32
+ });
33
+ this.provider = result.provider;
34
+ return result.provider;
35
+ })();
36
+ }
37
+ return this.providerPromise;
38
+ }
19
39
  /**
20
40
  * Analyze an image
21
41
  */
@@ -36,7 +56,8 @@ class ImageAgent {
36
56
  ]
37
57
  }
38
58
  ];
39
- const result = await this.provider.generateText({ messages });
59
+ const provider = await this.getProvider();
60
+ const result = await provider.generateText({ messages });
40
61
  if (this.verbose) {
41
62
  console.log(`[ImageAgent] Analysis: ${result.text.substring(0, 100)}...`);
42
63
  }
@@ -60,7 +81,8 @@ class ImageAgent {
60
81
  if (imageUrl) {
61
82
  return this.analyze({ imageUrl, prompt });
62
83
  }
63
- const result = await this.provider.generateText({
84
+ const provider = await this.getProvider();
85
+ const result = await provider.generateText({
64
86
  messages: [{ role: 'user', content: prompt }]
65
87
  });
66
88
  return result.text;
@@ -80,7 +102,8 @@ class ImageAgent {
80
102
  ]
81
103
  }
82
104
  ];
83
- const result = await this.provider.generateText({ messages });
105
+ const provider = await this.getProvider();
106
+ const result = await provider.generateText({ messages });
84
107
  return result.text;
85
108
  }
86
109
  }
@@ -20,9 +20,12 @@ export interface PromptExpanderConfig {
20
20
  export declare class PromptExpanderAgent {
21
21
  readonly name: string;
22
22
  private provider;
23
+ private providerPromise;
24
+ private llmModel;
23
25
  private defaultStrategy;
24
26
  private verbose;
25
27
  constructor(config?: PromptExpanderConfig);
28
+ private getProvider;
26
29
  /**
27
30
  * Expand a prompt
28
31
  */
@@ -5,17 +5,31 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PromptExpanderAgent = void 0;
7
7
  exports.createPromptExpanderAgent = createPromptExpanderAgent;
8
- const providers_1 = require("../llm/providers");
8
+ const backend_resolver_1 = require("../llm/backend-resolver");
9
9
  /**
10
10
  * PromptExpanderAgent - Expand prompts with more detail and context
11
11
  */
12
12
  class PromptExpanderAgent {
13
13
  constructor(config = {}) {
14
+ this.provider = null;
15
+ this.providerPromise = null;
14
16
  this.name = config.name || `PromptExpander_${Math.random().toString(36).substr(2, 9)}`;
15
- this.provider = (0, providers_1.createProvider)(config.llm || 'openai/gpt-4o-mini');
17
+ this.llmModel = config.llm || 'openai/gpt-4o-mini';
16
18
  this.defaultStrategy = config.defaultStrategy || 'auto';
17
19
  this.verbose = config.verbose ?? false;
18
20
  }
21
+ async getProvider() {
22
+ if (this.provider)
23
+ return this.provider;
24
+ if (!this.providerPromise) {
25
+ this.providerPromise = (async () => {
26
+ const result = await (0, backend_resolver_1.resolveBackend)(this.llmModel, { attribution: { agentId: this.name } });
27
+ this.provider = result.provider;
28
+ return result.provider;
29
+ })();
30
+ }
31
+ return this.providerPromise;
32
+ }
19
33
  /**
20
34
  * Expand a prompt
21
35
  */
@@ -23,7 +37,8 @@ class PromptExpanderAgent {
23
37
  const useStrategy = strategy || this.defaultStrategy;
24
38
  const actualStrategy = useStrategy === 'auto' ? this.detectStrategy(prompt) : useStrategy;
25
39
  const systemPrompt = this.getSystemPrompt(actualStrategy);
26
- const result = await this.provider.generateText({
40
+ const provider = await this.getProvider();
41
+ const result = await provider.generateText({
27
42
  messages: [
28
43
  { role: 'system', content: systemPrompt },
29
44
  { role: 'user', content: `Expand this prompt: ${prompt}` }
@@ -20,9 +20,12 @@ export interface QueryRewriterConfig {
20
20
  export declare class QueryRewriterAgent {
21
21
  readonly name: string;
22
22
  private provider;
23
+ private providerPromise;
24
+ private llmModel;
23
25
  private defaultStrategy;
24
26
  private verbose;
25
27
  constructor(config?: QueryRewriterConfig);
28
+ private getProvider;
26
29
  /**
27
30
  * Rewrite a query
28
31
  */
@@ -5,17 +5,31 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.QueryRewriterAgent = void 0;
7
7
  exports.createQueryRewriterAgent = createQueryRewriterAgent;
8
- const providers_1 = require("../llm/providers");
8
+ const backend_resolver_1 = require("../llm/backend-resolver");
9
9
  /**
10
10
  * QueryRewriterAgent - Optimize and rewrite queries
11
11
  */
12
12
  class QueryRewriterAgent {
13
13
  constructor(config = {}) {
14
+ this.provider = null;
15
+ this.providerPromise = null;
14
16
  this.name = config.name || `QueryRewriter_${Math.random().toString(36).substr(2, 9)}`;
15
- this.provider = (0, providers_1.createProvider)(config.llm || 'openai/gpt-4o-mini');
17
+ this.llmModel = config.llm || 'openai/gpt-4o-mini';
16
18
  this.defaultStrategy = config.defaultStrategy || 'auto';
17
19
  this.verbose = config.verbose ?? false;
18
20
  }
21
+ async getProvider() {
22
+ if (this.provider)
23
+ return this.provider;
24
+ if (!this.providerPromise) {
25
+ this.providerPromise = (async () => {
26
+ const result = await (0, backend_resolver_1.resolveBackend)(this.llmModel, { attribution: { agentId: this.name } });
27
+ this.provider = result.provider;
28
+ return result.provider;
29
+ })();
30
+ }
31
+ return this.providerPromise;
32
+ }
19
33
  /**
20
34
  * Rewrite a query
21
35
  */
@@ -23,7 +37,8 @@ class QueryRewriterAgent {
23
37
  const useStrategy = strategy || this.defaultStrategy;
24
38
  const actualStrategy = useStrategy === 'auto' ? this.detectStrategy(query) : useStrategy;
25
39
  const prompt = this.buildPrompt(query, actualStrategy);
26
- const result = await this.provider.generateText({
40
+ const provider = await this.getProvider();
41
+ const result = await provider.generateText({
27
42
  messages: [
28
43
  { role: 'system', content: this.getSystemPrompt(actualStrategy) },
29
44
  { role: 'user', content: prompt }
@@ -31,10 +31,13 @@ export interface DeepResearchConfig {
31
31
  export declare class DeepResearchAgent {
32
32
  readonly name: string;
33
33
  private provider;
34
+ private providerPromise;
35
+ private llmModel;
34
36
  private maxIterations;
35
37
  private searchTool?;
36
38
  private verbose;
37
39
  constructor(config?: DeepResearchConfig);
40
+ private getProvider;
38
41
  /**
39
42
  * Conduct deep research on a topic
40
43
  */
@@ -5,18 +5,32 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DeepResearchAgent = void 0;
7
7
  exports.createDeepResearchAgent = createDeepResearchAgent;
8
- const providers_1 = require("../llm/providers");
8
+ const backend_resolver_1 = require("../llm/backend-resolver");
9
9
  /**
10
10
  * DeepResearchAgent - Comprehensive research with citations
11
11
  */
12
12
  class DeepResearchAgent {
13
13
  constructor(config = {}) {
14
+ this.provider = null;
15
+ this.providerPromise = null;
14
16
  this.name = config.name || `ResearchAgent_${Math.random().toString(36).substr(2, 9)}`;
15
- this.provider = (0, providers_1.createProvider)(config.llm || 'openai/gpt-4o-mini');
17
+ this.llmModel = config.llm || 'openai/gpt-4o-mini';
16
18
  this.maxIterations = config.maxIterations ?? 5;
17
19
  this.searchTool = config.searchTool;
18
20
  this.verbose = config.verbose ?? false;
19
21
  }
22
+ async getProvider() {
23
+ if (this.provider)
24
+ return this.provider;
25
+ if (!this.providerPromise) {
26
+ this.providerPromise = (async () => {
27
+ const result = await (0, backend_resolver_1.resolveBackend)(this.llmModel, { attribution: { agentId: this.name } });
28
+ this.provider = result.provider;
29
+ return result.provider;
30
+ })();
31
+ }
32
+ return this.providerPromise;
33
+ }
20
34
  /**
21
35
  * Conduct deep research on a topic
22
36
  */
@@ -76,7 +90,8 @@ class DeepResearchAgent {
76
90
  };
77
91
  }
78
92
  async generateSearchQueries(query) {
79
- const result = await this.provider.generateText({
93
+ const provider = await this.getProvider();
94
+ const result = await provider.generateText({
80
95
  messages: [
81
96
  {
82
97
  role: 'system',
@@ -91,7 +106,8 @@ class DeepResearchAgent {
91
106
  const context = citations.length > 0
92
107
  ? `\n\nRelevant sources:\n${citations.map(c => `- ${c.title}: ${c.snippet || ''}`).join('\n')}`
93
108
  : '';
94
- const result = await this.provider.generateText({
109
+ const provider = await this.getProvider();
110
+ const result = await provider.generateText({
95
111
  messages: [
96
112
  {
97
113
  role: 'system',
@@ -115,7 +115,7 @@ export declare class Agent {
115
115
  private _useAISDKBackend;
116
116
  constructor(config: SimpleAgentConfig);
117
117
  /**
118
- * Generate a session ID based on current hour and agent name (like Python SDK)
118
+ * Generate a unique session ID based on current hour, agent name, and random suffix
119
119
  */
120
120
  private generateSessionId;
121
121
  /**
@@ -139,13 +139,14 @@ class Agent {
139
139
  }
140
140
  }
141
141
  /**
142
- * Generate a session ID based on current hour and agent name (like Python SDK)
142
+ * Generate a unique session ID based on current hour, agent name, and random suffix
143
143
  */
144
144
  generateSessionId() {
145
145
  const now = new Date();
146
146
  const hourStr = now.toISOString().slice(0, 13).replace(/[-T:]/g, '');
147
147
  const hash = this.name ? this.name.slice(0, 6) : 'agent';
148
- return `${hourStr}-${hash}`;
148
+ const randomSuffix = (0, crypto_1.randomUUID)().slice(0, 8);
149
+ return `${hourStr}-${hash}-${randomSuffix}`;
149
150
  }
150
151
  /**
151
152
  * Initialize DB session - restore history on first chat (lazy)
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Agent Loop - Manual Agent Loop Control
3
+ *
4
+ * Provides utilities for manual control of agent execution loops.
5
+ */
6
+ import type { Message } from './types';
7
+ export interface AgentLoopConfig {
8
+ /** Model to use */
9
+ model: string;
10
+ /** System prompt */
11
+ system?: string;
12
+ /** Available tools */
13
+ tools?: Record<string, AgentTool>;
14
+ /** Maximum steps (default: 10) */
15
+ maxSteps?: number;
16
+ /** Stop condition */
17
+ stopWhen?: StopCondition;
18
+ /** On step finish callback */
19
+ onStepFinish?: (step: AgentStep) => void | Promise<void>;
20
+ /** On tool call callback (for approval) */
21
+ onToolCall?: (toolCall: ToolCallInfo) => Promise<boolean>;
22
+ }
23
+ export interface AgentTool {
24
+ description: string;
25
+ parameters: any;
26
+ execute: (args: any) => Promise<any>;
27
+ }
28
+ export interface AgentStep {
29
+ stepNumber: number;
30
+ text: string;
31
+ toolCalls: ToolCallInfo[];
32
+ toolResults: ToolResultInfo[];
33
+ usage: {
34
+ promptTokens: number;
35
+ completionTokens: number;
36
+ totalTokens: number;
37
+ };
38
+ finishReason: string;
39
+ }
40
+ export interface ToolCallInfo {
41
+ toolCallId: string;
42
+ toolName: string;
43
+ args: any;
44
+ }
45
+ export interface ToolResultInfo {
46
+ toolCallId: string;
47
+ toolName: string;
48
+ result: any;
49
+ isError?: boolean;
50
+ }
51
+ export type StopCondition = {
52
+ type: 'stepCount';
53
+ count: number;
54
+ } | {
55
+ type: 'noToolCalls';
56
+ } | {
57
+ type: 'custom';
58
+ check: (step: AgentStep) => boolean;
59
+ };
60
+ export interface AgentLoopResult {
61
+ text: string;
62
+ steps: AgentStep[];
63
+ totalUsage: {
64
+ promptTokens: number;
65
+ completionTokens: number;
66
+ totalTokens: number;
67
+ };
68
+ finishReason: string;
69
+ }
70
+ /**
71
+ * Create a manual agent loop for fine-grained control.
72
+ *
73
+ * @example Basic usage
74
+ * ```typescript
75
+ * const loop = createAgentLoop({
76
+ * model: 'gpt-4o',
77
+ * system: 'You are a helpful assistant',
78
+ * tools: {
79
+ * search: {
80
+ * description: 'Search the web',
81
+ * parameters: z.object({ query: z.string() }),
82
+ * execute: async ({ query }) => searchWeb(query)
83
+ * }
84
+ * },
85
+ * maxSteps: 5
86
+ * });
87
+ *
88
+ * const result = await loop.run('Find information about AI');
89
+ * ```
90
+ *
91
+ * @example With approval
92
+ * ```typescript
93
+ * const loop = createAgentLoop({
94
+ * model: 'gpt-4o',
95
+ * tools: { ... },
96
+ * onToolCall: async (toolCall) => {
97
+ * const approved = await askUserForApproval(toolCall);
98
+ * return approved;
99
+ * }
100
+ * });
101
+ * ```
102
+ *
103
+ * @example Step-by-step control
104
+ * ```typescript
105
+ * const loop = createAgentLoop({ model: 'gpt-4o', tools: { ... } });
106
+ *
107
+ * // Initialize with a prompt
108
+ * loop.addMessage({ role: 'user', content: 'Hello' });
109
+ *
110
+ * // Run one step at a time
111
+ * while (!loop.isComplete()) {
112
+ * const step = await loop.step();
113
+ * console.log('Step:', step);
114
+ *
115
+ * // Optionally modify messages or tools between steps
116
+ * if (needsMoreContext) {
117
+ * loop.addMessage({ role: 'user', content: 'Additional context...' });
118
+ * }
119
+ * }
120
+ *
121
+ * const result = loop.getResult();
122
+ * ```
123
+ */
124
+ export declare function createAgentLoop(config: AgentLoopConfig): AgentLoop;
125
+ export declare class AgentLoop {
126
+ private config;
127
+ private messages;
128
+ private steps;
129
+ private currentStep;
130
+ private complete;
131
+ private totalUsage;
132
+ constructor(config: AgentLoopConfig);
133
+ /**
134
+ * Add a message to the conversation.
135
+ */
136
+ addMessage(message: Message): void;
137
+ /**
138
+ * Get all messages in the conversation.
139
+ */
140
+ getMessages(): Message[];
141
+ /**
142
+ * Check if the loop is complete.
143
+ */
144
+ isComplete(): boolean;
145
+ /**
146
+ * Run a single step of the agent loop.
147
+ */
148
+ step(): Promise<AgentStep>;
149
+ /**
150
+ * Run the full agent loop until completion.
151
+ */
152
+ run(prompt: string): Promise<AgentLoopResult>;
153
+ /**
154
+ * Get the final result.
155
+ */
156
+ getResult(): AgentLoopResult;
157
+ /**
158
+ * Check if the loop should stop.
159
+ */
160
+ private shouldStop;
161
+ /**
162
+ * Reset the agent loop.
163
+ */
164
+ reset(): void;
165
+ }
166
+ /**
167
+ * Create a stop condition that stops after N steps.
168
+ */
169
+ export declare function stopAfterSteps(count: number): StopCondition;
170
+ /**
171
+ * Create a stop condition that stops when no tool calls are made.
172
+ */
173
+ export declare function stopWhenNoToolCalls(): StopCondition;
174
+ /**
175
+ * Create a custom stop condition.
176
+ */
177
+ export declare function stopWhen(check: (step: AgentStep) => boolean): StopCondition;