@looopy-ai/core 2.1.8 → 2.1.11
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/core/agent.d.ts +4 -8
- package/dist/core/agent.js +3 -5
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/iteration.d.ts +3 -3
- package/dist/core/iteration.js +33 -34
- package/dist/core/loop.d.ts +3 -3
- package/dist/core/tools.d.ts +1 -1
- package/dist/core/tools.js +26 -19
- package/dist/events/utils.d.ts +19 -53
- package/dist/events/utils.js +0 -34
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/observability/spans/iteration.d.ts +1 -1
- package/dist/observability/spans/llm-call.d.ts +5 -5
- package/dist/observability/spans/llm-call.js +8 -4
- package/dist/observability/spans/tool.d.ts +3 -3
- package/dist/plugins/agent-academy.d.ts +9 -0
- package/dist/plugins/agent-academy.js +137 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/system-prompt.d.ts +3 -0
- package/dist/plugins/system-prompt.js +20 -0
- package/dist/providers/litellm-provider.d.ts +3 -2
- package/dist/providers/litellm-provider.js +11 -9
- package/dist/stores/artifacts/internal-event-artifact-store.d.ts +2 -2
- package/dist/stores/artifacts/internal-event-artifact-store.js +0 -6
- package/dist/stores/filesystem/filesystem-message-store.d.ts +5 -5
- package/dist/stores/messages/hybrid-message-store.d.ts +7 -7
- package/dist/stores/messages/interfaces.d.ts +8 -8
- package/dist/stores/messages/mem0-message-store.d.ts +5 -5
- package/dist/stores/messages/memory-message-store.d.ts +5 -5
- package/dist/tools/agent-tool-provider.d.ts +5 -5
- package/dist/tools/agent-tool-provider.js +14 -10
- package/dist/tools/artifact-tools.d.ts +2 -2
- package/dist/tools/artifact-tools.js +14 -14
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +0 -1
- package/dist/tools/local-tools.d.ts +4 -3
- package/dist/tools/local-tools.js +8 -8
- package/dist/tools/mcp-tool-provider.d.ts +5 -4
- package/dist/tools/mcp-tool-provider.js +7 -7
- package/dist/tools/tool-result-events.d.ts +3 -4
- package/dist/tools/tool-result-events.js +2 -8
- package/dist/types/a2a.d.ts +2 -2
- package/dist/types/agent.d.ts +1 -1
- package/dist/types/core.d.ts +56 -0
- package/dist/types/core.js +8 -0
- package/dist/types/event.d.ts +6 -5
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/llm.d.ts +3 -3
- package/dist/types/message.d.ts +5 -5
- package/dist/types/prettify.d.ts +3 -0
- package/dist/types/state.d.ts +2 -2
- package/dist/types/tools.d.ts +3 -12
- package/dist/types/tools.js +2 -2
- package/dist/utils/prompt.d.ts +5 -7
- package/dist/utils/prompt.js +12 -10
- package/package.json +5 -3
- package/dist/core/types.d.ts +0 -31
- package/dist/skills/index.d.ts +0 -1
- package/dist/skills/index.js +0 -1
- package/dist/skills/registry.d.ts +0 -14
- package/dist/skills/registry.js +0 -61
- package/dist/tools/client-tool-provider.d.ts +0 -25
- package/dist/tools/client-tool-provider.js +0 -143
- /package/dist/{core/types.js → types/prettify.js} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@looopy-ai/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.11",
|
|
4
4
|
"description": "RxJS-based AI agent framework",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/looopy-ai/lib"
|
|
7
|
+
},
|
|
5
8
|
"keywords": [
|
|
6
9
|
"agent",
|
|
7
10
|
"ai",
|
|
@@ -18,8 +21,7 @@
|
|
|
18
21
|
"import": "./dist/index.js",
|
|
19
22
|
"types": "./dist/index.d.ts"
|
|
20
23
|
},
|
|
21
|
-
"./package.json": "./package.json"
|
|
22
|
-
"./ts": "./src/index.ts"
|
|
24
|
+
"./package.json": "./package.json"
|
|
23
25
|
},
|
|
24
26
|
"main": "dist/index.js",
|
|
25
27
|
"types": "dist/index.d.ts",
|
package/dist/core/types.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type pino from 'pino';
|
|
2
|
-
import type { SkillRegistry } from '../skills';
|
|
3
|
-
import type { LLMProvider } from '../types/llm';
|
|
4
|
-
import type { ToolProvider } from '../types/tools';
|
|
5
|
-
import type { SystemPromptProp } from '../utils';
|
|
6
|
-
export type AgentContext<AuthContext> = {
|
|
7
|
-
agentId: string;
|
|
8
|
-
contextId: string;
|
|
9
|
-
parentContext: import('@opentelemetry/api').Context;
|
|
10
|
-
authContext?: AuthContext;
|
|
11
|
-
toolProviders: ToolProvider<AuthContext>[];
|
|
12
|
-
logger: pino.Logger;
|
|
13
|
-
systemPrompt?: SystemPromptProp;
|
|
14
|
-
skillRegistry?: SkillRegistry;
|
|
15
|
-
metadata?: Record<string, unknown>;
|
|
16
|
-
};
|
|
17
|
-
export type TurnContext<AuthContext> = AgentContext<AuthContext> & {
|
|
18
|
-
taskId: string;
|
|
19
|
-
turnNumber: number;
|
|
20
|
-
};
|
|
21
|
-
export type LoopContext<AuthContext> = TurnContext<AuthContext>;
|
|
22
|
-
export type IterationContext<AuthContext> = TurnContext<AuthContext>;
|
|
23
|
-
export type LoopConfig = {
|
|
24
|
-
llmProvider: LLMProvider;
|
|
25
|
-
maxIterations: number;
|
|
26
|
-
stopOnToolError: boolean;
|
|
27
|
-
};
|
|
28
|
-
export type IterationConfig = {
|
|
29
|
-
llmProvider: LLMProvider;
|
|
30
|
-
iterationNumber: number;
|
|
31
|
-
};
|
package/dist/skills/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './registry';
|
package/dist/skills/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './registry';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
import type { Skill } from '../types';
|
|
3
|
-
export declare const learnSkillToolName = "learn_skill";
|
|
4
|
-
export declare const skill: (definition: Skill) => Skill;
|
|
5
|
-
export declare class SkillRegistry {
|
|
6
|
-
private skills;
|
|
7
|
-
constructor(skills?: Skill[]);
|
|
8
|
-
register(skill: Skill): void;
|
|
9
|
-
get(name: string): Skill | undefined;
|
|
10
|
-
list(): Skill[];
|
|
11
|
-
tool(): import("..").LocalToolDefinition<z.ZodObject<{
|
|
12
|
-
name: z.ZodString;
|
|
13
|
-
}, z.core.$strip>, unknown>;
|
|
14
|
-
}
|
package/dist/skills/registry.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
import { tool } from '../tools/local-tools';
|
|
3
|
-
export const learnSkillToolName = 'learn_skill';
|
|
4
|
-
const getInstruction = async (instruction) => {
|
|
5
|
-
if (typeof instruction === 'string') {
|
|
6
|
-
return instruction;
|
|
7
|
-
}
|
|
8
|
-
return await instruction();
|
|
9
|
-
};
|
|
10
|
-
export const skill = (definition) => {
|
|
11
|
-
return { ...definition };
|
|
12
|
-
};
|
|
13
|
-
export class SkillRegistry {
|
|
14
|
-
skills = {};
|
|
15
|
-
constructor(skills = []) {
|
|
16
|
-
skills.forEach((skill) => {
|
|
17
|
-
this.skills[skill.name] = skill;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
register(skill) {
|
|
21
|
-
this.skills[skill.name] = skill;
|
|
22
|
-
}
|
|
23
|
-
get(name) {
|
|
24
|
-
return this.skills[name];
|
|
25
|
-
}
|
|
26
|
-
list() {
|
|
27
|
-
return Object.values(this.skills);
|
|
28
|
-
}
|
|
29
|
-
tool() {
|
|
30
|
-
return tool({
|
|
31
|
-
name: learnSkillToolName,
|
|
32
|
-
icon: 'lucide:graduation-cap',
|
|
33
|
-
description: 'Learns a new skill from the available skill registry.',
|
|
34
|
-
schema: z.object({
|
|
35
|
-
name: z.string().describe('The name of the skill to learn.'),
|
|
36
|
-
}),
|
|
37
|
-
handler: async ({ name }) => {
|
|
38
|
-
const foundSkill = this.get(name);
|
|
39
|
-
if (!foundSkill) {
|
|
40
|
-
const availableSkills = this.list()
|
|
41
|
-
.map((s) => `'${s.name}'`)
|
|
42
|
-
.join(', ');
|
|
43
|
-
return {
|
|
44
|
-
success: false,
|
|
45
|
-
result: null,
|
|
46
|
-
error: `Skill '${name}' not found. Available skills are: ${availableSkills}`,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const systemMessage = {
|
|
50
|
-
role: 'system',
|
|
51
|
-
content: `You have learned the following skill:\n\n**${foundSkill.name}**\n${await getInstruction(foundSkill.instruction)}`,
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
success: true,
|
|
55
|
-
result: `Successfully learned the '${name}' skill.`,
|
|
56
|
-
messages: [systemMessage],
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext } from '../types/context';
|
|
2
|
-
import { type ToolCall, type ToolDefinition, type ToolProvider, type ToolResult } from '../types/tools';
|
|
3
|
-
export interface ClientToolConfig<AuthContext> {
|
|
4
|
-
tools: unknown;
|
|
5
|
-
onInputRequired: (toolCall: ToolCall, context: ExecutionContext<AuthContext>) => Promise<ToolResult>;
|
|
6
|
-
}
|
|
7
|
-
export declare class ClientToolProvider<AuthContext> implements ToolProvider<AuthContext> {
|
|
8
|
-
name: string;
|
|
9
|
-
private readonly tools;
|
|
10
|
-
private readonly toolNames;
|
|
11
|
-
private readonly onInputRequired;
|
|
12
|
-
constructor(config: ClientToolConfig<AuthContext>);
|
|
13
|
-
getTools(): Promise<ToolDefinition[]>;
|
|
14
|
-
execute(toolCall: ToolCall, context: ExecutionContext<AuthContext>): import("rxjs").Observable<import("..").ContextAnyEvent | import("..").ContextEvent<import("..").ToolCompleteEvent>>;
|
|
15
|
-
getTool(name: string): Promise<ToolDefinition | undefined>;
|
|
16
|
-
validateToolArguments(toolCall: ToolCall): Promise<{
|
|
17
|
-
valid: boolean;
|
|
18
|
-
errors?: string[];
|
|
19
|
-
}>;
|
|
20
|
-
private validateRequiredParams;
|
|
21
|
-
private validateUnknownParams;
|
|
22
|
-
private validateParamTypes;
|
|
23
|
-
private checkParamType;
|
|
24
|
-
private getJsonSchemaType;
|
|
25
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { catchError, defer, mergeMap, of } from 'rxjs';
|
|
2
|
-
import { validateToolDefinitions, } from '../types/tools';
|
|
3
|
-
import { toolErrorEvent, toolResultToEvents } from './tool-result-events';
|
|
4
|
-
export class ClientToolProvider {
|
|
5
|
-
name = 'client-tool-provider';
|
|
6
|
-
tools;
|
|
7
|
-
toolNames;
|
|
8
|
-
onInputRequired;
|
|
9
|
-
constructor(config) {
|
|
10
|
-
try {
|
|
11
|
-
this.tools = validateToolDefinitions(config.tools);
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
if (error instanceof Error) {
|
|
15
|
-
throw new Error(`Invalid client tool definitions: ${error.message}`);
|
|
16
|
-
}
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
this.toolNames = new Set(this.tools.map((t) => t.name));
|
|
20
|
-
if (this.toolNames.size !== this.tools.length) {
|
|
21
|
-
const names = this.tools.map((t) => t.name);
|
|
22
|
-
const duplicates = names.filter((name, index) => names.indexOf(name) !== index);
|
|
23
|
-
throw new Error(`Duplicate tool names: ${duplicates.join(', ')}`);
|
|
24
|
-
}
|
|
25
|
-
this.onInputRequired = config.onInputRequired;
|
|
26
|
-
}
|
|
27
|
-
async getTools() {
|
|
28
|
-
return [...this.tools];
|
|
29
|
-
}
|
|
30
|
-
execute(toolCall, context) {
|
|
31
|
-
return defer(async () => {
|
|
32
|
-
const tool = await this.getTool(toolCall.function.name);
|
|
33
|
-
if (!tool) {
|
|
34
|
-
return {
|
|
35
|
-
toolCallId: toolCall.id,
|
|
36
|
-
toolName: toolCall.function.name,
|
|
37
|
-
success: false,
|
|
38
|
-
result: null,
|
|
39
|
-
error: `Tool ${toolCall.function.name} not found in client tools`,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
if (typeof toolCall.function.arguments !== 'object' ||
|
|
44
|
-
toolCall.function.arguments === null) {
|
|
45
|
-
return {
|
|
46
|
-
toolCallId: toolCall.id,
|
|
47
|
-
toolName: toolCall.function.name,
|
|
48
|
-
success: false,
|
|
49
|
-
result: null,
|
|
50
|
-
error: `Invalid tool arguments: must be an object.`,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const result = await this.onInputRequired(toolCall, context);
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
return {
|
|
58
|
-
toolCallId: toolCall.id,
|
|
59
|
-
toolName: toolCall.function.name,
|
|
60
|
-
success: false,
|
|
61
|
-
result: null,
|
|
62
|
-
error: error instanceof Error ? error.message : String(error),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}).pipe(mergeMap((result) => toolResultToEvents(context, toolCall, result)), catchError((error) => of(toolErrorEvent(context, toolCall, error instanceof Error ? error.message : String(error)))));
|
|
66
|
-
}
|
|
67
|
-
async getTool(name) {
|
|
68
|
-
return this.tools.find((t) => t.name === name);
|
|
69
|
-
}
|
|
70
|
-
async validateToolArguments(toolCall) {
|
|
71
|
-
const tool = await this.getTool(toolCall.function.name);
|
|
72
|
-
if (!tool) {
|
|
73
|
-
return { valid: false, errors: [`Tool ${toolCall.function.name} not found`] };
|
|
74
|
-
}
|
|
75
|
-
if (typeof toolCall.function.arguments !== 'object' || toolCall.function.arguments === null) {
|
|
76
|
-
return {
|
|
77
|
-
valid: false,
|
|
78
|
-
errors: ['Arguments are not valid: must be an object.'],
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const args = toolCall.function.arguments;
|
|
82
|
-
const errors = [];
|
|
83
|
-
this.validateRequiredParams(tool, args, errors);
|
|
84
|
-
this.validateUnknownParams(tool, args, errors);
|
|
85
|
-
this.validateParamTypes(tool, args, errors);
|
|
86
|
-
return errors.length > 0 ? { valid: false, errors } : { valid: true };
|
|
87
|
-
}
|
|
88
|
-
validateRequiredParams(tool, args, errors) {
|
|
89
|
-
const required = tool.parameters.required || [];
|
|
90
|
-
for (const param of required) {
|
|
91
|
-
if (!(param in args)) {
|
|
92
|
-
errors.push(`Missing required parameter: ${param}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
validateUnknownParams(tool, args, errors) {
|
|
97
|
-
if (tool.parameters.additionalProperties === false) {
|
|
98
|
-
const allowedParams = new Set(Object.keys(tool.parameters.properties));
|
|
99
|
-
for (const param of Object.keys(args)) {
|
|
100
|
-
if (!allowedParams.has(param)) {
|
|
101
|
-
errors.push(`Unknown parameter: ${param}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
validateParamTypes(tool, args, errors) {
|
|
107
|
-
for (const [paramName, paramValue] of Object.entries(args)) {
|
|
108
|
-
const schema = tool.parameters.properties[paramName];
|
|
109
|
-
if (!schema)
|
|
110
|
-
continue;
|
|
111
|
-
const type = schema.type;
|
|
112
|
-
if (!type)
|
|
113
|
-
continue;
|
|
114
|
-
const typeError = this.checkParamType(paramName, paramValue, type);
|
|
115
|
-
if (typeError) {
|
|
116
|
-
errors.push(typeError);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
checkParamType(paramName, paramValue, expectedType) {
|
|
121
|
-
const actualType = this.getJsonSchemaType(paramValue);
|
|
122
|
-
if (expectedType === 'integer') {
|
|
123
|
-
if (actualType !== 'number') {
|
|
124
|
-
return `Parameter ${paramName} has wrong type: expected integer, got ${actualType}`;
|
|
125
|
-
}
|
|
126
|
-
if (!Number.isInteger(paramValue)) {
|
|
127
|
-
return `Parameter ${paramName} must be an integer, got: ${paramValue}`;
|
|
128
|
-
}
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
if (actualType !== expectedType) {
|
|
132
|
-
return `Parameter ${paramName} has wrong type: expected ${expectedType}, got ${actualType}`;
|
|
133
|
-
}
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
getJsonSchemaType(value) {
|
|
137
|
-
if (Array.isArray(value))
|
|
138
|
-
return 'array';
|
|
139
|
-
if (value === null)
|
|
140
|
-
return 'null';
|
|
141
|
-
return typeof value;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
File without changes
|