fourmis-agents-sdk 0.2.6 → 0.3.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/agent-loop.d.ts +3 -0
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +23 -9
- package/dist/agents/index.js +40 -12
- package/dist/agents/tools.js +40 -12
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +658 -28
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +666 -28
- package/dist/memory/index.d.ts +42 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +319 -0
- package/dist/memory/memory-handler.d.ts +49 -0
- package/dist/memory/memory-handler.d.ts.map +1 -0
- package/dist/memory/memory-handler.js +233 -0
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +17 -3
- package/dist/providers/registry.js +17 -3
- package/dist/providers/types.d.ts +6 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/skills/frontmatter.d.ts +15 -0
- package/dist/skills/frontmatter.d.ts.map +1 -0
- package/dist/skills/frontmatter.js +51 -0
- package/dist/skills/index.d.ts +8 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +289 -0
- package/dist/skills/skills.d.ts +78 -0
- package/dist/skills/skills.d.ts.map +1 -0
- package/dist/skills/skills.js +287 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/system-prompt.d.ts +2 -0
- package/dist/utils/system-prompt.d.ts.map +1 -1
- package/dist/utils/system-prompt.js +279 -3
- package/package.json +3 -2
package/dist/agent-loop.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type { ToolRegistry } from "./tools/registry.js";
|
|
|
15
15
|
import type { PermissionManager } from "./permissions.js";
|
|
16
16
|
import type { HookManager } from "./hooks.js";
|
|
17
17
|
import type { McpClientManager } from "./mcp/client.js";
|
|
18
|
+
import type { NativeMemoryTool } from "./memory/index.js";
|
|
18
19
|
export type SessionLogger = (role: "user" | "assistant", content: NormalizedContent[] | string, parentUuid: string | null) => string;
|
|
19
20
|
export type AgentLoopOptions = {
|
|
20
21
|
provider: ProviderAdapter;
|
|
@@ -34,6 +35,8 @@ export type AgentLoopOptions = {
|
|
|
34
35
|
mcpClient?: McpClientManager;
|
|
35
36
|
previousMessages?: NormalizedMessage[];
|
|
36
37
|
sessionLogger?: SessionLogger;
|
|
38
|
+
/** Native memory tool for Anthropic provider (handled specially) */
|
|
39
|
+
nativeMemoryTool?: NativeMemoryTool;
|
|
37
40
|
};
|
|
38
41
|
export declare function agentLoop(prompt: string, options: AgentLoopOptions): AsyncGenerator<AgentMessage>;
|
|
39
42
|
//# sourceMappingURL=agent-loop.d.ts.map
|
package/dist/agent-loop.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../src/agent-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAa,MAAM,sBAAsB,CAAC;AAC7G,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../src/agent-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,i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,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,GACxB,cAAc,CAAC,YAAY,CAAC,CAkZ9B"}
|
package/dist/agent-loop.js
CHANGED
|
@@ -122,7 +122,8 @@ async function* agentLoop(prompt, options) {
|
|
|
122
122
|
hooks,
|
|
123
123
|
mcpClient,
|
|
124
124
|
previousMessages,
|
|
125
|
-
sessionLogger
|
|
125
|
+
sessionLogger,
|
|
126
|
+
nativeMemoryTool
|
|
126
127
|
} = options;
|
|
127
128
|
const startTime = Date.now();
|
|
128
129
|
let apiTimeMs = 0;
|
|
@@ -176,13 +177,15 @@ async function* agentLoop(prompt, options) {
|
|
|
176
177
|
let assistantTextParts = [];
|
|
177
178
|
let toolCalls = [];
|
|
178
179
|
let turnUsage = emptyTokenUsage();
|
|
180
|
+
const nativeTools = nativeMemoryTool ? [nativeMemoryTool.definition] : undefined;
|
|
179
181
|
try {
|
|
180
182
|
const chunks = provider.chat({
|
|
181
183
|
model,
|
|
182
184
|
messages,
|
|
183
185
|
tools: toolDefs.length > 0 ? toolDefs : undefined,
|
|
184
186
|
systemPrompt,
|
|
185
|
-
signal
|
|
187
|
+
signal,
|
|
188
|
+
nativeTools
|
|
186
189
|
});
|
|
187
190
|
for await (const chunk of chunks) {
|
|
188
191
|
switch (chunk.type) {
|
|
@@ -340,13 +343,24 @@ async function* agentLoop(prompt, options) {
|
|
|
340
343
|
input: toolInput,
|
|
341
344
|
uuid: uuid()
|
|
342
345
|
};
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
let result;
|
|
347
|
+
if (call.name === "memory" && nativeMemoryTool) {
|
|
348
|
+
try {
|
|
349
|
+
const content = await nativeMemoryTool.execute(toolInput);
|
|
350
|
+
result = { content, isError: content.startsWith("Error:") };
|
|
351
|
+
} catch (err) {
|
|
352
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
353
|
+
result = { content: `Error: ${message}`, isError: true };
|
|
354
|
+
}
|
|
355
|
+
} else {
|
|
356
|
+
const toolCtx = {
|
|
357
|
+
cwd,
|
|
358
|
+
signal,
|
|
359
|
+
sessionId,
|
|
360
|
+
env
|
|
361
|
+
};
|
|
362
|
+
result = await tools.execute(call.name, toolInput, toolCtx);
|
|
363
|
+
}
|
|
350
364
|
if (debug) {
|
|
351
365
|
console.error(`[debug] Tool ${call.name}: ${result.isError ? "ERROR" : "OK"} (${result.content.length} chars)`);
|
|
352
366
|
}
|
package/dist/agents/index.js
CHANGED
|
@@ -501,7 +501,8 @@ async function* agentLoop(prompt, options) {
|
|
|
501
501
|
hooks,
|
|
502
502
|
mcpClient,
|
|
503
503
|
previousMessages,
|
|
504
|
-
sessionLogger
|
|
504
|
+
sessionLogger,
|
|
505
|
+
nativeMemoryTool
|
|
505
506
|
} = options;
|
|
506
507
|
const startTime = Date.now();
|
|
507
508
|
let apiTimeMs = 0;
|
|
@@ -555,13 +556,15 @@ async function* agentLoop(prompt, options) {
|
|
|
555
556
|
let assistantTextParts = [];
|
|
556
557
|
let toolCalls = [];
|
|
557
558
|
let turnUsage = emptyTokenUsage();
|
|
559
|
+
const nativeTools = nativeMemoryTool ? [nativeMemoryTool.definition] : undefined;
|
|
558
560
|
try {
|
|
559
561
|
const chunks = provider.chat({
|
|
560
562
|
model,
|
|
561
563
|
messages,
|
|
562
564
|
tools: toolDefs.length > 0 ? toolDefs : undefined,
|
|
563
565
|
systemPrompt,
|
|
564
|
-
signal
|
|
566
|
+
signal,
|
|
567
|
+
nativeTools
|
|
565
568
|
});
|
|
566
569
|
for await (const chunk of chunks) {
|
|
567
570
|
switch (chunk.type) {
|
|
@@ -719,13 +722,24 @@ async function* agentLoop(prompt, options) {
|
|
|
719
722
|
input: toolInput,
|
|
720
723
|
uuid: uuid()
|
|
721
724
|
};
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
725
|
+
let result;
|
|
726
|
+
if (call.name === "memory" && nativeMemoryTool) {
|
|
727
|
+
try {
|
|
728
|
+
const content = await nativeMemoryTool.execute(toolInput);
|
|
729
|
+
result = { content, isError: content.startsWith("Error:") };
|
|
730
|
+
} catch (err) {
|
|
731
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
732
|
+
result = { content: `Error: ${message}`, isError: true };
|
|
733
|
+
}
|
|
734
|
+
} else {
|
|
735
|
+
const toolCtx = {
|
|
736
|
+
cwd,
|
|
737
|
+
signal,
|
|
738
|
+
sessionId,
|
|
739
|
+
env
|
|
740
|
+
};
|
|
741
|
+
result = await tools.execute(call.name, toolInput, toolCtx);
|
|
742
|
+
}
|
|
729
743
|
if (debug) {
|
|
730
744
|
console.error(`[debug] Tool ${call.name}: ${result.isError ? "ERROR" : "OK"} (${result.content.length} chars)`);
|
|
731
745
|
}
|
|
@@ -1040,15 +1054,29 @@ class AnthropicAdapter {
|
|
|
1040
1054
|
} else if (request.systemPrompt) {
|
|
1041
1055
|
params.system = request.systemPrompt;
|
|
1042
1056
|
}
|
|
1057
|
+
const allTools = [];
|
|
1043
1058
|
if (tools && tools.length > 0) {
|
|
1044
|
-
|
|
1059
|
+
allTools.push(...tools);
|
|
1060
|
+
}
|
|
1061
|
+
if (request.nativeTools && request.nativeTools.length > 0) {
|
|
1062
|
+
allTools.push(...request.nativeTools);
|
|
1063
|
+
}
|
|
1064
|
+
if (allTools.length > 0) {
|
|
1065
|
+
params.tools = allTools;
|
|
1045
1066
|
}
|
|
1046
1067
|
if (request.temperature !== undefined) {
|
|
1047
1068
|
params.temperature = request.temperature;
|
|
1048
1069
|
}
|
|
1049
|
-
const
|
|
1070
|
+
const hasMemoryTool = request.nativeTools?.some((t) => t.type === "memory_20250818");
|
|
1071
|
+
const requestOptions = {
|
|
1050
1072
|
signal: request.signal
|
|
1051
|
-
}
|
|
1073
|
+
};
|
|
1074
|
+
if (hasMemoryTool) {
|
|
1075
|
+
requestOptions.headers = {
|
|
1076
|
+
"anthropic-beta": "context-management-2025-06-27"
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
const stream = this.client.messages.stream(params, requestOptions);
|
|
1052
1080
|
const toolInputBuffers = new Map;
|
|
1053
1081
|
for await (const event of stream) {
|
|
1054
1082
|
switch (event.type) {
|
package/dist/agents/tools.js
CHANGED
|
@@ -501,7 +501,8 @@ async function* agentLoop(prompt, options) {
|
|
|
501
501
|
hooks,
|
|
502
502
|
mcpClient,
|
|
503
503
|
previousMessages,
|
|
504
|
-
sessionLogger
|
|
504
|
+
sessionLogger,
|
|
505
|
+
nativeMemoryTool
|
|
505
506
|
} = options;
|
|
506
507
|
const startTime = Date.now();
|
|
507
508
|
let apiTimeMs = 0;
|
|
@@ -555,13 +556,15 @@ async function* agentLoop(prompt, options) {
|
|
|
555
556
|
let assistantTextParts = [];
|
|
556
557
|
let toolCalls = [];
|
|
557
558
|
let turnUsage = emptyTokenUsage();
|
|
559
|
+
const nativeTools = nativeMemoryTool ? [nativeMemoryTool.definition] : undefined;
|
|
558
560
|
try {
|
|
559
561
|
const chunks = provider.chat({
|
|
560
562
|
model,
|
|
561
563
|
messages,
|
|
562
564
|
tools: toolDefs.length > 0 ? toolDefs : undefined,
|
|
563
565
|
systemPrompt,
|
|
564
|
-
signal
|
|
566
|
+
signal,
|
|
567
|
+
nativeTools
|
|
565
568
|
});
|
|
566
569
|
for await (const chunk of chunks) {
|
|
567
570
|
switch (chunk.type) {
|
|
@@ -719,13 +722,24 @@ async function* agentLoop(prompt, options) {
|
|
|
719
722
|
input: toolInput,
|
|
720
723
|
uuid: uuid()
|
|
721
724
|
};
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
725
|
+
let result;
|
|
726
|
+
if (call.name === "memory" && nativeMemoryTool) {
|
|
727
|
+
try {
|
|
728
|
+
const content = await nativeMemoryTool.execute(toolInput);
|
|
729
|
+
result = { content, isError: content.startsWith("Error:") };
|
|
730
|
+
} catch (err) {
|
|
731
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
732
|
+
result = { content: `Error: ${message}`, isError: true };
|
|
733
|
+
}
|
|
734
|
+
} else {
|
|
735
|
+
const toolCtx = {
|
|
736
|
+
cwd,
|
|
737
|
+
signal,
|
|
738
|
+
sessionId,
|
|
739
|
+
env
|
|
740
|
+
};
|
|
741
|
+
result = await tools.execute(call.name, toolInput, toolCtx);
|
|
742
|
+
}
|
|
729
743
|
if (debug) {
|
|
730
744
|
console.error(`[debug] Tool ${call.name}: ${result.isError ? "ERROR" : "OK"} (${result.content.length} chars)`);
|
|
731
745
|
}
|
|
@@ -1040,15 +1054,29 @@ class AnthropicAdapter {
|
|
|
1040
1054
|
} else if (request.systemPrompt) {
|
|
1041
1055
|
params.system = request.systemPrompt;
|
|
1042
1056
|
}
|
|
1057
|
+
const allTools = [];
|
|
1043
1058
|
if (tools && tools.length > 0) {
|
|
1044
|
-
|
|
1059
|
+
allTools.push(...tools);
|
|
1060
|
+
}
|
|
1061
|
+
if (request.nativeTools && request.nativeTools.length > 0) {
|
|
1062
|
+
allTools.push(...request.nativeTools);
|
|
1063
|
+
}
|
|
1064
|
+
if (allTools.length > 0) {
|
|
1065
|
+
params.tools = allTools;
|
|
1045
1066
|
}
|
|
1046
1067
|
if (request.temperature !== undefined) {
|
|
1047
1068
|
params.temperature = request.temperature;
|
|
1048
1069
|
}
|
|
1049
|
-
const
|
|
1070
|
+
const hasMemoryTool = request.nativeTools?.some((t) => t.type === "memory_20250818");
|
|
1071
|
+
const requestOptions = {
|
|
1050
1072
|
signal: request.signal
|
|
1051
|
-
}
|
|
1073
|
+
};
|
|
1074
|
+
if (hasMemoryTool) {
|
|
1075
|
+
requestOptions.headers = {
|
|
1076
|
+
"anthropic-beta": "context-management-2025-06-27"
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
const stream = this.client.messages.stream(params, requestOptions);
|
|
1052
1080
|
const toolInputBuffers = new Map;
|
|
1053
1081
|
for await (const event of stream) {
|
|
1054
1082
|
switch (event.type) {
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AAwBzE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB,GAAG,KAAK,CA+LR"}
|