@looopy-ai/core 2.1.22 → 2.1.24
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.
|
@@ -76,16 +76,16 @@ export function initializeTracing(config) {
|
|
|
76
76
|
}
|
|
77
77
|
const serviceName = config?.serviceName || 'looopy';
|
|
78
78
|
const serviceVersion = config?.serviceVersion || '1.0.0';
|
|
79
|
-
const
|
|
79
|
+
const stage = config?.stage || process.env.STAGE || 'dev';
|
|
80
80
|
DEFAULT_LOGGER.trace({
|
|
81
81
|
serviceName,
|
|
82
82
|
serviceVersion,
|
|
83
|
-
|
|
83
|
+
stage,
|
|
84
84
|
}, 'Initializing OpenTelemetry tracing');
|
|
85
85
|
const resource = resourceFromAttributes({
|
|
86
86
|
[ATTR_SERVICE_NAME]: serviceName,
|
|
87
87
|
[ATTR_SERVICE_VERSION]: serviceVersion,
|
|
88
|
-
'deployment.environment':
|
|
88
|
+
'deployment.environment': stage,
|
|
89
89
|
});
|
|
90
90
|
const otlpEndpoint = config?.otlpEndpoint ||
|
|
91
91
|
process.env.OTEL_EXPORTER_OTLP_ENDPOINT ||
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Skill } from '../types';
|
|
1
|
+
import type { MaterializedSkill, Skill } from '../types';
|
|
2
2
|
import type { IterationContext, Plugin, SystemPrompt } from '../types/core';
|
|
3
3
|
export declare const learnSkillToolName = "learn_skill";
|
|
4
4
|
export declare const getInstruction: (instruction: string | (() => Promise<string>)) => Promise<string>;
|
|
5
5
|
export declare const skill: (definition: Skill) => Skill;
|
|
6
6
|
export type AgentAcademyOptions<AuthContext> = {
|
|
7
|
-
learnSkillPrompt?: (skills:
|
|
7
|
+
learnSkillPrompt?: (skills: MaterializedSkill[], context: IterationContext<AuthContext>) => Promise<string | SystemPrompt>;
|
|
8
8
|
};
|
|
9
9
|
export declare function agentAcademy<AuthContext>(skills: Skill[], options?: AgentAcademyOptions<AuthContext>): Plugin<AuthContext>;
|
|
@@ -12,13 +12,6 @@ export const skill = (definition) => {
|
|
|
12
12
|
return { ...definition };
|
|
13
13
|
};
|
|
14
14
|
export function agentAcademy(skills, options) {
|
|
15
|
-
const skillMap = new Map();
|
|
16
|
-
for (const skill of skills) {
|
|
17
|
-
if (skillMap.has(skill.name)) {
|
|
18
|
-
throw new Error(`Duplicate skill name: ${skill.name}`);
|
|
19
|
-
}
|
|
20
|
-
skillMap.set(skill.name, skill);
|
|
21
|
-
}
|
|
22
15
|
const learnSkillToolDefinition = {
|
|
23
16
|
id: learnSkillToolName,
|
|
24
17
|
description: 'Learns a new skill from the available agent academy.',
|
|
@@ -35,13 +28,18 @@ export function agentAcademy(skills, options) {
|
|
|
35
28
|
},
|
|
36
29
|
};
|
|
37
30
|
const learnSkillPromptFn = options?.learnSkillPrompt ?? defaultPrompt;
|
|
31
|
+
const materializedSkillsPromises = skills.map(async (s) => ({
|
|
32
|
+
...s,
|
|
33
|
+
instruction: await getInstruction(s.instruction),
|
|
34
|
+
}));
|
|
35
|
+
const materializedSkills = Promise.all(materializedSkillsPromises);
|
|
38
36
|
return {
|
|
39
37
|
name: 'agent-academy',
|
|
40
38
|
generateSystemPrompts: async (context) => {
|
|
41
39
|
if (!learnSkillPromptFn) {
|
|
42
40
|
return [];
|
|
43
41
|
}
|
|
44
|
-
const prompt = await learnSkillPromptFn(
|
|
42
|
+
const prompt = await learnSkillPromptFn(await materializedSkills, context);
|
|
45
43
|
if (typeof prompt === 'string') {
|
|
46
44
|
return [
|
|
47
45
|
{
|
|
@@ -82,6 +80,7 @@ export function agentAcademy(skills, options) {
|
|
|
82
80
|
name: z.string().describe('The name of the skill to learn.'),
|
|
83
81
|
});
|
|
84
82
|
const validatedParams = schema.parse(toolCall.function.arguments);
|
|
83
|
+
const skillMap = buildMaterializedSkillMap(await materializedSkills);
|
|
85
84
|
const foundSkill = skillMap.get(validatedParams.name);
|
|
86
85
|
if (!foundSkill) {
|
|
87
86
|
const availableSkills = Array.from(skillMap.values())
|
|
@@ -129,9 +128,14 @@ export function agentAcademy(skills, options) {
|
|
|
129
128
|
}).pipe(mergeMap((result) => toolResultToEvents(result)), catchError((error) => of(toolErrorEvent(toolCall, error instanceof Error ? error.message : String(error))))),
|
|
130
129
|
};
|
|
131
130
|
}
|
|
131
|
+
const buildMaterializedSkillMap = (skills) => {
|
|
132
|
+
const map = new Map();
|
|
133
|
+
skills.forEach((skill) => {
|
|
134
|
+
map.set(skill.name, skill);
|
|
135
|
+
});
|
|
136
|
+
return map;
|
|
137
|
+
};
|
|
132
138
|
const defaultPrompt = (skills) => {
|
|
133
|
-
const skillList = skills
|
|
134
|
-
.map((skill) => `- **${skill.name}**: ${typeof skill.instruction === 'string' ? skill.instruction : 'A useful skill.'}`)
|
|
135
|
-
.join('\n');
|
|
139
|
+
const skillList = skills.map((skill) => `- **${skill.name}**: ${skill.instruction}`).join('\n');
|
|
136
140
|
return `You can learn new skills using the learn_skill tool. The available skills are:\n\n${skillList}\n\nTo learn a skill, call the learn_skill tool with the name of the skill you want to learn.`;
|
|
137
141
|
};
|
package/dist/types/skills.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export interface Skill {
|
|
|
3
3
|
description: string;
|
|
4
4
|
instruction: string | (() => Promise<string>);
|
|
5
5
|
}
|
|
6
|
+
export interface MaterializedSkill {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
instruction: string;
|
|
10
|
+
}
|
|
6
11
|
export interface SkillRegistration {
|
|
7
12
|
[key: string]: Skill;
|
|
8
13
|
}
|