praisonai 1.1.0 → 1.2.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.
- package/dist/agent/image.d.ts +51 -0
- package/dist/agent/image.js +93 -0
- package/dist/agent/prompt-expander.d.ts +40 -0
- package/dist/agent/prompt-expander.js +84 -0
- package/dist/agent/query-rewriter.d.ts +38 -0
- package/dist/agent/query-rewriter.js +79 -0
- package/dist/agent/research.d.ts +52 -0
- package/dist/agent/research.js +118 -0
- package/dist/auto/index.d.ts +56 -0
- package/dist/auto/index.js +142 -0
- package/dist/guardrails/llm-guardrail.d.ts +40 -0
- package/dist/guardrails/llm-guardrail.js +91 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +51 -1
- package/dist/knowledge/chunking.d.ts +55 -0
- package/dist/knowledge/chunking.js +157 -0
- package/dist/memory/memory.d.ts +92 -0
- package/dist/memory/memory.js +169 -0
- package/dist/planning/index.d.ts +133 -0
- package/dist/planning/index.js +228 -0
- package/dist/telemetry/index.d.ts +102 -0
- package/dist/telemetry/index.js +187 -0
- package/package.json +1 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageAgent - Agent for image generation and analysis
|
|
3
|
+
*/
|
|
4
|
+
export interface ImageGenerationConfig {
|
|
5
|
+
prompt: string;
|
|
6
|
+
size?: '256x256' | '512x512' | '1024x1024' | '1792x1024' | '1024x1792';
|
|
7
|
+
quality?: 'standard' | 'hd';
|
|
8
|
+
style?: 'vivid' | 'natural';
|
|
9
|
+
n?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ImageAnalysisConfig {
|
|
12
|
+
imageUrl: string;
|
|
13
|
+
prompt?: string;
|
|
14
|
+
detail?: 'low' | 'high' | 'auto';
|
|
15
|
+
}
|
|
16
|
+
export interface ImageAgentConfig {
|
|
17
|
+
name?: string;
|
|
18
|
+
llm?: string;
|
|
19
|
+
imageModel?: string;
|
|
20
|
+
verbose?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* ImageAgent - Agent for image generation and analysis
|
|
24
|
+
*/
|
|
25
|
+
export declare class ImageAgent {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
private provider;
|
|
28
|
+
private imageModel;
|
|
29
|
+
private verbose;
|
|
30
|
+
constructor(config?: ImageAgentConfig);
|
|
31
|
+
/**
|
|
32
|
+
* Analyze an image
|
|
33
|
+
*/
|
|
34
|
+
analyze(config: ImageAnalysisConfig): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Generate an image (requires OpenAI DALL-E)
|
|
37
|
+
*/
|
|
38
|
+
generate(config: ImageGenerationConfig): Promise<string[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Chat with image context
|
|
41
|
+
*/
|
|
42
|
+
chat(prompt: string, imageUrl?: string): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Compare two images
|
|
45
|
+
*/
|
|
46
|
+
compare(imageUrl1: string, imageUrl2: string, prompt?: string): Promise<string>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create an ImageAgent
|
|
50
|
+
*/
|
|
51
|
+
export declare function createImageAgent(config?: ImageAgentConfig): ImageAgent;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ImageAgent - Agent for image generation and analysis
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ImageAgent = void 0;
|
|
7
|
+
exports.createImageAgent = createImageAgent;
|
|
8
|
+
const providers_1 = require("../llm/providers");
|
|
9
|
+
/**
|
|
10
|
+
* ImageAgent - Agent for image generation and analysis
|
|
11
|
+
*/
|
|
12
|
+
class ImageAgent {
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
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');
|
|
16
|
+
this.imageModel = config.imageModel || 'dall-e-3';
|
|
17
|
+
this.verbose = config.verbose ?? false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Analyze an image
|
|
21
|
+
*/
|
|
22
|
+
async analyze(config) {
|
|
23
|
+
const prompt = config.prompt || 'Describe this image in detail.';
|
|
24
|
+
const messages = [
|
|
25
|
+
{
|
|
26
|
+
role: 'user',
|
|
27
|
+
content: [
|
|
28
|
+
{ type: 'text', text: prompt },
|
|
29
|
+
{
|
|
30
|
+
type: 'image_url',
|
|
31
|
+
image_url: {
|
|
32
|
+
url: config.imageUrl,
|
|
33
|
+
detail: config.detail || 'auto'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
const result = await this.provider.generateText({ messages });
|
|
40
|
+
if (this.verbose) {
|
|
41
|
+
console.log(`[ImageAgent] Analysis: ${result.text.substring(0, 100)}...`);
|
|
42
|
+
}
|
|
43
|
+
return result.text;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate an image (requires OpenAI DALL-E)
|
|
47
|
+
*/
|
|
48
|
+
async generate(config) {
|
|
49
|
+
// This would require direct OpenAI API call for image generation
|
|
50
|
+
// For now, return a placeholder
|
|
51
|
+
if (this.verbose) {
|
|
52
|
+
console.log(`[ImageAgent] Generating image: ${config.prompt}`);
|
|
53
|
+
}
|
|
54
|
+
throw new Error('Image generation requires direct OpenAI API integration. Use the OpenAI SDK directly for DALL-E.');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Chat with image context
|
|
58
|
+
*/
|
|
59
|
+
async chat(prompt, imageUrl) {
|
|
60
|
+
if (imageUrl) {
|
|
61
|
+
return this.analyze({ imageUrl, prompt });
|
|
62
|
+
}
|
|
63
|
+
const result = await this.provider.generateText({
|
|
64
|
+
messages: [{ role: 'user', content: prompt }]
|
|
65
|
+
});
|
|
66
|
+
return result.text;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Compare two images
|
|
70
|
+
*/
|
|
71
|
+
async compare(imageUrl1, imageUrl2, prompt) {
|
|
72
|
+
const comparePrompt = prompt || 'Compare these two images and describe the differences and similarities.';
|
|
73
|
+
const messages = [
|
|
74
|
+
{
|
|
75
|
+
role: 'user',
|
|
76
|
+
content: [
|
|
77
|
+
{ type: 'text', text: comparePrompt },
|
|
78
|
+
{ type: 'image_url', image_url: { url: imageUrl1 } },
|
|
79
|
+
{ type: 'image_url', image_url: { url: imageUrl2 } }
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
const result = await this.provider.generateText({ messages });
|
|
84
|
+
return result.text;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ImageAgent = ImageAgent;
|
|
88
|
+
/**
|
|
89
|
+
* Create an ImageAgent
|
|
90
|
+
*/
|
|
91
|
+
function createImageAgent(config) {
|
|
92
|
+
return new ImageAgent(config);
|
|
93
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptExpanderAgent - Expand and enhance prompts
|
|
3
|
+
*/
|
|
4
|
+
export type ExpandStrategy = 'detail' | 'context' | 'examples' | 'constraints' | 'auto';
|
|
5
|
+
export interface ExpandResult {
|
|
6
|
+
original: string;
|
|
7
|
+
expanded: string;
|
|
8
|
+
strategy: ExpandStrategy;
|
|
9
|
+
additions: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface PromptExpanderConfig {
|
|
12
|
+
name?: string;
|
|
13
|
+
llm?: string;
|
|
14
|
+
defaultStrategy?: ExpandStrategy;
|
|
15
|
+
verbose?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* PromptExpanderAgent - Expand prompts with more detail and context
|
|
19
|
+
*/
|
|
20
|
+
export declare class PromptExpanderAgent {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
private provider;
|
|
23
|
+
private defaultStrategy;
|
|
24
|
+
private verbose;
|
|
25
|
+
constructor(config?: PromptExpanderConfig);
|
|
26
|
+
/**
|
|
27
|
+
* Expand a prompt
|
|
28
|
+
*/
|
|
29
|
+
expand(prompt: string, strategy?: ExpandStrategy): Promise<ExpandResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Detect the best expansion strategy
|
|
32
|
+
*/
|
|
33
|
+
detectStrategy(prompt: string): ExpandStrategy;
|
|
34
|
+
private getSystemPrompt;
|
|
35
|
+
private extractAdditions;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a PromptExpanderAgent
|
|
39
|
+
*/
|
|
40
|
+
export declare function createPromptExpanderAgent(config?: PromptExpanderConfig): PromptExpanderAgent;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* PromptExpanderAgent - Expand and enhance prompts
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PromptExpanderAgent = void 0;
|
|
7
|
+
exports.createPromptExpanderAgent = createPromptExpanderAgent;
|
|
8
|
+
const providers_1 = require("../llm/providers");
|
|
9
|
+
/**
|
|
10
|
+
* PromptExpanderAgent - Expand prompts with more detail and context
|
|
11
|
+
*/
|
|
12
|
+
class PromptExpanderAgent {
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
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');
|
|
16
|
+
this.defaultStrategy = config.defaultStrategy || 'auto';
|
|
17
|
+
this.verbose = config.verbose ?? false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Expand a prompt
|
|
21
|
+
*/
|
|
22
|
+
async expand(prompt, strategy) {
|
|
23
|
+
const useStrategy = strategy || this.defaultStrategy;
|
|
24
|
+
const actualStrategy = useStrategy === 'auto' ? this.detectStrategy(prompt) : useStrategy;
|
|
25
|
+
const systemPrompt = this.getSystemPrompt(actualStrategy);
|
|
26
|
+
const result = await this.provider.generateText({
|
|
27
|
+
messages: [
|
|
28
|
+
{ role: 'system', content: systemPrompt },
|
|
29
|
+
{ role: 'user', content: `Expand this prompt: ${prompt}` }
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
const expanded = result.text;
|
|
33
|
+
const additions = this.extractAdditions(prompt, expanded);
|
|
34
|
+
if (this.verbose) {
|
|
35
|
+
console.log(`[PromptExpander] Strategy: ${actualStrategy}, Added ${additions.length} elements`);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
original: prompt,
|
|
39
|
+
expanded,
|
|
40
|
+
strategy: actualStrategy,
|
|
41
|
+
additions
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Detect the best expansion strategy
|
|
46
|
+
*/
|
|
47
|
+
detectStrategy(prompt) {
|
|
48
|
+
const words = prompt.split(/\s+/).length;
|
|
49
|
+
const lower = prompt.toLowerCase();
|
|
50
|
+
if (words < 5)
|
|
51
|
+
return 'detail';
|
|
52
|
+
if (lower.includes('why') || lower.includes('explain') || lower.includes('context'))
|
|
53
|
+
return 'context';
|
|
54
|
+
if (lower.includes('example') || lower.includes('show') || lower.includes('demonstrate'))
|
|
55
|
+
return 'examples';
|
|
56
|
+
if (lower.includes('must') || lower.includes('should') || lower.includes('require'))
|
|
57
|
+
return 'constraints';
|
|
58
|
+
return 'detail';
|
|
59
|
+
}
|
|
60
|
+
getSystemPrompt(strategy) {
|
|
61
|
+
const prompts = {
|
|
62
|
+
detail: 'Expand this prompt by adding specific details, requirements, and clarifications. Make it more precise and actionable.',
|
|
63
|
+
context: 'Expand this prompt by adding relevant background context, explaining the purpose, and providing necessary information.',
|
|
64
|
+
examples: 'Expand this prompt by adding concrete examples, sample inputs/outputs, and demonstrations of expected behavior.',
|
|
65
|
+
constraints: 'Expand this prompt by adding explicit constraints, requirements, limitations, and success criteria.',
|
|
66
|
+
auto: 'Expand this prompt to make it clearer, more specific, and more actionable. Add relevant details and context.'
|
|
67
|
+
};
|
|
68
|
+
return prompts[strategy];
|
|
69
|
+
}
|
|
70
|
+
extractAdditions(original, expanded) {
|
|
71
|
+
const originalWords = new Set(original.toLowerCase().split(/\s+/));
|
|
72
|
+
const expandedWords = expanded.toLowerCase().split(/\s+/);
|
|
73
|
+
const newWords = expandedWords.filter(w => !originalWords.has(w) && w.length > 3);
|
|
74
|
+
const uniqueNew = [...new Set(newWords)];
|
|
75
|
+
return uniqueNew.slice(0, 10);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.PromptExpanderAgent = PromptExpanderAgent;
|
|
79
|
+
/**
|
|
80
|
+
* Create a PromptExpanderAgent
|
|
81
|
+
*/
|
|
82
|
+
function createPromptExpanderAgent(config) {
|
|
83
|
+
return new PromptExpanderAgent(config);
|
|
84
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QueryRewriterAgent - Rewrite and optimize queries
|
|
3
|
+
*/
|
|
4
|
+
export type RewriteStrategy = 'expand' | 'simplify' | 'decompose' | 'rephrase' | 'auto';
|
|
5
|
+
export interface RewriteResult {
|
|
6
|
+
original: string;
|
|
7
|
+
rewritten: string[];
|
|
8
|
+
strategy: RewriteStrategy;
|
|
9
|
+
confidence: number;
|
|
10
|
+
}
|
|
11
|
+
export interface QueryRewriterConfig {
|
|
12
|
+
name?: string;
|
|
13
|
+
llm?: string;
|
|
14
|
+
defaultStrategy?: RewriteStrategy;
|
|
15
|
+
verbose?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* QueryRewriterAgent - Optimize and rewrite queries
|
|
19
|
+
*/
|
|
20
|
+
export declare class QueryRewriterAgent {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
private provider;
|
|
23
|
+
private defaultStrategy;
|
|
24
|
+
private verbose;
|
|
25
|
+
constructor(config?: QueryRewriterConfig);
|
|
26
|
+
/**
|
|
27
|
+
* Rewrite a query
|
|
28
|
+
*/
|
|
29
|
+
rewrite(query: string, strategy?: RewriteStrategy): Promise<RewriteResult>;
|
|
30
|
+
private detectStrategy;
|
|
31
|
+
private getSystemPrompt;
|
|
32
|
+
private buildPrompt;
|
|
33
|
+
private parseRewrittenQueries;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a QueryRewriterAgent
|
|
37
|
+
*/
|
|
38
|
+
export declare function createQueryRewriterAgent(config?: QueryRewriterConfig): QueryRewriterAgent;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* QueryRewriterAgent - Rewrite and optimize queries
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.QueryRewriterAgent = void 0;
|
|
7
|
+
exports.createQueryRewriterAgent = createQueryRewriterAgent;
|
|
8
|
+
const providers_1 = require("../llm/providers");
|
|
9
|
+
/**
|
|
10
|
+
* QueryRewriterAgent - Optimize and rewrite queries
|
|
11
|
+
*/
|
|
12
|
+
class QueryRewriterAgent {
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
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');
|
|
16
|
+
this.defaultStrategy = config.defaultStrategy || 'auto';
|
|
17
|
+
this.verbose = config.verbose ?? false;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Rewrite a query
|
|
21
|
+
*/
|
|
22
|
+
async rewrite(query, strategy) {
|
|
23
|
+
const useStrategy = strategy || this.defaultStrategy;
|
|
24
|
+
const actualStrategy = useStrategy === 'auto' ? this.detectStrategy(query) : useStrategy;
|
|
25
|
+
const prompt = this.buildPrompt(query, actualStrategy);
|
|
26
|
+
const result = await this.provider.generateText({
|
|
27
|
+
messages: [
|
|
28
|
+
{ role: 'system', content: this.getSystemPrompt(actualStrategy) },
|
|
29
|
+
{ role: 'user', content: prompt }
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
const rewritten = this.parseRewrittenQueries(result.text);
|
|
33
|
+
if (this.verbose) {
|
|
34
|
+
console.log(`[QueryRewriter] Strategy: ${actualStrategy}, Rewrites: ${rewritten.length}`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
original: query,
|
|
38
|
+
rewritten,
|
|
39
|
+
strategy: actualStrategy,
|
|
40
|
+
confidence: rewritten.length > 0 ? 0.85 : 0.5
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
detectStrategy(query) {
|
|
44
|
+
const words = query.split(/\s+/).length;
|
|
45
|
+
if (words < 3)
|
|
46
|
+
return 'expand';
|
|
47
|
+
if (words > 20)
|
|
48
|
+
return 'simplify';
|
|
49
|
+
if (query.includes(' and ') || query.includes(' or '))
|
|
50
|
+
return 'decompose';
|
|
51
|
+
return 'rephrase';
|
|
52
|
+
}
|
|
53
|
+
getSystemPrompt(strategy) {
|
|
54
|
+
const prompts = {
|
|
55
|
+
expand: 'Expand this query with more context and detail. Generate 3 expanded versions.',
|
|
56
|
+
simplify: 'Simplify this query to its core intent. Generate 3 simpler versions.',
|
|
57
|
+
decompose: 'Break this query into smaller, focused sub-queries. Generate 3-5 sub-queries.',
|
|
58
|
+
rephrase: 'Rephrase this query in different ways while keeping the same meaning. Generate 3 versions.',
|
|
59
|
+
auto: 'Optimize this query for better search results. Generate 3 improved versions.'
|
|
60
|
+
};
|
|
61
|
+
return prompts[strategy] + ' Output one query per line.';
|
|
62
|
+
}
|
|
63
|
+
buildPrompt(query, strategy) {
|
|
64
|
+
return `Query: ${query}\n\nRewrite using ${strategy} strategy:`;
|
|
65
|
+
}
|
|
66
|
+
parseRewrittenQueries(response) {
|
|
67
|
+
return response
|
|
68
|
+
.split('\n')
|
|
69
|
+
.map(line => line.replace(/^\d+[\.\)]\s*/, '').trim())
|
|
70
|
+
.filter(line => line.length > 0 && line.length < 500);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.QueryRewriterAgent = QueryRewriterAgent;
|
|
74
|
+
/**
|
|
75
|
+
* Create a QueryRewriterAgent
|
|
76
|
+
*/
|
|
77
|
+
function createQueryRewriterAgent(config) {
|
|
78
|
+
return new QueryRewriterAgent(config);
|
|
79
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeepResearchAgent - Agent for comprehensive research tasks
|
|
3
|
+
*/
|
|
4
|
+
export interface Citation {
|
|
5
|
+
title: string;
|
|
6
|
+
url: string;
|
|
7
|
+
snippet?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ReasoningStep {
|
|
10
|
+
step: number;
|
|
11
|
+
thought: string;
|
|
12
|
+
action?: string;
|
|
13
|
+
result?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ResearchResponse {
|
|
16
|
+
answer: string;
|
|
17
|
+
citations: Citation[];
|
|
18
|
+
reasoning: ReasoningStep[];
|
|
19
|
+
confidence: number;
|
|
20
|
+
}
|
|
21
|
+
export interface DeepResearchConfig {
|
|
22
|
+
name?: string;
|
|
23
|
+
llm?: string;
|
|
24
|
+
maxIterations?: number;
|
|
25
|
+
searchTool?: (query: string) => Promise<Citation[]>;
|
|
26
|
+
verbose?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* DeepResearchAgent - Comprehensive research with citations
|
|
30
|
+
*/
|
|
31
|
+
export declare class DeepResearchAgent {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
private provider;
|
|
34
|
+
private maxIterations;
|
|
35
|
+
private searchTool?;
|
|
36
|
+
private verbose;
|
|
37
|
+
constructor(config?: DeepResearchConfig);
|
|
38
|
+
/**
|
|
39
|
+
* Conduct deep research on a topic
|
|
40
|
+
*/
|
|
41
|
+
research(query: string): Promise<ResearchResponse>;
|
|
42
|
+
private generateSearchQueries;
|
|
43
|
+
private synthesizeAnswer;
|
|
44
|
+
/**
|
|
45
|
+
* Set search tool
|
|
46
|
+
*/
|
|
47
|
+
setSearchTool(tool: (query: string) => Promise<Citation[]>): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a DeepResearchAgent
|
|
51
|
+
*/
|
|
52
|
+
export declare function createDeepResearchAgent(config?: DeepResearchConfig): DeepResearchAgent;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* DeepResearchAgent - Agent for comprehensive research tasks
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DeepResearchAgent = void 0;
|
|
7
|
+
exports.createDeepResearchAgent = createDeepResearchAgent;
|
|
8
|
+
const providers_1 = require("../llm/providers");
|
|
9
|
+
/**
|
|
10
|
+
* DeepResearchAgent - Comprehensive research with citations
|
|
11
|
+
*/
|
|
12
|
+
class DeepResearchAgent {
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
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');
|
|
16
|
+
this.maxIterations = config.maxIterations ?? 5;
|
|
17
|
+
this.searchTool = config.searchTool;
|
|
18
|
+
this.verbose = config.verbose ?? false;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Conduct deep research on a topic
|
|
22
|
+
*/
|
|
23
|
+
async research(query) {
|
|
24
|
+
const reasoning = [];
|
|
25
|
+
const citations = [];
|
|
26
|
+
let iteration = 0;
|
|
27
|
+
// Step 1: Analyze the query
|
|
28
|
+
reasoning.push({
|
|
29
|
+
step: ++iteration,
|
|
30
|
+
thought: `Analyzing research query: "${query}"`,
|
|
31
|
+
action: 'query_analysis'
|
|
32
|
+
});
|
|
33
|
+
// Step 2: Generate search queries
|
|
34
|
+
const searchQueries = await this.generateSearchQueries(query);
|
|
35
|
+
reasoning.push({
|
|
36
|
+
step: ++iteration,
|
|
37
|
+
thought: `Generated ${searchQueries.length} search queries`,
|
|
38
|
+
action: 'generate_queries',
|
|
39
|
+
result: searchQueries.join(', ')
|
|
40
|
+
});
|
|
41
|
+
// Step 3: Execute searches if tool available
|
|
42
|
+
if (this.searchTool) {
|
|
43
|
+
for (const sq of searchQueries.slice(0, 3)) {
|
|
44
|
+
try {
|
|
45
|
+
const results = await this.searchTool(sq);
|
|
46
|
+
citations.push(...results);
|
|
47
|
+
reasoning.push({
|
|
48
|
+
step: ++iteration,
|
|
49
|
+
thought: `Searched for: "${sq}"`,
|
|
50
|
+
action: 'web_search',
|
|
51
|
+
result: `Found ${results.length} results`
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (this.verbose) {
|
|
56
|
+
console.log(`[Research] Search failed for: ${sq}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Step 4: Synthesize answer
|
|
62
|
+
const answer = await this.synthesizeAnswer(query, citations);
|
|
63
|
+
reasoning.push({
|
|
64
|
+
step: ++iteration,
|
|
65
|
+
thought: 'Synthesizing final answer from gathered information',
|
|
66
|
+
action: 'synthesize',
|
|
67
|
+
result: 'Answer generated'
|
|
68
|
+
});
|
|
69
|
+
// Calculate confidence based on citations
|
|
70
|
+
const confidence = Math.min(0.5 + (citations.length * 0.1), 0.95);
|
|
71
|
+
return {
|
|
72
|
+
answer,
|
|
73
|
+
citations,
|
|
74
|
+
reasoning,
|
|
75
|
+
confidence
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async generateSearchQueries(query) {
|
|
79
|
+
const result = await this.provider.generateText({
|
|
80
|
+
messages: [
|
|
81
|
+
{
|
|
82
|
+
role: 'system',
|
|
83
|
+
content: 'Generate 3 search queries to research this topic. Output only the queries, one per line.'
|
|
84
|
+
},
|
|
85
|
+
{ role: 'user', content: query }
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
return result.text.split('\n').filter(q => q.trim().length > 0).slice(0, 3);
|
|
89
|
+
}
|
|
90
|
+
async synthesizeAnswer(query, citations) {
|
|
91
|
+
const context = citations.length > 0
|
|
92
|
+
? `\n\nRelevant sources:\n${citations.map(c => `- ${c.title}: ${c.snippet || ''}`).join('\n')}`
|
|
93
|
+
: '';
|
|
94
|
+
const result = await this.provider.generateText({
|
|
95
|
+
messages: [
|
|
96
|
+
{
|
|
97
|
+
role: 'system',
|
|
98
|
+
content: 'You are a research assistant. Provide a comprehensive, well-structured answer based on the available information. Cite sources when available.'
|
|
99
|
+
},
|
|
100
|
+
{ role: 'user', content: `${query}${context}` }
|
|
101
|
+
]
|
|
102
|
+
});
|
|
103
|
+
return result.text;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Set search tool
|
|
107
|
+
*/
|
|
108
|
+
setSearchTool(tool) {
|
|
109
|
+
this.searchTool = tool;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.DeepResearchAgent = DeepResearchAgent;
|
|
113
|
+
/**
|
|
114
|
+
* Create a DeepResearchAgent
|
|
115
|
+
*/
|
|
116
|
+
function createDeepResearchAgent(config) {
|
|
117
|
+
return new DeepResearchAgent(config);
|
|
118
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AutoAgents - Automatic agent generation from task descriptions
|
|
3
|
+
*/
|
|
4
|
+
export interface AgentConfig {
|
|
5
|
+
name: string;
|
|
6
|
+
role: string;
|
|
7
|
+
goal: string;
|
|
8
|
+
backstory?: string;
|
|
9
|
+
instructions?: string;
|
|
10
|
+
tools?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface TaskConfig {
|
|
13
|
+
description: string;
|
|
14
|
+
expectedOutput?: string;
|
|
15
|
+
agent?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TeamStructure {
|
|
18
|
+
agents: AgentConfig[];
|
|
19
|
+
tasks: TaskConfig[];
|
|
20
|
+
pattern: 'sequential' | 'parallel' | 'hierarchical';
|
|
21
|
+
}
|
|
22
|
+
export interface AutoAgentsConfig {
|
|
23
|
+
llm?: string;
|
|
24
|
+
pattern?: 'sequential' | 'parallel' | 'routing' | 'orchestrator-workers' | 'evaluator-optimizer';
|
|
25
|
+
singleAgent?: boolean;
|
|
26
|
+
verbose?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* AutoAgents - Generate agent configurations from task descriptions
|
|
30
|
+
*/
|
|
31
|
+
export declare class AutoAgents {
|
|
32
|
+
private provider;
|
|
33
|
+
private pattern;
|
|
34
|
+
private singleAgent;
|
|
35
|
+
private verbose;
|
|
36
|
+
constructor(config?: AutoAgentsConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Generate agent configuration from task description
|
|
39
|
+
*/
|
|
40
|
+
generate(taskDescription: string): Promise<TeamStructure>;
|
|
41
|
+
/**
|
|
42
|
+
* Recommend a pattern for the task
|
|
43
|
+
*/
|
|
44
|
+
recommendPattern(taskDescription: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Analyze task complexity
|
|
47
|
+
*/
|
|
48
|
+
analyzeComplexity(taskDescription: string): 'simple' | 'moderate' | 'complex';
|
|
49
|
+
private getSystemPrompt;
|
|
50
|
+
private buildPrompt;
|
|
51
|
+
private parseResponse;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create an AutoAgents instance
|
|
55
|
+
*/
|
|
56
|
+
export declare function createAutoAgents(config?: AutoAgentsConfig): AutoAgents;
|