@looopy-ai/core 2.1.20 → 2.1.22
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.js +1 -0
- package/dist/core/iteration.d.ts +1 -1
- package/dist/core/iteration.js +14 -5
- package/dist/core/loop.d.ts +1 -1
- package/dist/core/loop.js +1 -0
- package/dist/stores/messages/memory-message-store.js +2 -2
- package/dist/tools/agent-tool-provider.d.ts +3 -2
- package/dist/tools/agent-tool-provider.js +1 -0
- package/dist/tools/local-tools.d.ts +2 -2
- package/dist/tools/mcp-tool-provider.d.ts +2 -2
- package/dist/types/agent.d.ts +2 -1
- package/dist/types/core.d.ts +7 -4
- package/dist/utils/prompt.d.ts +1 -1
- package/dist/utils/prompt.js +2 -1
- package/package.json +8 -8
package/dist/core/agent.js
CHANGED
package/dist/core/iteration.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Observable } from 'rxjs';
|
|
2
|
-
import type
|
|
2
|
+
import { type IterationConfig, type IterationContext } from '../types/core';
|
|
3
3
|
import type { ContextAnyEvent } from '../types/event';
|
|
4
4
|
import type { LLMMessage } from '../types/message';
|
|
5
5
|
export declare const runIteration: <AuthContext>(context: IterationContext<AuthContext>, config: IterationConfig<AuthContext>, history: LLMMessage[]) => Observable<ContextAnyEvent>;
|
package/dist/core/iteration.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { concat, defer, filter, map, mergeMap, shareReplay } from 'rxjs';
|
|
2
2
|
import { startLLMCallSpan, startLoopIterationSpan } from '../observability/spans';
|
|
3
|
+
import { isToolPlugin, } from '../types/core';
|
|
3
4
|
import { getSystemPrompts } from '../utils/prompt';
|
|
4
5
|
import { runToolCall } from './tools';
|
|
5
6
|
export const runIteration = (context, config, history) => {
|
|
@@ -9,10 +10,18 @@ export const runIteration = (context, config, history) => {
|
|
|
9
10
|
});
|
|
10
11
|
const { traceContext: iterationContext, tapFinish: finishIterationSpan } = startLoopIterationSpan({ ...context, logger }, config.iterationNumber);
|
|
11
12
|
const llmEvents$ = defer(async () => {
|
|
12
|
-
const
|
|
13
|
+
const allowedPlugins = config.filterPlugins
|
|
14
|
+
? config.filterPlugins(context.plugins, context)
|
|
15
|
+
: context.plugins;
|
|
16
|
+
const systemPrompts = await getSystemPrompts(allowedPlugins, context);
|
|
13
17
|
const messages = await prepareMessages(systemPrompts, history);
|
|
14
|
-
const tools = await prepareTools(
|
|
15
|
-
logger.debug({
|
|
18
|
+
const tools = await prepareTools(allowedPlugins);
|
|
19
|
+
logger.debug({
|
|
20
|
+
systemPrompts,
|
|
21
|
+
messages: messages.length,
|
|
22
|
+
plugins: allowedPlugins.map((p) => p.name).join(', '),
|
|
23
|
+
tools: tools.map((t) => t.id).join(', '),
|
|
24
|
+
}, 'Prepared messages and tools for LLM call');
|
|
16
25
|
return { messages, tools, systemPrompts };
|
|
17
26
|
}).pipe(mergeMap(({ messages, tools, systemPrompts }) => {
|
|
18
27
|
const { tapFinish: finishLLMCallSpan } = startLLMCallSpan({ ...context, parentContext: iterationContext }, systemPrompts, messages, tools);
|
|
@@ -59,8 +68,8 @@ const prepareMessages = async (systemPrompts, history) => {
|
|
|
59
68
|
content: sp.content,
|
|
60
69
|
})));
|
|
61
70
|
};
|
|
62
|
-
const prepareTools = async (
|
|
63
|
-
const toolPromises =
|
|
71
|
+
const prepareTools = async (plugins) => {
|
|
72
|
+
const toolPromises = plugins.filter(isToolPlugin).map((p) => p.listTools());
|
|
64
73
|
const toolArrays = await Promise.all(toolPromises);
|
|
65
74
|
return toolArrays.filter(Boolean).flat();
|
|
66
75
|
};
|
package/dist/core/loop.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { LoopConfig, LoopContext } from '../types/core';
|
|
2
2
|
import type { ContextAnyEvent } from '../types/event';
|
|
3
3
|
import type { LLMMessage } from '../types/message';
|
|
4
|
-
export declare const runLoop: <AuthContext>(context: LoopContext<AuthContext>, config: LoopConfig
|
|
4
|
+
export declare const runLoop: <AuthContext>(context: LoopContext<AuthContext>, config: LoopConfig<AuthContext>, history: LLMMessage[]) => import("rxjs").Observable<ContextAnyEvent>;
|
package/dist/core/loop.js
CHANGED
|
@@ -35,6 +35,7 @@ export const runLoop = (context, config, history) => {
|
|
|
35
35
|
}, (state) => runIteration({ ...context, parentContext: loopContext }, {
|
|
36
36
|
llmProvider: config.llmProvider,
|
|
37
37
|
iterationNumber: state.iteration,
|
|
38
|
+
filterPlugins: config.filterPlugins,
|
|
38
39
|
}, state.messages), (state, { events }) => ({
|
|
39
40
|
...state,
|
|
40
41
|
messages: [...state.messages, ...eventsToMessages(events)],
|
|
@@ -26,10 +26,10 @@ export class InMemoryMessageStore {
|
|
|
26
26
|
if (maxTokens) {
|
|
27
27
|
messages = trimToTokenBudget(messages, maxTokens);
|
|
28
28
|
}
|
|
29
|
-
return messages;
|
|
29
|
+
return messages.slice();
|
|
30
30
|
}
|
|
31
31
|
async getAll(contextId) {
|
|
32
|
-
return this.messages.get(contextId) || [];
|
|
32
|
+
return (this.messages.get(contextId) || []).slice();
|
|
33
33
|
}
|
|
34
34
|
async getCount(contextId) {
|
|
35
35
|
const messages = this.messages.get(contextId) || [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import z from 'zod';
|
|
3
|
-
import type { AnyEvent, ExecutionContext,
|
|
3
|
+
import type { AnyEvent, ExecutionContext, ToolPlugin } from '../types';
|
|
4
4
|
import type { ToolCall, ToolDefinition } from '../types/tools';
|
|
5
5
|
export type HeaderFactory<AuthContext> = (context: ExecutionContext<AuthContext>, card: AgentCard) => Promise<Record<string, string | undefined>>;
|
|
6
6
|
export declare const cardSchema: z.ZodObject<{
|
|
@@ -16,9 +16,10 @@ export declare const cardSchema: z.ZodObject<{
|
|
|
16
16
|
token_endpoint: z.ZodString;
|
|
17
17
|
scopes: z.ZodArray<z.ZodString>;
|
|
18
18
|
}, z.core.$loose>>;
|
|
19
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
19
20
|
}, z.core.$strip>;
|
|
20
21
|
export type AgentCard = z.infer<typeof cardSchema>;
|
|
21
|
-
export declare class AgentToolProvider<AuthContext> implements
|
|
22
|
+
export declare class AgentToolProvider<AuthContext> implements ToolPlugin<AuthContext> {
|
|
22
23
|
readonly card: AgentCard;
|
|
23
24
|
readonly getHeaders?: HeaderFactory<AuthContext> | undefined;
|
|
24
25
|
static fromUrl: <AuthContext_1>(cardUrl: string, getHeaders?: HeaderFactory<AuthContext_1>) => Promise<AgentToolProvider<AuthContext_1>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ExecutionContext } from '../types/context';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ToolPlugin } from '../types/core';
|
|
4
4
|
import type { ToolResult } from '../types/tools';
|
|
5
5
|
type InternalToolResult = Omit<ToolResult, 'toolCallId' | 'toolName'>;
|
|
6
6
|
export type ToolHandler<TParams, AuthContext> = (params: TParams, context: ExecutionContext<AuthContext>) => Promise<InternalToolResult> | InternalToolResult;
|
|
@@ -12,5 +12,5 @@ export interface LocalToolDefinition<TSchema extends z.ZodObject, AuthContext> {
|
|
|
12
12
|
handler: ToolHandler<z.infer<TSchema>, AuthContext>;
|
|
13
13
|
}
|
|
14
14
|
export declare function tool<TSchema extends z.ZodObject, AuthContext>(definition: LocalToolDefinition<TSchema, AuthContext>): LocalToolDefinition<TSchema, AuthContext>;
|
|
15
|
-
export declare function localTools<AuthContext>(tools: LocalToolDefinition<z.ZodObject, AuthContext>[]):
|
|
15
|
+
export declare function localTools<AuthContext>(tools: LocalToolDefinition<z.ZodObject, AuthContext>[]): ToolPlugin<AuthContext>;
|
|
16
16
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ToolPlugin } from '..';
|
|
2
2
|
import type { ExecutionContext } from '../types/context';
|
|
3
3
|
import type { ToolCall, ToolDefinition } from '../types/tools';
|
|
4
4
|
export interface MCPProviderConfig<AuthContext> {
|
|
@@ -8,7 +8,7 @@ export interface MCPProviderConfig<AuthContext> {
|
|
|
8
8
|
getHeaders: (authContext?: AuthContext) => Record<string, string>;
|
|
9
9
|
}
|
|
10
10
|
export declare const mcp: <AuthContext>(config: MCPProviderConfig<AuthContext>) => McpToolProvider<AuthContext>;
|
|
11
|
-
export declare class McpToolProvider<AuthContext> implements
|
|
11
|
+
export declare class McpToolProvider<AuthContext> implements ToolPlugin<AuthContext> {
|
|
12
12
|
name: string;
|
|
13
13
|
readonly id: string;
|
|
14
14
|
private readonly client;
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { MessageStore } from '../stores/messages';
|
|
2
2
|
import type { SerializedError } from '../utils/error';
|
|
3
|
-
import type { Plugin } from './core';
|
|
3
|
+
import type { FilterPlugins, Plugin } from './core';
|
|
4
4
|
import type { LLMProvider } from './llm';
|
|
5
5
|
export interface AgentConfig<AuthContext> {
|
|
6
6
|
agentId: string;
|
|
7
7
|
contextId: string;
|
|
8
8
|
llmProvider: LLMProvider;
|
|
9
|
+
filterPlugins?: FilterPlugins<AuthContext>;
|
|
9
10
|
messageStore: MessageStore;
|
|
10
11
|
agentStore?: AgentStore;
|
|
11
12
|
autoCompact?: boolean;
|
package/dist/types/core.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Observable } from 'rxjs';
|
|
|
3
3
|
import type { LLMProvider } from '../types/llm';
|
|
4
4
|
import type { AnyEvent, ContextAnyEvent } from './event';
|
|
5
5
|
import type { ToolCall, ToolDefinition } from './tools';
|
|
6
|
+
export type FilterPlugins<AuthContext> = (availablePlugins: readonly Plugin<AuthContext>[], context: IterationContext<AuthContext>) => readonly Plugin<AuthContext>[];
|
|
6
7
|
export type AgentContext<AuthContext> = Readonly<{
|
|
7
8
|
agentId: string;
|
|
8
9
|
contextId: string;
|
|
@@ -18,25 +19,27 @@ export type TurnContext<AuthContext> = AgentContext<AuthContext> & Readonly<{
|
|
|
18
19
|
}>;
|
|
19
20
|
export type LoopContext<AuthContext> = TurnContext<AuthContext>;
|
|
20
21
|
export type IterationContext<AuthContext> = TurnContext<AuthContext>;
|
|
21
|
-
export type LoopConfig = {
|
|
22
|
+
export type LoopConfig<AuthContext> = {
|
|
23
|
+
filterPlugins: FilterPlugins<AuthContext> | undefined;
|
|
22
24
|
llmProvider: LLMProvider;
|
|
23
25
|
maxIterations: number;
|
|
24
26
|
stopOnToolError: boolean;
|
|
25
27
|
};
|
|
26
28
|
export type IterationConfig<AuthContext> = {
|
|
29
|
+
filterPlugins: FilterPlugins<AuthContext> | undefined;
|
|
27
30
|
llmProvider: LLMProvider | ((context: LoopContext<AuthContext>, systemPromptMetadata: Record<string, unknown> | undefined) => LLMProvider);
|
|
28
31
|
iterationNumber: number;
|
|
29
32
|
};
|
|
30
|
-
export type Plugin<AuthContext> =
|
|
33
|
+
export type Plugin<AuthContext> = SystemPromptPlugin<AuthContext> | ToolPlugin<AuthContext>;
|
|
31
34
|
type BasePlugin = {
|
|
32
35
|
readonly name: string;
|
|
33
36
|
readonly version?: string;
|
|
34
37
|
};
|
|
35
|
-
export type SystemPromptPlugin<AuthContext> = {
|
|
38
|
+
export type SystemPromptPlugin<AuthContext> = BasePlugin & {
|
|
36
39
|
generateSystemPrompts: (context: IterationContext<AuthContext>) => SystemPrompt[] | Promise<SystemPrompt[]>;
|
|
37
40
|
};
|
|
38
41
|
export declare const isSystemPromptPlugin: <AuthContext>(plugin: Plugin<AuthContext>) => plugin is BasePlugin & SystemPromptPlugin<AuthContext>;
|
|
39
|
-
export type ToolPlugin<AuthContext> = {
|
|
42
|
+
export type ToolPlugin<AuthContext> = BasePlugin & {
|
|
40
43
|
listTools: () => Promise<ToolDefinition[]>;
|
|
41
44
|
getTool: (toolId: string) => Promise<ToolDefinition | undefined>;
|
|
42
45
|
executeTool: (toolCall: ToolCall, context: IterationContext<AuthContext>) => Observable<ContextAnyEvent | AnyEvent>;
|
package/dist/utils/prompt.d.ts
CHANGED
package/dist/utils/prompt.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { isSystemPromptPlugin, } from '../types/core';
|
|
1
2
|
export const getSystemPrompts = async (plugins, loopContext) => {
|
|
2
3
|
if (!plugins?.length) {
|
|
3
4
|
return { before: [], after: [] };
|
|
4
5
|
}
|
|
5
|
-
const prompts = await Promise.all(plugins.map((p) => p.generateSystemPrompts?.(loopContext)));
|
|
6
|
+
const prompts = await Promise.all(plugins.filter(isSystemPromptPlugin).map((p) => p.generateSystemPrompts?.(loopContext)));
|
|
6
7
|
const flattened = prompts.flat().filter((p) => p !== undefined);
|
|
7
8
|
const before = Object.freeze(flattened
|
|
8
9
|
.filter((p) => p.position === 'before')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@looopy-ai/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.22",
|
|
4
4
|
"description": "RxJS-based AI agent framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://github.com/looopy-ai/lib"
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.207.0",
|
|
35
35
|
"@opentelemetry/exporter-trace-otlp-http": "^0.207.0",
|
|
36
36
|
"@opentelemetry/instrumentation": "^0.207.0",
|
|
37
|
-
"@opentelemetry/resources": "^2.
|
|
38
|
-
"@opentelemetry/sdk-metrics": "^2.
|
|
39
|
-
"@opentelemetry/sdk-trace-base": "^2.
|
|
40
|
-
"@opentelemetry/sdk-trace-node": "^2.
|
|
41
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
37
|
+
"@opentelemetry/resources": "^2.4.0",
|
|
38
|
+
"@opentelemetry/sdk-metrics": "^2.4.0",
|
|
39
|
+
"@opentelemetry/sdk-trace-base": "^2.4.0",
|
|
40
|
+
"@opentelemetry/sdk-trace-node": "^2.4.0",
|
|
41
|
+
"@opentelemetry/semantic-conventions": "^1.39.0",
|
|
42
42
|
"pino": "^9.14.0",
|
|
43
|
-
"pino-pretty": "^13.1.
|
|
43
|
+
"pino-pretty": "^13.1.3",
|
|
44
44
|
"rxjs": "^7.8.2",
|
|
45
|
-
"zod": "^4.
|
|
45
|
+
"zod": "^4.3.5"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|