praisonai 1.3.5 → 1.3.6
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.
- package/dist/agent/context.d.ts +6 -0
- package/dist/agent/context.js +24 -3
- package/dist/agent/enhanced.d.ts +6 -0
- package/dist/agent/enhanced.js +32 -6
- package/dist/agent/image.d.ts +6 -0
- package/dist/agent/image.js +28 -5
- package/dist/agent/prompt-expander.d.ts +3 -0
- package/dist/agent/prompt-expander.js +18 -3
- package/dist/agent/query-rewriter.d.ts +3 -0
- package/dist/agent/query-rewriter.js +18 -3
- package/dist/agent/research.d.ts +3 -0
- package/dist/agent/research.js +20 -4
- package/dist/agent/simple.d.ts +1 -1
- package/dist/agent/simple.js +3 -2
- package/dist/auto/index.d.ts +6 -0
- package/dist/auto/index.js +24 -3
- package/dist/cli/commands/chat.js +2 -2
- package/dist/guardrails/llm-guardrail.d.ts +6 -0
- package/dist/guardrails/llm-guardrail.js +24 -3
- package/package.json +1 -1
package/dist/agent/context.d.ts
CHANGED
|
@@ -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
|
*/
|
package/dist/agent/context.js
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
|
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',
|
package/dist/agent/enhanced.d.ts
CHANGED
|
@@ -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
|
package/dist/agent/enhanced.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.EnhancedAgent = void 0;
|
|
7
|
-
const
|
|
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
|
-
//
|
|
25
|
-
this.
|
|
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
|
|
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
|
|
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
|
-
|
|
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,
|
package/dist/agent/image.d.ts
CHANGED
|
@@ -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
|
*/
|
package/dist/agent/image.js
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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 }
|
package/dist/agent/research.d.ts
CHANGED
|
@@ -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
|
*/
|
package/dist/agent/research.js
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
|
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
|
|
109
|
+
const provider = await this.getProvider();
|
|
110
|
+
const result = await provider.generateText({
|
|
95
111
|
messages: [
|
|
96
112
|
{
|
|
97
113
|
role: 'system',
|
package/dist/agent/simple.d.ts
CHANGED
|
@@ -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
|
|
118
|
+
* Generate a unique session ID based on current hour, agent name, and random suffix
|
|
119
119
|
*/
|
|
120
120
|
private generateSessionId;
|
|
121
121
|
/**
|
package/dist/agent/simple.js
CHANGED
|
@@ -139,13 +139,14 @@ class Agent {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
|
-
* Generate a session ID based on current hour
|
|
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
|
-
|
|
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)
|
package/dist/auto/index.d.ts
CHANGED
|
@@ -30,10 +30,16 @@ export interface AutoAgentsConfig {
|
|
|
30
30
|
*/
|
|
31
31
|
export declare class AutoAgents {
|
|
32
32
|
private provider;
|
|
33
|
+
private providerPromise;
|
|
34
|
+
private llmModel;
|
|
33
35
|
private pattern;
|
|
34
36
|
private singleAgent;
|
|
35
37
|
private verbose;
|
|
36
38
|
constructor(config?: AutoAgentsConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Get the LLM provider (lazy initialization with AI SDK backend)
|
|
41
|
+
*/
|
|
42
|
+
private getProvider;
|
|
37
43
|
/**
|
|
38
44
|
* Generate agent configuration from task description
|
|
39
45
|
*/
|
package/dist/auto/index.js
CHANGED
|
@@ -5,23 +5,44 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.AutoAgents = void 0;
|
|
7
7
|
exports.createAutoAgents = createAutoAgents;
|
|
8
|
-
const
|
|
8
|
+
const backend_resolver_1 = require("../llm/backend-resolver");
|
|
9
9
|
/**
|
|
10
10
|
* AutoAgents - Generate agent configurations from task descriptions
|
|
11
11
|
*/
|
|
12
12
|
class AutoAgents {
|
|
13
13
|
constructor(config = {}) {
|
|
14
|
-
this.provider =
|
|
14
|
+
this.provider = null;
|
|
15
|
+
this.providerPromise = null;
|
|
16
|
+
this.llmModel = config.llm || 'openai/gpt-4o-mini';
|
|
15
17
|
this.pattern = config.pattern || 'sequential';
|
|
16
18
|
this.singleAgent = config.singleAgent ?? false;
|
|
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: 'AutoAgents' },
|
|
32
|
+
});
|
|
33
|
+
this.provider = result.provider;
|
|
34
|
+
return result.provider;
|
|
35
|
+
})();
|
|
36
|
+
}
|
|
37
|
+
return this.providerPromise;
|
|
38
|
+
}
|
|
19
39
|
/**
|
|
20
40
|
* Generate agent configuration from task description
|
|
21
41
|
*/
|
|
22
42
|
async generate(taskDescription) {
|
|
23
43
|
const prompt = this.buildPrompt(taskDescription);
|
|
24
|
-
const
|
|
44
|
+
const provider = await this.getProvider();
|
|
45
|
+
const result = await provider.generateText({
|
|
25
46
|
messages: [
|
|
26
47
|
{ role: 'system', content: this.getSystemPrompt() },
|
|
27
48
|
{ role: 'user', content: prompt }
|
|
@@ -37,7 +37,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.execute = execute;
|
|
40
|
-
const
|
|
40
|
+
const backend_resolver_1 = require("../../llm/backend-resolver");
|
|
41
41
|
const session_1 = require("../../session");
|
|
42
42
|
const resolve_1 = require("../config/resolve");
|
|
43
43
|
const json_1 = require("../output/json");
|
|
@@ -66,7 +66,7 @@ async function execute(args, options) {
|
|
|
66
66
|
const startTime = Date.now();
|
|
67
67
|
const outputFormat = options.json ? 'json' : (options.output || 'pretty');
|
|
68
68
|
try {
|
|
69
|
-
const provider = (0,
|
|
69
|
+
const { provider } = await (0, backend_resolver_1.resolveBackend)(config.model);
|
|
70
70
|
const session = new session_1.Session({ id: options.session });
|
|
71
71
|
session.addMessage({ role: 'user', content: prompt });
|
|
72
72
|
let responseText = '';
|
|
@@ -21,9 +21,15 @@ export declare class LLMGuardrail {
|
|
|
21
21
|
readonly name: string;
|
|
22
22
|
readonly criteria: string;
|
|
23
23
|
private provider;
|
|
24
|
+
private providerPromise;
|
|
25
|
+
private llmModel;
|
|
24
26
|
private threshold;
|
|
25
27
|
private verbose;
|
|
26
28
|
constructor(config: LLMGuardrailConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Get the LLM provider (lazy initialization with AI SDK backend)
|
|
31
|
+
*/
|
|
32
|
+
private getProvider;
|
|
27
33
|
/**
|
|
28
34
|
* Check content against criteria
|
|
29
35
|
*/
|
|
@@ -5,18 +5,38 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.LLMGuardrail = void 0;
|
|
7
7
|
exports.createLLMGuardrail = createLLMGuardrail;
|
|
8
|
-
const
|
|
8
|
+
const backend_resolver_1 = require("../llm/backend-resolver");
|
|
9
9
|
/**
|
|
10
10
|
* LLMGuardrail - Use LLM to validate content against criteria
|
|
11
11
|
*/
|
|
12
12
|
class LLMGuardrail {
|
|
13
13
|
constructor(config) {
|
|
14
|
+
this.provider = null;
|
|
15
|
+
this.providerPromise = null;
|
|
14
16
|
this.name = config.name;
|
|
15
17
|
this.criteria = config.criteria;
|
|
16
|
-
this.
|
|
18
|
+
this.llmModel = config.llm || 'openai/gpt-4o-mini';
|
|
17
19
|
this.threshold = config.threshold ?? 0.7;
|
|
18
20
|
this.verbose = config.verbose ?? false;
|
|
19
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the LLM provider (lazy initialization with AI SDK backend)
|
|
24
|
+
*/
|
|
25
|
+
async getProvider() {
|
|
26
|
+
if (this.provider) {
|
|
27
|
+
return this.provider;
|
|
28
|
+
}
|
|
29
|
+
if (!this.providerPromise) {
|
|
30
|
+
this.providerPromise = (async () => {
|
|
31
|
+
const result = await (0, backend_resolver_1.resolveBackend)(this.llmModel, {
|
|
32
|
+
attribution: { agentId: `LLMGuardrail:${this.name}` },
|
|
33
|
+
});
|
|
34
|
+
this.provider = result.provider;
|
|
35
|
+
return result.provider;
|
|
36
|
+
})();
|
|
37
|
+
}
|
|
38
|
+
return this.providerPromise;
|
|
39
|
+
}
|
|
20
40
|
/**
|
|
21
41
|
* Check content against criteria
|
|
22
42
|
*/
|
|
@@ -34,7 +54,8 @@ Respond with a JSON object containing:
|
|
|
34
54
|
|
|
35
55
|
JSON response:`;
|
|
36
56
|
try {
|
|
37
|
-
const
|
|
57
|
+
const provider = await this.getProvider();
|
|
58
|
+
const result = await provider.generateText({
|
|
38
59
|
messages: [{ role: 'user', content: prompt }]
|
|
39
60
|
});
|
|
40
61
|
const parsed = this.parseResponse(result.text);
|