@easynet/agent-runtime 1.0.3 → 1.0.4
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/.github/workflows/ci.yml +9 -24
- package/.github/workflows/release.yml +14 -35
- package/agent-runtime/.github/workflows/ci.yml +69 -0
- package/agent-runtime/.github/workflows/release.yml +118 -0
- package/agent-runtime/.releaserc.cjs +26 -0
- package/agent-runtime/config/agent.deep.yaml +25 -0
- package/agent-runtime/config/agent.react.yaml +24 -0
- package/agent-runtime/example/basic-usage.ts +49 -0
- package/agent-runtime/package-lock.json +7740 -0
- package/agent-runtime/package.json +49 -0
- package/agent-runtime/pnpm-lock.yaml +3712 -0
- package/agent-runtime/scripts/resolve-deps.js +54 -0
- package/agent-runtime/src/agents/deep-agent.ts +165 -0
- package/agent-runtime/src/agents/react-agent.helpers.ts +227 -0
- package/agent-runtime/src/agents/react-agent.ts +584 -0
- package/{src → agent-runtime/src/agents}/sub-agent.ts +2 -2
- package/agent-runtime/src/cli/args.ts +15 -0
- package/agent-runtime/src/cli/event-listener.ts +162 -0
- package/agent-runtime/src/cli/interactive.ts +144 -0
- package/agent-runtime/src/cli/runtime.ts +31 -0
- package/agent-runtime/src/cli/spinner.ts +23 -0
- package/agent-runtime/src/cli/terminal-render.ts +322 -0
- package/agent-runtime/src/cli/types.ts +33 -0
- package/agent-runtime/src/cli.ts +134 -0
- package/agent-runtime/src/config/helpers.ts +179 -0
- package/agent-runtime/src/config/index.ts +245 -0
- package/agent-runtime/src/config/types.ts +62 -0
- package/agent-runtime/src/core/context.ts +266 -0
- package/agent-runtime/src/index.ts +55 -0
- package/agent-runtime/tsconfig.json +18 -0
- package/apps/imessagebot/README.md +38 -0
- package/apps/imessagebot/config/.agent/cache/easynet/agent-tool-buildin/0.0.45/README.md +33 -0
- package/apps/imessagebot/config/.agent/cache/easynet/agent-tool-buildin/0.0.45/package-lock.json +15257 -0
- package/apps/imessagebot/config/.agent/cache/easynet/agent-tool-buildin/0.0.45/package.json +55 -0
- package/apps/imessagebot/config/agents/deep/agent.yaml +31 -0
- package/apps/imessagebot/config/agents/react/agent.yaml +58 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.43/README.md +33 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.43/package-lock.json +15457 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.43/package.json +55 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.46/README.md +33 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.46/package-lock.json +15257 -0
- package/apps/imessagebot/config/agents/shared/.agent/cache/easynet/agent-tool-buildin/0.0.46/package.json +62 -0
- package/apps/imessagebot/config/agents/shared/memory.yaml +31 -0
- package/apps/imessagebot/config/agents/shared/model.yaml +23 -0
- package/apps/imessagebot/config/agents/shared/tool.yaml +13 -0
- package/apps/imessagebot/config/app.yaml +14 -0
- package/apps/imessagebot/package-lock.json +53695 -0
- package/apps/imessagebot/package.json +41 -0
- package/apps/imessagebot/pnpm-lock.yaml +1589 -0
- package/apps/imessagebot/scripts/resolve-deps.js +41 -0
- package/apps/imessagebot/scripts/test-llm.mjs +27 -0
- package/apps/imessagebot/scripts/validate-tools-config.mjs +174 -0
- package/apps/imessagebot/src/config.ts +76 -0
- package/apps/imessagebot/src/context.ts +35 -0
- package/apps/imessagebot/src/index.ts +17 -0
- package/apps/imessagebot/tsconfig.json +18 -0
- package/apps/itermbot/.github/workflows/ci.yml +61 -0
- package/apps/itermbot/.github/workflows/release.yml +80 -0
- package/apps/itermbot/.releaserc.cjs +26 -0
- package/apps/itermbot/README.md +82 -0
- package/apps/itermbot/config/app.yaml +29 -0
- package/apps/itermbot/config/tsconfig.json +18 -0
- package/apps/itermbot/macos_disk_usage_agent_plan.md +244 -0
- package/apps/itermbot/package-lock.json +53697 -0
- package/apps/itermbot/package.json +57 -0
- package/apps/itermbot/pnpm-lock.yaml +3966 -0
- package/apps/itermbot/scripts/patch-buildin-cache.sh +25 -0
- package/apps/itermbot/scripts/resolve-deps.js +41 -0
- package/apps/itermbot/scripts/test-llm.mjs +32 -0
- package/apps/itermbot/skills/command-explain-and-guard/SKILL.md +39 -0
- package/apps/itermbot/skills/command-explain-and-guard/handler.js +86 -0
- package/apps/itermbot/skills/disk-usage-investigate/SKILL.md +44 -0
- package/apps/itermbot/skills/disk-usage-investigate/handler.js +12 -0
- package/apps/itermbot/skills/gpu-ssh-monitor/SKILL.md +64 -0
- package/apps/itermbot/skills/repo-triage/SKILL.md +40 -0
- package/apps/itermbot/skills/repo-triage/handler.js +56 -0
- package/apps/itermbot/skills/test-failure-diagnose/SKILL.md +43 -0
- package/apps/itermbot/skills/test-failure-diagnose/handler.js +107 -0
- package/apps/itermbot/src/config.ts +95 -0
- package/apps/itermbot/src/context.ts +35 -0
- package/apps/itermbot/src/index.ts +223 -0
- package/apps/itermbot/src/iterm/session-hint.ts +40 -0
- package/apps/itermbot/src/iterm/target-routing.ts +419 -0
- package/apps/itermbot/src/startup/colors.ts +317 -0
- package/apps/itermbot/src/startup/diagnostics.ts +97 -0
- package/apps/itermbot/src/startup/ui.ts +141 -0
- package/config/agent.deep.yaml +25 -0
- package/config/agent.react.yaml +24 -0
- package/dist/agents/deep-agent.d.ts +37 -0
- package/dist/agents/deep-agent.d.ts.map +1 -0
- package/dist/agents/deep-agent.js +115 -0
- package/dist/agents/deep-agent.js.map +1 -0
- package/dist/agents/react-agent.d.ts +40 -0
- package/dist/agents/react-agent.d.ts.map +1 -0
- package/dist/agents/react-agent.helpers.d.ts +40 -0
- package/dist/agents/react-agent.helpers.d.ts.map +1 -0
- package/dist/agents/react-agent.helpers.js +196 -0
- package/dist/agents/react-agent.helpers.js.map +1 -0
- package/dist/agents/react-agent.js +400 -0
- package/dist/agents/react-agent.js.map +1 -0
- package/dist/agents/sub-agent.d.ts +34 -0
- package/dist/agents/sub-agent.d.ts.map +1 -0
- package/dist/agents/sub-agent.js +53 -0
- package/dist/agents/sub-agent.js.map +1 -0
- package/dist/cli/args.d.ts +8 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +9 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/event-listener.d.ts +3 -0
- package/dist/cli/event-listener.d.ts.map +1 -0
- package/dist/cli/event-listener.js +131 -0
- package/dist/cli/event-listener.js.map +1 -0
- package/dist/cli/interactive.d.ts +4 -0
- package/dist/cli/interactive.d.ts.map +1 -0
- package/dist/cli/interactive.js +118 -0
- package/dist/cli/interactive.js.map +1 -0
- package/dist/cli/runtime.d.ts +8 -0
- package/dist/cli/runtime.d.ts.map +1 -0
- package/dist/cli/runtime.js +27 -0
- package/dist/cli/runtime.js.map +1 -0
- package/dist/cli/spinner.d.ts +2 -0
- package/dist/cli/spinner.d.ts.map +1 -0
- package/dist/cli/spinner.js +22 -0
- package/dist/cli/spinner.js.map +1 -0
- package/dist/cli/terminal-render.d.ts +7 -0
- package/dist/cli/terminal-render.d.ts.map +1 -0
- package/dist/cli/terminal-render.js +282 -0
- package/dist/cli/terminal-render.js.map +1 -0
- package/dist/cli/types.d.ts +29 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +3 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli.d.ts +4 -41
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +84 -588
- package/dist/cli.js.map +1 -1
- package/dist/config/helpers.d.ts +6 -0
- package/dist/config/helpers.d.ts.map +1 -0
- package/dist/config/helpers.js +164 -0
- package/dist/config/helpers.js.map +1 -0
- package/dist/config/index.d.ts +15 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +160 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +57 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/context.d.ts +8 -69
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +44 -24
- package/dist/context.js.map +1 -1
- package/dist/core/context.d.ts +66 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +149 -0
- package/dist/core/context.js.map +1 -0
- package/dist/deep-agent.d.ts +5 -2
- package/dist/deep-agent.d.ts.map +1 -1
- package/dist/deep-agent.js +44 -11
- package/dist/deep-agent.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/middleware/malformed-tool-call-middleware.d.ts +8 -0
- package/dist/middleware/malformed-tool-call-middleware.d.ts.map +1 -0
- package/dist/middleware/malformed-tool-call-middleware.js +191 -0
- package/dist/middleware/malformed-tool-call-middleware.js.map +1 -0
- package/dist/react-agent.d.ts +2 -2
- package/dist/react-agent.d.ts.map +1 -1
- package/dist/react-agent.js +28 -9
- package/dist/react-agent.js.map +1 -1
- package/package.json +1 -1
- package/scripts/resolve-deps.js +54 -0
- package/src/agents/deep-agent.ts +165 -0
- package/src/agents/react-agent.helpers.ts +227 -0
- package/src/agents/react-agent.ts +584 -0
- package/src/agents/sub-agent.ts +82 -0
- package/src/cli/args.ts +15 -0
- package/src/cli/event-listener.ts +162 -0
- package/src/cli/interactive.ts +144 -0
- package/src/cli/runtime.ts +31 -0
- package/src/cli/spinner.ts +23 -0
- package/src/cli/terminal-render.ts +322 -0
- package/src/cli/types.ts +33 -0
- package/src/cli.ts +91 -702
- package/src/config/helpers.ts +179 -0
- package/src/config/index.ts +245 -0
- package/src/config/types.ts +62 -0
- package/src/core/context.ts +266 -0
- package/src/index.ts +13 -11
- package/src/middleware/malformed-tool-call-middleware.ts +239 -0
- package/src/types/markdown-it-terminal.d.ts +4 -0
- package/src/types/marked-terminal.d.ts +16 -0
- package/dist/config.d.ts +0 -86
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -84
- package/dist/config.js.map +0 -1
- package/src/config.ts +0 -177
- package/src/context.ts +0 -247
- package/src/deep-agent.ts +0 -104
- package/src/react-agent.ts +0 -576
- /package/{src → agent-runtime/src/middleware}/malformed-tool-call-middleware.ts +0 -0
- /package/{src → agent-runtime/src/types}/markdown-it-terminal.d.ts +0 -0
- /package/{src → agent-runtime/src/types}/marked-terminal.d.ts +0 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { createAgentModelRegistry } from "@easynet/agent-model";
|
|
2
|
+
import { createAgentMemory as createMemoryClient } from "@easynet/agent-memory/internal";
|
|
3
|
+
import { createLangChainAgentTools } from "@easynet/agent-tool/api";
|
|
4
|
+
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
5
|
+
import {
|
|
6
|
+
createAgentEventBus,
|
|
7
|
+
loadYamlFile,
|
|
8
|
+
asObject,
|
|
9
|
+
type AgentEventBus,
|
|
10
|
+
} from "@easynet/agent-common";
|
|
11
|
+
import type { SkillConfig } from "@easynet/agent-skill";
|
|
12
|
+
import { createSkills, type EmbedFn, type SkillSet } from "@easynet/agent-skill";
|
|
13
|
+
import { getSkillsConfig } from "../config/index.js";
|
|
14
|
+
import type { BaseAgentConfig, ConfigApi } from "../config/types.js";
|
|
15
|
+
import { resolve, dirname } from "node:path";
|
|
16
|
+
export type { BaseAgentConfig } from "../config/types.js";
|
|
17
|
+
export type { ConfigApi } from "../config/types.js";
|
|
18
|
+
|
|
19
|
+
export type AgentName = string;
|
|
20
|
+
|
|
21
|
+
export type BotTool = ReturnType<typeof createLangChainAgentTools>[number];
|
|
22
|
+
|
|
23
|
+
/** Minimal memory interface used by the runtime. */
|
|
24
|
+
export interface AgentMemory {
|
|
25
|
+
memorize(namespace: string, type: string, contentOrUrl: string | URL, metadata?: Record<string, unknown>): Promise<unknown>;
|
|
26
|
+
recall(req: { namespace: string; query?: string; types?: string[]; topK?: number; budgetTokens?: number }): Promise<{ items: unknown[]; injectedText: string; traceId: string }>;
|
|
27
|
+
deleteByNamespace(namespace: string): Promise<void>;
|
|
28
|
+
getByKey(namespace: string, key: string): Promise<unknown>;
|
|
29
|
+
deleteByKey(namespace: string, key: string): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface BotContext<TConfig extends BaseAgentConfig = BaseAgentConfig, TTool = BotTool> {
|
|
33
|
+
llm: BaseChatModel;
|
|
34
|
+
memory: AgentMemory;
|
|
35
|
+
tools: TTool[];
|
|
36
|
+
config: TConfig;
|
|
37
|
+
events: AgentEventBus;
|
|
38
|
+
skillSet?: SkillSet;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CreateContextOptions<TTool = BotTool> {
|
|
42
|
+
configPath?: string;
|
|
43
|
+
agentName?: AgentName;
|
|
44
|
+
events?: AgentEventBus;
|
|
45
|
+
llm?: BaseChatModel;
|
|
46
|
+
memory?: AgentMemory;
|
|
47
|
+
tools?: TTool[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function publishEvent(
|
|
51
|
+
events: AgentEventBus,
|
|
52
|
+
name: string,
|
|
53
|
+
from: string,
|
|
54
|
+
to: string,
|
|
55
|
+
payload?: unknown
|
|
56
|
+
): void {
|
|
57
|
+
events.publish({ name, from, to, payload });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function injectSkillsRuntimeConfig(
|
|
61
|
+
config: BaseAgentConfig,
|
|
62
|
+
agentName: string,
|
|
63
|
+
values: Pick<SkillConfig, "mode" | "inject_metadata" | "embedding_threshold" | "keyword_threshold">
|
|
64
|
+
): void {
|
|
65
|
+
const agentConfig = config.app?.agent?.[agentName];
|
|
66
|
+
if (!agentConfig) return;
|
|
67
|
+
agentConfig.skills = {
|
|
68
|
+
...(agentConfig.skills ?? {}),
|
|
69
|
+
...values,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function createContextBuilders<TConfig extends BaseAgentConfig>(params: {
|
|
74
|
+
configApi: ConfigApi<TConfig>;
|
|
75
|
+
}) {
|
|
76
|
+
const {
|
|
77
|
+
loadAgentConfig,
|
|
78
|
+
getModelsConfigPath,
|
|
79
|
+
getMemoryConfigPath,
|
|
80
|
+
getToolConfigPath,
|
|
81
|
+
} = params.configApi;
|
|
82
|
+
|
|
83
|
+
const pickDefaultAgentName = (config: TConfig): AgentName | undefined => {
|
|
84
|
+
const names = Object.keys(config.app?.agent ?? {});
|
|
85
|
+
return names[0];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
async function getAgentLlm(
|
|
89
|
+
config: TConfig,
|
|
90
|
+
events: AgentEventBus,
|
|
91
|
+
agentName?: AgentName
|
|
92
|
+
): Promise<BaseChatModel> {
|
|
93
|
+
const modelsPath = getModelsConfigPath(config, agentName ?? pickDefaultAgentName(config));
|
|
94
|
+
publishEvent(events, "llm.init.start", "app", "llm", { configPath: modelsPath });
|
|
95
|
+
const modelRegistry = await createAgentModelRegistry(modelsPath);
|
|
96
|
+
const llm = await modelRegistry.getChatModel();
|
|
97
|
+
publishEvent(events, "llm.init.done", "llm", "app");
|
|
98
|
+
return llm;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function getAgentMemory(
|
|
102
|
+
config: TConfig,
|
|
103
|
+
events: AgentEventBus,
|
|
104
|
+
agentName?: AgentName
|
|
105
|
+
): Promise<AgentMemory> {
|
|
106
|
+
const memoryPath = getMemoryConfigPath(config, agentName ?? pickDefaultAgentName(config));
|
|
107
|
+
publishEvent(events, "memory.init.start", "app", "memory", { configPath: memoryPath });
|
|
108
|
+
const memory = await createMemoryClient({ configPath: memoryPath });
|
|
109
|
+
publishEvent(events, "memory.init.done", "memory", "app");
|
|
110
|
+
return memory;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function getAgentTools(
|
|
114
|
+
config: TConfig,
|
|
115
|
+
events: AgentEventBus,
|
|
116
|
+
agentName?: AgentName
|
|
117
|
+
): Promise<BotTool[]> {
|
|
118
|
+
const toolPath = getToolConfigPath(config, agentName ?? pickDefaultAgentName(config));
|
|
119
|
+
publishEvent(events, "tools.init.start", "app", "tools", { configPath: toolPath });
|
|
120
|
+
const tools = createLangChainAgentTools({ configFilePath: toolPath });
|
|
121
|
+
publishEvent(events, "tools.init.done", "tools", "app", { count: tools.length });
|
|
122
|
+
return tools;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function createAgent(options: CreateContextOptions<BotTool> = {}): Promise<BotContext<TConfig, BotTool>> {
|
|
126
|
+
const config = await loadAgentConfig(options.configPath);
|
|
127
|
+
const agentName = options.agentName ?? pickDefaultAgentName(config);
|
|
128
|
+
const events = options.events ?? createAgentEventBus();
|
|
129
|
+
publishEvent(events, "agent.context.init.start", "app", "runtime");
|
|
130
|
+
|
|
131
|
+
const [llm, memory, tools] = await Promise.all([
|
|
132
|
+
options.llm ?? getAgentLlm(config, events, agentName),
|
|
133
|
+
options.memory ?? getAgentMemory(config, events, agentName),
|
|
134
|
+
options.tools ?? getAgentTools(config, events, agentName),
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
const appConfig = config as unknown as BaseAgentConfig;
|
|
138
|
+
const skillSet = await initializeSkills({
|
|
139
|
+
appConfig,
|
|
140
|
+
config,
|
|
141
|
+
agentName,
|
|
142
|
+
events,
|
|
143
|
+
getModelsConfigPath: (c, name) => getModelsConfigPath(c as TConfig, name),
|
|
144
|
+
pickDefaultAgentName: (c) => pickDefaultAgentName(c as TConfig),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
publishEvent(events, "agent.context.init.done", "runtime", "app");
|
|
148
|
+
return { llm, memory, tools, config, events, skillSet };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function createBotContext(
|
|
152
|
+
configPath?: string,
|
|
153
|
+
agentName?: AgentName
|
|
154
|
+
): Promise<BotContext<TConfig, BotTool>> {
|
|
155
|
+
return createAgent({ configPath, agentName });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
getAgentLlm,
|
|
160
|
+
getAgentMemory,
|
|
161
|
+
getAgentTools,
|
|
162
|
+
// Backward-compatible aliases
|
|
163
|
+
createAgentLlm: getAgentLlm,
|
|
164
|
+
createAgentMemory: getAgentMemory,
|
|
165
|
+
createAgentTools: getAgentTools,
|
|
166
|
+
createAgent,
|
|
167
|
+
createBotContext,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function initializeSkills(input: {
|
|
172
|
+
appConfig: BaseAgentConfig;
|
|
173
|
+
config: BaseAgentConfig;
|
|
174
|
+
agentName?: AgentName;
|
|
175
|
+
events: AgentEventBus;
|
|
176
|
+
getModelsConfigPath: (config: BaseAgentConfig, agentName?: AgentName) => string;
|
|
177
|
+
pickDefaultAgentName: (config: BaseAgentConfig) => AgentName | undefined;
|
|
178
|
+
}): Promise<SkillSet | undefined> {
|
|
179
|
+
const skillsConfig = await getSkillsConfig(input.appConfig, input.agentName);
|
|
180
|
+
if (!skillsConfig) return undefined;
|
|
181
|
+
publishEvent(input.events, "skills.init.start", "app", "skills", { path: skillsConfig.path });
|
|
182
|
+
const embedFn = buildSkillsEmbedFn(input.config, input.agentName, input.getModelsConfigPath, input.pickDefaultAgentName);
|
|
183
|
+
const skillsDir = await resolveSkillsDir(skillsConfig.path);
|
|
184
|
+
const skillSet = await createSkills({ path: skillsDir, embed: embedFn });
|
|
185
|
+
const mode = applySkillsPromptAndMetadata(input.appConfig, input.agentName, skillsConfig, skillSet);
|
|
186
|
+
publishEvent(input.events, "skills.init.done", "skills", "app", { count: skillSet.list().length, mode });
|
|
187
|
+
return skillSet;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function buildSkillsEmbedFn(
|
|
191
|
+
config: BaseAgentConfig,
|
|
192
|
+
agentName: AgentName | undefined,
|
|
193
|
+
getModelsConfigPath: (config: BaseAgentConfig, agentName?: AgentName) => string,
|
|
194
|
+
pickDefaultAgentName: (config: BaseAgentConfig) => AgentName | undefined,
|
|
195
|
+
): EmbedFn | undefined {
|
|
196
|
+
const modelsPath = getModelsConfigPath(config, agentName ?? pickDefaultAgentName(config));
|
|
197
|
+
const lazyEmbed: EmbedFn = async (input: string | string[]) => {
|
|
198
|
+
const modelRegistry = await createAgentModelRegistry(modelsPath);
|
|
199
|
+
const embeddings = modelRegistry.getEmbeddingModel();
|
|
200
|
+
if (Array.isArray(input)) return embeddings.embedDocuments(input);
|
|
201
|
+
const one = await embeddings.embedQuery(input);
|
|
202
|
+
return [one];
|
|
203
|
+
};
|
|
204
|
+
return lazyEmbed;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function applySkillsPromptAndMetadata(
|
|
208
|
+
appConfig: BaseAgentConfig,
|
|
209
|
+
agentName: AgentName | undefined,
|
|
210
|
+
skillsConfig: SkillConfig,
|
|
211
|
+
skillSet: SkillSet,
|
|
212
|
+
): string {
|
|
213
|
+
const mode = skillsConfig.mode ?? "prompt";
|
|
214
|
+
if (agentName) {
|
|
215
|
+
injectSkillsRuntimeConfig(appConfig, agentName, {
|
|
216
|
+
mode: skillsConfig.mode,
|
|
217
|
+
inject_metadata: skillsConfig.inject_metadata,
|
|
218
|
+
embedding_threshold: skillsConfig.embedding_threshold,
|
|
219
|
+
keyword_threshold: skillsConfig.keyword_threshold,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (mode === "prompt" && skillsConfig.inject_metadata !== false) {
|
|
223
|
+
injectSkillsPromptSection(appConfig, agentName, skillSet.promptSection());
|
|
224
|
+
}
|
|
225
|
+
return mode;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function injectSkillsPromptSection(
|
|
229
|
+
appConfig: BaseAgentConfig,
|
|
230
|
+
agentName: AgentName | undefined,
|
|
231
|
+
section: string | undefined,
|
|
232
|
+
): void {
|
|
233
|
+
if (!section || !agentName) return;
|
|
234
|
+
const agentConfig = appConfig.app?.agent?.[agentName];
|
|
235
|
+
if (!agentConfig) return;
|
|
236
|
+
const currentPrompt = agentConfig.systemPrompt ?? "";
|
|
237
|
+
agentConfig.systemPrompt = currentPrompt.trimEnd() + "\n\n" + section;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface AppContextBuilders {
|
|
241
|
+
getAgentLlm: (config: BaseAgentConfig, events: AgentEventBus, agentName?: AgentName) => Promise<BaseChatModel>;
|
|
242
|
+
getAgentMemory: (config: BaseAgentConfig, events: AgentEventBus, agentName?: AgentName) => Promise<AgentMemory>;
|
|
243
|
+
getAgentTools: (config: BaseAgentConfig, events: AgentEventBus, agentName?: AgentName) => Promise<BotTool[]>;
|
|
244
|
+
createAgentLlm: (config: BaseAgentConfig, events: AgentEventBus, agentName?: AgentName) => Promise<BaseChatModel>;
|
|
245
|
+
createAgentMemory: (config: BaseAgentConfig, events: AgentEventBus, agentName?: AgentName) => Promise<AgentMemory>;
|
|
246
|
+
createAgentTools: (config: BaseAgentConfig, events: AgentEventBus, agentName?: AgentName) => Promise<BotTool[]>;
|
|
247
|
+
createAgent: (options?: CreateContextOptions<BotTool>) => Promise<BotContext>;
|
|
248
|
+
createBotContext: (configPath?: string, agentName?: AgentName) => Promise<BotContext>;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Resolve skills directory path from either a YAML config file or a direct path.
|
|
253
|
+
* If the path ends with .yaml/.yml, loads the YAML and extracts the `path:` field.
|
|
254
|
+
*/
|
|
255
|
+
async function resolveSkillsDir(skillsPath: string): Promise<string> {
|
|
256
|
+
if (/\.ya?ml$/i.test(skillsPath)) {
|
|
257
|
+
const raw = await loadYamlFile<{ path?: string }>(skillsPath);
|
|
258
|
+
const spec = asObject((raw as { spec?: unknown } | undefined)?.spec);
|
|
259
|
+
const pathRef = typeof spec?.path === "string" ? spec.path : raw?.path;
|
|
260
|
+
if (!pathRef) {
|
|
261
|
+
throw new Error(`skills config missing "path" field: ${skillsPath}`);
|
|
262
|
+
}
|
|
263
|
+
return resolve(dirname(skillsPath), pathRef);
|
|
264
|
+
}
|
|
265
|
+
return skillsPath;
|
|
266
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createContextBuilders,
|
|
3
|
+
type AppContextBuilders,
|
|
4
|
+
type BaseAgentConfig,
|
|
5
|
+
type BotContext,
|
|
6
|
+
type BotTool,
|
|
7
|
+
type CreateContextOptions,
|
|
8
|
+
type ConfigApi,
|
|
9
|
+
} from "./core/context.js";
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
createReactAgent,
|
|
13
|
+
printReactSteps,
|
|
14
|
+
type ReactAgentOptions,
|
|
15
|
+
type ReactAgentRuntime,
|
|
16
|
+
} from "./agents/react-agent.js";
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
createDeepAgent,
|
|
20
|
+
type DeepAgentOptions,
|
|
21
|
+
type DeepAgentRuntime,
|
|
22
|
+
} from "./agents/deep-agent.js";
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
createConfigApi,
|
|
26
|
+
createRuntimeConfig,
|
|
27
|
+
loadAgentConfig,
|
|
28
|
+
getModelsConfigPath,
|
|
29
|
+
getMemoryConfigPath,
|
|
30
|
+
getToolConfigPath,
|
|
31
|
+
resolveDefaultAgentName,
|
|
32
|
+
type CreateRuntimeConfigOptions,
|
|
33
|
+
type AgentRuntimeConfig,
|
|
34
|
+
type AgentConfigDefaults,
|
|
35
|
+
type AgentProfileConfig,
|
|
36
|
+
} from "./config/index.js";
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
runAppCli,
|
|
40
|
+
createStructuredRunEventListener,
|
|
41
|
+
type AppCliOptions,
|
|
42
|
+
type AppCliUiOptions,
|
|
43
|
+
} from "./cli.js";
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
malformedToolCallMiddleware,
|
|
47
|
+
type MalformedToolCallMiddlewareConfig,
|
|
48
|
+
} from "./middleware/malformed-tool-call-middleware.js";
|
|
49
|
+
|
|
50
|
+
export {
|
|
51
|
+
createSubAgentRunner,
|
|
52
|
+
type SubAgentRunner,
|
|
53
|
+
type SubAgentOptions,
|
|
54
|
+
type SubAgentResult,
|
|
55
|
+
} from "./agents/sub-agent.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"declarationMap": true,
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"],
|
|
17
|
+
"exclude": ["node_modules", "dist"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# iMessageBot
|
|
2
|
+
|
|
3
|
+
iMessageBot is an application built on the **@easynet** agent framework. It runs two agents:
|
|
4
|
+
|
|
5
|
+
1. **ReAct agent** - LangChain ReAct with tools and memory.
|
|
6
|
+
2. **Deep agent** - DeepAgents with persistent memory store.
|
|
7
|
+
|
|
8
|
+
The app is configured to send outbound messages on macOS via the `messagesSendByHandle` tool in `@easynet/agent-tool-buildin`.
|
|
9
|
+
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
- Node.js >= 18
|
|
13
|
+
- macOS with Messages.app signed in
|
|
14
|
+
- Automation permission granted for your terminal/Node process to control Messages.app
|
|
15
|
+
- Ollama (or another OpenAI-compatible endpoint) for the LLM
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd apps/imessagebot
|
|
21
|
+
npm install
|
|
22
|
+
npm run build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm run react
|
|
29
|
+
npm run deep
|
|
30
|
+
node dist/index.js react "Send hello to +1234567890"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Config
|
|
34
|
+
|
|
35
|
+
- `config/app.yaml`: app name, paths, and bot prompts
|
|
36
|
+
- `config/agents/shared/model.yaml`: LLM + embedding models config
|
|
37
|
+
- `config/agents/shared/memory.yaml`: memory backend config
|
|
38
|
+
- `config/agents/shared/tool.yaml`: tool config
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @easynet/agent-tool-buildin
|
|
2
|
+
|
|
3
|
+
内置工具扩展包,配合 `@easynet/agent-tool` 使用。
|
|
4
|
+
|
|
5
|
+
## 最小使用方式
|
|
6
|
+
|
|
7
|
+
在 `tool.yaml` 中添加该包:
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
tools:
|
|
11
|
+
sandboxedPath: .
|
|
12
|
+
allowedHosts: []
|
|
13
|
+
blockedHosts: []
|
|
14
|
+
list:
|
|
15
|
+
- npm:@easynet/agent-tool-buildin
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 常用最小工具集(可选)
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
tools:
|
|
22
|
+
sandboxedPath: .
|
|
23
|
+
allowedHosts: [api.github.com]
|
|
24
|
+
blockedHosts: []
|
|
25
|
+
list:
|
|
26
|
+
- npm:@easynet/agent-tool-buildin#fs.readText
|
|
27
|
+
- npm:@easynet/agent-tool-buildin#fs.writeText
|
|
28
|
+
- npm:@easynet/agent-tool-buildin#http.fetchJson
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
说明:
|
|
32
|
+
- `fs.*` 受 `sandboxedPath` 限制
|
|
33
|
+
- `http.*` 受 `allowedHosts` / `blockedHosts` 限制
|