@looopy-ai/core 1.2.0 → 1.2.1
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/iteration.js
CHANGED
|
@@ -10,11 +10,11 @@ export const runIteration = (context, config, history) => {
|
|
|
10
10
|
const { traceContext: iterationContext, tapFinish: finishIterationSpan } = startLoopIterationSpan({ ...context, logger }, config.iterationNumber);
|
|
11
11
|
const llmEvents$ = defer(async () => {
|
|
12
12
|
const systemPrompt = await getSystemPrompt(context.systemPrompt);
|
|
13
|
-
const messages = await prepareMessages(systemPrompt, context.
|
|
13
|
+
const messages = await prepareMessages(systemPrompt, context.skillRegistry, history);
|
|
14
14
|
const tools = await prepareTools(context.toolProviders);
|
|
15
15
|
return { messages, tools, systemPrompt };
|
|
16
16
|
}).pipe(mergeMap(({ messages, tools, systemPrompt }) => {
|
|
17
|
-
const { tapFinish: finishLLMCallSpan } = startLLMCallSpan({ ...context, parentContext: iterationContext }, systemPrompt, messages);
|
|
17
|
+
const { tapFinish: finishLLMCallSpan } = startLLMCallSpan({ ...context, parentContext: iterationContext }, systemPrompt, messages, tools);
|
|
18
18
|
return config.llmProvider
|
|
19
19
|
.call({
|
|
20
20
|
messages,
|
|
@@ -35,22 +35,23 @@ export const runIteration = (context, config, history) => {
|
|
|
35
35
|
}, event)));
|
|
36
36
|
return concat(llmEvents$.pipe(filter((event) => event.kind !== 'tool-call')), toolEvents$).pipe(finishIterationSpan);
|
|
37
37
|
};
|
|
38
|
-
const prepareMessages = async (systemPrompt,
|
|
38
|
+
const prepareMessages = async (systemPrompt, skillRegistry, history) => {
|
|
39
39
|
const messages = [];
|
|
40
40
|
if (systemPrompt) {
|
|
41
41
|
messages.push({
|
|
42
42
|
role: 'system',
|
|
43
43
|
content: systemPrompt.prompt,
|
|
44
|
-
name: systemPrompt.name || 'system-prompt',
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
if (skillRegistry) {
|
|
47
|
+
const skills = skillRegistry.list();
|
|
48
|
+
if (skills.length > 0) {
|
|
49
|
+
const skillList = skills.map((s) => `- **${s.name}**: ${s.description}`).join('\n');
|
|
50
|
+
const skillMessage = {
|
|
50
51
|
role: 'system',
|
|
51
|
-
content
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
content: `You can learn new skills by using the 'learn_skill' tool. Available skills:\n\n${skillList}`,
|
|
53
|
+
};
|
|
54
|
+
messages.push(skillMessage);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
return messages.concat(history);
|
package/dist/core/loop.js
CHANGED
|
@@ -27,20 +27,8 @@ export const runLoop = (context, config, history) => {
|
|
|
27
27
|
status: 'working',
|
|
28
28
|
metadata: {},
|
|
29
29
|
});
|
|
30
|
-
const initialMessages = [...history];
|
|
31
|
-
if (context.skillRegistry) {
|
|
32
|
-
const skills = context.skillRegistry.list();
|
|
33
|
-
if (skills.length > 0) {
|
|
34
|
-
const skillList = skills.map((s) => `- **${s.name}**: ${s.description}`).join('\n');
|
|
35
|
-
const skillMessage = {
|
|
36
|
-
role: 'system',
|
|
37
|
-
content: `You can learn new skills by using the 'learn_skill' tool. Available skills:\n\n${skillList}`,
|
|
38
|
-
};
|
|
39
|
-
initialMessages.unshift(skillMessage);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
30
|
const merged$ = recursiveMerge({
|
|
43
|
-
messages:
|
|
31
|
+
messages: history,
|
|
44
32
|
completed: false,
|
|
45
33
|
iteration: 0,
|
|
46
34
|
}, (state) => runIteration({ ...context, parentContext: loopContext }, {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../..';
|
|
1
2
|
import type { LoopContext } from '../../core/types';
|
|
2
3
|
import type { AnyEvent } from '../../types/event';
|
|
3
4
|
import type { Message } from '../../types/message';
|
|
@@ -8,7 +9,7 @@ export interface LLMCallSpanParams {
|
|
|
8
9
|
messages: Message[];
|
|
9
10
|
parentContext: import('@opentelemetry/api').Context;
|
|
10
11
|
}
|
|
11
|
-
export declare const startLLMCallSpan: (context: LoopContext, systemPrompt: SystemPrompt | undefined, messages: Message[]) => {
|
|
12
|
+
export declare const startLLMCallSpan: (context: LoopContext, systemPrompt: SystemPrompt | undefined, messages: Message[], tools: ToolDefinition[]) => {
|
|
12
13
|
span: import("@opentelemetry/api").Span;
|
|
13
14
|
traceContext: import("@opentelemetry/api").Context;
|
|
14
15
|
tapFinish: import("rxjs").MonoTypeOperatorFunction<AnyEvent>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SpanStatusCode, trace } from '@opentelemetry/api';
|
|
2
2
|
import { tap } from 'rxjs/internal/operators/tap';
|
|
3
3
|
import { SpanAttributes, SpanNames } from '../tracing';
|
|
4
|
-
export const startLLMCallSpan = (context, systemPrompt, messages) => {
|
|
4
|
+
export const startLLMCallSpan = (context, systemPrompt, messages, tools) => {
|
|
5
5
|
const tracer = trace.getTracer('looopy');
|
|
6
6
|
const span = tracer.startSpan(SpanNames.LLM_CALL, {
|
|
7
7
|
attributes: {
|
|
@@ -11,6 +11,7 @@ export const startLLMCallSpan = (context, systemPrompt, messages) => {
|
|
|
11
11
|
[SpanAttributes.LANGFUSE_OBSERVATION_TYPE]: 'generation',
|
|
12
12
|
[SpanAttributes.LANGFUSE_PROMPT_NAME]: systemPrompt?.name,
|
|
13
13
|
[SpanAttributes.LANGFUSE_PROMPT_VERSION]: systemPrompt?.version,
|
|
14
|
+
'tools.available': tools.map((t) => t.name),
|
|
14
15
|
},
|
|
15
16
|
}, context.parentContext);
|
|
16
17
|
const traceContext = trace.setSpan(context.parentContext, span);
|
package/dist/skills/registry.js
CHANGED
|
@@ -29,6 +29,7 @@ export class SkillRegistry {
|
|
|
29
29
|
tool() {
|
|
30
30
|
return tool({
|
|
31
31
|
name: learnSkillToolName,
|
|
32
|
+
icon: 'lucide:graduation-cap',
|
|
32
33
|
description: 'Learns a new skill from the available skill registry.',
|
|
33
34
|
schema: z.object({
|
|
34
35
|
name: z.string().describe('The name of the skill to learn.'),
|