@framers/agentos 0.1.122 → 0.1.124
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/api/TextToolCallParser.d.ts +61 -0
- package/dist/api/TextToolCallParser.d.ts.map +1 -0
- package/dist/api/TextToolCallParser.js +137 -0
- package/dist/api/TextToolCallParser.js.map +1 -0
- package/dist/api/agent.d.ts +7 -0
- package/dist/api/agent.d.ts.map +1 -1
- package/dist/api/agent.js +1 -0
- package/dist/api/agent.js.map +1 -1
- package/dist/api/generateText.d.ts +105 -0
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js +191 -2
- package/dist/api/generateText.js.map +1 -1
- package/dist/cognitive_substrate/GMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/GMI.js +27 -1
- package/dist/cognitive_substrate/GMI.js.map +1 -1
- package/dist/cognitive_substrate/IGMI.d.ts +5 -0
- package/dist/cognitive_substrate/IGMI.d.ts.map +1 -1
- package/dist/cognitive_substrate/IGMI.js.map +1 -1
- package/dist/emergent/AdaptPersonalityTool.d.ts +5 -21
- package/dist/emergent/AdaptPersonalityTool.d.ts.map +1 -1
- package/dist/emergent/AdaptPersonalityTool.js +18 -10
- package/dist/emergent/AdaptPersonalityTool.js.map +1 -1
- package/dist/emergent/CreateWorkflowTool.d.ts +1 -0
- package/dist/emergent/CreateWorkflowTool.d.ts.map +1 -1
- package/dist/emergent/CreateWorkflowTool.js +28 -5
- package/dist/emergent/CreateWorkflowTool.js.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.d.ts +68 -0
- package/dist/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
- package/dist/emergent/EmergentCapabilityEngine.js +99 -0
- package/dist/emergent/EmergentCapabilityEngine.js.map +1 -1
- package/dist/emergent/SelfEvaluateTool.d.ts +15 -5
- package/dist/emergent/SelfEvaluateTool.d.ts.map +1 -1
- package/dist/emergent/SelfEvaluateTool.js +111 -54
- package/dist/emergent/SelfEvaluateTool.js.map +1 -1
- package/dist/emergent/SelfImprovementConfig.d.ts +12 -1
- package/dist/emergent/SelfImprovementConfig.d.ts.map +1 -1
- package/dist/emergent/SelfImprovementConfig.js.map +1 -1
- package/dist/emergent/index.d.ts +7 -0
- package/dist/emergent/index.d.ts.map +1 -1
- package/dist/emergent/index.js +5 -0
- package/dist/emergent/index.js.map +1 -1
- package/dist/memory/AgentMemory.d.ts +2 -2
- package/dist/memory/AgentMemory.d.ts.map +1 -1
- package/dist/memory/AgentMemory.js +4 -3
- package/dist/memory/AgentMemory.js.map +1 -1
- package/dist/memory/consolidation/ConsolidationLoop.d.ts +31 -4
- package/dist/memory/consolidation/ConsolidationLoop.d.ts.map +1 -1
- package/dist/memory/consolidation/ConsolidationLoop.js +112 -69
- package/dist/memory/consolidation/ConsolidationLoop.js.map +1 -1
- package/dist/memory/facade/Memory.d.ts +12 -6
- package/dist/memory/facade/Memory.d.ts.map +1 -1
- package/dist/memory/facade/Memory.js +216 -212
- package/dist/memory/facade/Memory.js.map +1 -1
- package/dist/memory/facade/types.d.ts +11 -1
- package/dist/memory/facade/types.d.ts.map +1 -1
- package/dist/memory/feedback/RetrievalFeedbackSignal.d.ts +7 -10
- package/dist/memory/feedback/RetrievalFeedbackSignal.d.ts.map +1 -1
- package/dist/memory/feedback/RetrievalFeedbackSignal.js +40 -36
- package/dist/memory/feedback/RetrievalFeedbackSignal.js.map +1 -1
- package/dist/memory/io/ChatGptImporter.d.ts.map +1 -1
- package/dist/memory/io/ChatGptImporter.js +24 -18
- package/dist/memory/io/ChatGptImporter.js.map +1 -1
- package/dist/memory/io/CsvImporter.d.ts.map +1 -1
- package/dist/memory/io/CsvImporter.js +21 -8
- package/dist/memory/io/CsvImporter.js.map +1 -1
- package/dist/memory/io/JsonExporter.d.ts.map +1 -1
- package/dist/memory/io/JsonExporter.js +6 -17
- package/dist/memory/io/JsonExporter.js.map +1 -1
- package/dist/memory/io/JsonImporter.d.ts +3 -0
- package/dist/memory/io/JsonImporter.d.ts.map +1 -1
- package/dist/memory/io/JsonImporter.js +58 -29
- package/dist/memory/io/JsonImporter.js.map +1 -1
- package/dist/memory/io/MarkdownExporter.d.ts.map +1 -1
- package/dist/memory/io/MarkdownExporter.js +1 -4
- package/dist/memory/io/MarkdownExporter.js.map +1 -1
- package/dist/memory/io/MarkdownImporter.d.ts.map +1 -1
- package/dist/memory/io/MarkdownImporter.js +12 -7
- package/dist/memory/io/MarkdownImporter.js.map +1 -1
- package/dist/memory/io/ObsidianExporter.d.ts +14 -9
- package/dist/memory/io/ObsidianExporter.d.ts.map +1 -1
- package/dist/memory/io/ObsidianExporter.js +35 -23
- package/dist/memory/io/ObsidianExporter.js.map +1 -1
- package/dist/memory/io/ObsidianImporter.d.ts.map +1 -1
- package/dist/memory/io/ObsidianImporter.js +34 -27
- package/dist/memory/io/ObsidianImporter.js.map +1 -1
- package/dist/memory/io/SqliteExporter.d.ts +1 -2
- package/dist/memory/io/SqliteExporter.d.ts.map +1 -1
- package/dist/memory/io/SqliteExporter.js +2 -3
- package/dist/memory/io/SqliteExporter.js.map +1 -1
- package/dist/memory/io/SqliteImporter.d.ts +3 -0
- package/dist/memory/io/SqliteImporter.d.ts.map +1 -1
- package/dist/memory/io/SqliteImporter.js +62 -27
- package/dist/memory/io/SqliteImporter.js.map +1 -1
- package/dist/memory/store/SqliteBrain.d.ts +84 -24
- package/dist/memory/store/SqliteBrain.d.ts.map +1 -1
- package/dist/memory/store/SqliteBrain.js +139 -55
- package/dist/memory/store/SqliteBrain.js.map +1 -1
- package/dist/memory/store/SqliteKnowledgeGraph.d.ts +6 -2
- package/dist/memory/store/SqliteKnowledgeGraph.d.ts.map +1 -1
- package/dist/memory/store/SqliteKnowledgeGraph.js +94 -120
- package/dist/memory/store/SqliteKnowledgeGraph.js.map +1 -1
- package/dist/memory/store/SqliteMemoryGraph.d.ts +4 -5
- package/dist/memory/store/SqliteMemoryGraph.d.ts.map +1 -1
- package/dist/memory/store/SqliteMemoryGraph.js +31 -41
- package/dist/memory/store/SqliteMemoryGraph.js.map +1 -1
- package/dist/memory/tools/MemoryAddTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryAddTool.js +12 -16
- package/dist/memory/tools/MemoryAddTool.js.map +1 -1
- package/dist/memory/tools/MemoryDeleteTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryDeleteTool.js +1 -3
- package/dist/memory/tools/MemoryDeleteTool.js.map +1 -1
- package/dist/memory/tools/MemoryMergeTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryMergeTool.js +13 -22
- package/dist/memory/tools/MemoryMergeTool.js.map +1 -1
- package/dist/memory/tools/MemorySearchTool.js +4 -4
- package/dist/memory/tools/MemorySearchTool.js.map +1 -1
- package/dist/memory/tools/MemoryUpdateTool.d.ts.map +1 -1
- package/dist/memory/tools/MemoryUpdateTool.js +10 -18
- package/dist/memory/tools/MemoryUpdateTool.js.map +1 -1
- package/dist/orchestration/runtime/LoopController.d.ts +7 -0
- package/dist/orchestration/runtime/LoopController.d.ts.map +1 -1
- package/dist/orchestration/runtime/LoopController.js +7 -0
- package/dist/orchestration/runtime/LoopController.js.map +1 -1
- package/dist/rag/search/BM25Index.js +1 -1
- package/dist/rag/search/BM25Index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file TextToolCallParser.ts
|
|
3
|
+
* Fallback parser for extracting tool invocations from plain-text LLM responses.
|
|
4
|
+
*
|
|
5
|
+
* When an LLM does not support native `tool_calls` (e.g. some Ollama models,
|
|
6
|
+
* open-source models), the model may still emit structured text that encodes
|
|
7
|
+
* tool invocations. This parser recognises two common formats:
|
|
8
|
+
*
|
|
9
|
+
* **Format A — JSON in markdown code fences:**
|
|
10
|
+
* ```json
|
|
11
|
+
* {"tool": "web_search", "arguments": {"query": "AgentOS features"}}
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* **Format B — ReAct-style structured text:**
|
|
15
|
+
* ```
|
|
16
|
+
* Thought: I need to search for information about AgentOS.
|
|
17
|
+
* Action: web_search
|
|
18
|
+
* Input: {"query": "AgentOS features"}
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The parser first attempts Format A extraction, then Format B. Results from
|
|
22
|
+
* both passes are concatenated and returned as a unified array.
|
|
23
|
+
*
|
|
24
|
+
* @module api/TextToolCallParser
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* A tool invocation extracted from unstructured LLM text output.
|
|
28
|
+
*
|
|
29
|
+
* Maps directly onto the `ToolCallRecord` shape used by {@link generateText},
|
|
30
|
+
* but uses `arguments` instead of `args` to match the canonical tool-call wire
|
|
31
|
+
* format before execution.
|
|
32
|
+
*/
|
|
33
|
+
export interface ParsedToolCall {
|
|
34
|
+
/** Name of the tool to invoke, as it appears in the tool registry. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Parsed argument object to pass to the tool's `execute` function. */
|
|
37
|
+
arguments: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parses tool invocations from an LLM's plain-text response.
|
|
41
|
+
*
|
|
42
|
+
* This is the primary entry point for the text-based tool-call fallback.
|
|
43
|
+
* It first attempts to extract JSON tool calls from markdown code fences
|
|
44
|
+
* (Format A), then falls back to ReAct-style `Action: / Input:` patterns
|
|
45
|
+
* (Format B). Results from both passes are concatenated and de-duplicated
|
|
46
|
+
* by position (i.e. if the same tool call appears in both formats, both
|
|
47
|
+
* are included — the caller is responsible for deduplication if needed).
|
|
48
|
+
*
|
|
49
|
+
* @param text - Raw text from an LLM response.
|
|
50
|
+
* @returns An array of parsed tool calls, or an empty array if none were found.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const calls = parseToolCallsFromText(responseText);
|
|
55
|
+
* for (const call of calls) {
|
|
56
|
+
* console.log(`Tool: ${call.name}, Args:`, call.arguments);
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseToolCallsFromText(text: string): ParsedToolCall[];
|
|
61
|
+
//# sourceMappingURL=TextToolCallParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextToolCallParser.d.ts","sourceRoot":"","sources":["../../src/api/TextToolCallParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAgGD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAOrE"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file TextToolCallParser.ts
|
|
3
|
+
* Fallback parser for extracting tool invocations from plain-text LLM responses.
|
|
4
|
+
*
|
|
5
|
+
* When an LLM does not support native `tool_calls` (e.g. some Ollama models,
|
|
6
|
+
* open-source models), the model may still emit structured text that encodes
|
|
7
|
+
* tool invocations. This parser recognises two common formats:
|
|
8
|
+
*
|
|
9
|
+
* **Format A — JSON in markdown code fences:**
|
|
10
|
+
* ```json
|
|
11
|
+
* {"tool": "web_search", "arguments": {"query": "AgentOS features"}}
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* **Format B — ReAct-style structured text:**
|
|
15
|
+
* ```
|
|
16
|
+
* Thought: I need to search for information about AgentOS.
|
|
17
|
+
* Action: web_search
|
|
18
|
+
* Input: {"query": "AgentOS features"}
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The parser first attempts Format A extraction, then Format B. Results from
|
|
22
|
+
* both passes are concatenated and returned as a unified array.
|
|
23
|
+
*
|
|
24
|
+
* @module api/TextToolCallParser
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Extracts tool calls embedded in a JSON markdown code fence.
|
|
28
|
+
*
|
|
29
|
+
* Matches ```json blocks whose body contains a top-level object with either
|
|
30
|
+
* `"tool"` or `"name"` plus `"arguments"` (or `"input"` / `"parameters"`).
|
|
31
|
+
* Also handles fenced arrays of such objects.
|
|
32
|
+
*
|
|
33
|
+
* @param text - Raw LLM response text.
|
|
34
|
+
* @returns Parsed tool calls found in fenced JSON blocks (may be empty).
|
|
35
|
+
*/
|
|
36
|
+
function parseJsonFences(text) {
|
|
37
|
+
const results = [];
|
|
38
|
+
// Match ```json ... ``` blocks (case-insensitive language tag)
|
|
39
|
+
const fencePattern = /```(?:json)?\s*\n?([\s\S]*?)```/gi;
|
|
40
|
+
let match;
|
|
41
|
+
while ((match = fencePattern.exec(text)) !== null) {
|
|
42
|
+
const body = match[1].trim();
|
|
43
|
+
if (!body)
|
|
44
|
+
continue;
|
|
45
|
+
try {
|
|
46
|
+
const parsed = JSON.parse(body);
|
|
47
|
+
const items = Array.isArray(parsed) ? parsed : [parsed];
|
|
48
|
+
for (const item of items) {
|
|
49
|
+
if (typeof item !== 'object' || item === null)
|
|
50
|
+
continue;
|
|
51
|
+
const name = item.tool ?? item.name ?? item.function;
|
|
52
|
+
const args = item.arguments ?? item.input ?? item.parameters ?? item.params ?? {};
|
|
53
|
+
if (typeof name === 'string' && name.length > 0) {
|
|
54
|
+
results.push({
|
|
55
|
+
name,
|
|
56
|
+
arguments: typeof args === 'object' && args !== null ? args : {},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Malformed JSON — skip this fence silently
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return results;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Extracts tool calls from ReAct-style `Action: ... / Input: ...` blocks.
|
|
69
|
+
*
|
|
70
|
+
* The parser is line-oriented: it scans for `Action:` lines and then looks
|
|
71
|
+
* for a subsequent `Input:` line whose value is valid JSON. An `Action:`
|
|
72
|
+
* without a following `Input:` is accepted with an empty argument object.
|
|
73
|
+
*
|
|
74
|
+
* @param text - Raw LLM response text.
|
|
75
|
+
* @returns Parsed tool calls found via the Action/Input pattern (may be empty).
|
|
76
|
+
*/
|
|
77
|
+
function parseReActStyle(text) {
|
|
78
|
+
const results = [];
|
|
79
|
+
// Match Action/Input pairs (multiline, case-insensitive keys)
|
|
80
|
+
const actionPattern = /^[ \t]*Action\s*:\s*(.+)$/gim;
|
|
81
|
+
let actionMatch;
|
|
82
|
+
while ((actionMatch = actionPattern.exec(text)) !== null) {
|
|
83
|
+
const name = actionMatch[1].trim();
|
|
84
|
+
if (!name)
|
|
85
|
+
continue;
|
|
86
|
+
// Look for a subsequent Input: line after this Action: line
|
|
87
|
+
const afterAction = text.slice(actionMatch.index + actionMatch[0].length);
|
|
88
|
+
const inputMatch = afterAction.match(/^[ \t]*Input\s*:\s*([\s\S]*?)(?=\n[ \t]*(?:Action|Thought|Observation)\s*:|$)/im);
|
|
89
|
+
let args = {};
|
|
90
|
+
if (inputMatch) {
|
|
91
|
+
const rawInput = inputMatch[1].trim();
|
|
92
|
+
if (rawInput) {
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(rawInput);
|
|
95
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
96
|
+
args = parsed;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Non-JSON input — treat as a single string argument
|
|
101
|
+
args = { input: rawInput };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
results.push({ name, arguments: args });
|
|
106
|
+
}
|
|
107
|
+
return results;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Parses tool invocations from an LLM's plain-text response.
|
|
111
|
+
*
|
|
112
|
+
* This is the primary entry point for the text-based tool-call fallback.
|
|
113
|
+
* It first attempts to extract JSON tool calls from markdown code fences
|
|
114
|
+
* (Format A), then falls back to ReAct-style `Action: / Input:` patterns
|
|
115
|
+
* (Format B). Results from both passes are concatenated and de-duplicated
|
|
116
|
+
* by position (i.e. if the same tool call appears in both formats, both
|
|
117
|
+
* are included — the caller is responsible for deduplication if needed).
|
|
118
|
+
*
|
|
119
|
+
* @param text - Raw text from an LLM response.
|
|
120
|
+
* @returns An array of parsed tool calls, or an empty array if none were found.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const calls = parseToolCallsFromText(responseText);
|
|
125
|
+
* for (const call of calls) {
|
|
126
|
+
* console.log(`Tool: ${call.name}, Args:`, call.arguments);
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export function parseToolCallsFromText(text) {
|
|
131
|
+
if (!text || typeof text !== 'string')
|
|
132
|
+
return [];
|
|
133
|
+
const fromFences = parseJsonFences(text);
|
|
134
|
+
const fromReAct = parseReActStyle(text);
|
|
135
|
+
return [...fromFences, ...fromReAct];
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=TextToolCallParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextToolCallParser.js","sourceRoot":"","sources":["../../src/api/TextToolCallParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAgBH;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,OAAO,GAAqB,EAAE,CAAC;IAErC,+DAA+D;IAC/D,MAAM,YAAY,GAAG,mCAAmC,CAAC;IACzD,IAAI,KAA6B,CAAC;IAElC,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAA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AC,CAAC;IACzC,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAExC,OAAO,CAAC,GAAG,UAAU,EAAE,GAAG,SAAS,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/api/agent.d.ts
CHANGED
|
@@ -27,6 +27,13 @@ export interface AgentOptions extends BaseAgentConfig {
|
|
|
27
27
|
* When present, forwarded to `observability.usageLedger` internally.
|
|
28
28
|
*/
|
|
29
29
|
usageLedger?: AgentOSUsageLedgerOptions;
|
|
30
|
+
/**
|
|
31
|
+
* Chain-of-thought reasoning instruction.
|
|
32
|
+
* - `false` — disable CoT injection.
|
|
33
|
+
* - `true` (default for agents) — inject the default CoT instruction when tools are present.
|
|
34
|
+
* - `string` — inject a custom CoT instruction when tools are present.
|
|
35
|
+
*/
|
|
36
|
+
chainOfThought?: boolean | string;
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
32
39
|
* A named conversation session returned by `Agent.session()`.
|
package/dist/api/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/api/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC/B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAA4C,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEpG;;;;;;;GAOG;AACH,MAAM,WAAW,YAAa,SAAQ,eAAe;IACnD;;;OAGG;IACH,WAAW,CAAC,EAAE,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.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M,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,gBAAgB,CAAC;IAC9E;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IACnC,8EAA8E;IAC9E,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC1D,+DAA+D;IAC/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC;IACpE;;;;OAIG;IACH,UAAU,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;CAC9D;AAgCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,KAAK,CA+J/C"}
|
package/dist/api/agent.js
CHANGED
package/dist/api/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/api/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,YAAY,GAIb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAyB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACL,uBAAuB,GAGxB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAA0B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/api/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,YAAY,GAIb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAyB,MAAM,iBAAiB,CAAC;AACpE,O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uB,CAAC;wBAC7B,OAAO,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO;wBACtC,IAAI,EAAE,QAAQ,CAAC,WAAW,EAAE,IAAI;wBAChC,SAAS;qBACV,CAAC,CAAC;gBACL,CAAC;gBAED,KAAK;oBACH,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;gBACrB,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,SAAkB;YAC5B,OAAO,uBAAuB,CAAC;gBAC7B,OAAO,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO;gBACtC,IAAI,EAAE,QAAQ,CAAC,WAAW,EAAE,IAAI;gBAChC,SAAS;aACV,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,KAAK;YACT,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;QAED;;;;WAIG;QACH,MAAM,CAAC,QAAwC;YAC7C,OAAO,iBAAiB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC;QAED;;;;WAIG;QACH,UAAU,CAAC,QAAwC;YACjD,OAAO,qBAAqB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QACxD,CAAC;KACF,CAAC;IAEF,iEAAiE;IACjE,wEAAwE;IACxE,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE;QAC/C,KAAK,EAAE,IAAI;QACX,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -39,6 +39,49 @@ export interface TokenUsage {
|
|
|
39
39
|
/** Total cost reported by the provider across all steps, when available. */
|
|
40
40
|
costUSD?: number;
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Configuration for the optional plan-then-execute planning phase.
|
|
44
|
+
*
|
|
45
|
+
* When `planning` is set to `true` on {@link GenerateTextOptions}, default
|
|
46
|
+
* settings are used. Pass a `PlanningConfig` object for fine-grained control
|
|
47
|
+
* over the planning LLM call.
|
|
48
|
+
*/
|
|
49
|
+
export interface PlanningConfig {
|
|
50
|
+
/**
|
|
51
|
+
* Custom system prompt for the planning call. When omitted a sensible
|
|
52
|
+
* default that asks the model to produce a numbered JSON plan is used.
|
|
53
|
+
*/
|
|
54
|
+
systemPrompt?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Sampling temperature for the planning call.
|
|
57
|
+
* Defaults to `0.2` (low creativity, high determinism for plans).
|
|
58
|
+
*/
|
|
59
|
+
temperature?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Hard token cap for the planning response.
|
|
62
|
+
* Defaults to `2048`.
|
|
63
|
+
*/
|
|
64
|
+
maxTokens?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A single step in a plan produced by the planning phase.
|
|
68
|
+
* Serialised to / from the JSON plan the LLM emits.
|
|
69
|
+
*/
|
|
70
|
+
export interface PlanStep {
|
|
71
|
+
/** Human-readable description of what this step accomplishes. */
|
|
72
|
+
description: string;
|
|
73
|
+
/** Name of the tool to invoke, or `null` when the step is pure reasoning. */
|
|
74
|
+
tool: string | null;
|
|
75
|
+
/** Short explanation of why this step is needed. */
|
|
76
|
+
reasoning: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The complete plan returned by {@link createPlan}.
|
|
80
|
+
*/
|
|
81
|
+
export interface Plan {
|
|
82
|
+
/** Ordered list of steps the agent should follow. */
|
|
83
|
+
steps: PlanStep[];
|
|
84
|
+
}
|
|
42
85
|
/**
|
|
43
86
|
* Options for a {@link generateText} call.
|
|
44
87
|
* Either `prompt` or `messages` (or both) must be provided.
|
|
@@ -92,6 +135,25 @@ export interface GenerateTextOptions {
|
|
|
92
135
|
baseUrl?: string;
|
|
93
136
|
/** Optional durable usage ledger configuration for helper-level accounting. */
|
|
94
137
|
usageLedger?: AgentOSUsageLedgerOptions;
|
|
138
|
+
/**
|
|
139
|
+
* Chain-of-thought instruction prepended to the system prompt when tools
|
|
140
|
+
* are available. Encourages the model to reason explicitly before choosing
|
|
141
|
+
* an action.
|
|
142
|
+
*
|
|
143
|
+
* - `false` (default) — no CoT injection.
|
|
144
|
+
* - `true` — inject the default CoT instruction.
|
|
145
|
+
* - `string` — inject a custom CoT instruction.
|
|
146
|
+
*/
|
|
147
|
+
chainOfThought?: boolean | string;
|
|
148
|
+
/**
|
|
149
|
+
* Enable plan-then-execute mode. When `true` (or a {@link PlanningConfig}),
|
|
150
|
+
* an upfront LLM call decomposes the task into numbered steps before the
|
|
151
|
+
* tool-calling loop begins. The plan is injected into the system prompt
|
|
152
|
+
* so the model executes with full awareness of the strategy.
|
|
153
|
+
*
|
|
154
|
+
* Set to `false` or omit to skip planning entirely (the default).
|
|
155
|
+
*/
|
|
156
|
+
planning?: boolean | PlanningConfig;
|
|
95
157
|
}
|
|
96
158
|
/**
|
|
97
159
|
* The completed result returned by {@link generateText}.
|
|
@@ -130,7 +192,47 @@ export interface GenerateTextResult {
|
|
|
130
192
|
* schema. `undefined` when no output schema is configured.
|
|
131
193
|
*/
|
|
132
194
|
parsed?: unknown;
|
|
195
|
+
/**
|
|
196
|
+
* The plan produced by the planning phase when `planning` is enabled.
|
|
197
|
+
* `undefined` when planning is disabled or was not requested.
|
|
198
|
+
*/
|
|
199
|
+
plan?: Plan;
|
|
133
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Default chain-of-thought instruction prepended to the system prompt when
|
|
203
|
+
* tools are available and `chainOfThought` is enabled. Encourages the model
|
|
204
|
+
* to reason explicitly before selecting a tool or crafting a response.
|
|
205
|
+
*/
|
|
206
|
+
export declare const DEFAULT_COT_INSTRUCTION = "Before choosing an action, briefly reason about what you need to do and why. Consider:\n1. What information do you already have?\n2. What information do you need?\n3. Which tool is most appropriate and why?\nThen proceed with your tool call or response.";
|
|
207
|
+
/**
|
|
208
|
+
* Resolves the chain-of-thought instruction from the `chainOfThought` option.
|
|
209
|
+
*
|
|
210
|
+
* @param cot - The `chainOfThought` option value.
|
|
211
|
+
* @returns The resolved CoT instruction string, or `undefined` if disabled.
|
|
212
|
+
*
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
215
|
+
export declare function resolveChainOfThought(cot: boolean | string | undefined): string | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Makes a single LLM call to create an execution plan before the tool loop.
|
|
218
|
+
*
|
|
219
|
+
* The plan is a lightweight JSON object containing ordered steps. It is
|
|
220
|
+
* injected into the system prompt for the subsequent tool loop so the model
|
|
221
|
+
* executes with full awareness of the strategy.
|
|
222
|
+
*
|
|
223
|
+
* @param provider - The resolved LLM provider instance.
|
|
224
|
+
* @param modelId - Model identifier to use for the planning call.
|
|
225
|
+
* @param userMessages - The user-supplied messages that describe the task.
|
|
226
|
+
* @param toolNames - Names of available tools (informational context for the planner).
|
|
227
|
+
* @param config - Optional planning configuration overrides.
|
|
228
|
+
* @param totalUsage - Mutable usage aggregator — the planning call's tokens are added here.
|
|
229
|
+
* @returns The parsed {@link Plan}, or `undefined` if parsing fails gracefully.
|
|
230
|
+
*
|
|
231
|
+
* @internal
|
|
232
|
+
*/
|
|
233
|
+
export declare function createPlan(provider: {
|
|
234
|
+
generateCompletion: (...args: any[]) => Promise<any>;
|
|
235
|
+
}, modelId: string, userMessages: Array<Record<string, unknown>>, toolNames: string[], config: PlanningConfig | undefined, totalUsage: TokenUsage): Promise<Plan | undefined>;
|
|
134
236
|
/**
|
|
135
237
|
* Stateless text generation with optional multi-step tool calling.
|
|
136
238
|
*
|
|
@@ -139,6 +241,9 @@ export interface GenerateTextResult {
|
|
|
139
241
|
* assembled result. Provider credentials are resolved from environment
|
|
140
242
|
* variables unless overridden in `opts`.
|
|
141
243
|
*
|
|
244
|
+
* When `planning` is enabled, an upfront LLM call produces a step-by-step plan
|
|
245
|
+
* that is then injected into the system prompt for the tool loop.
|
|
246
|
+
*
|
|
142
247
|
* @param opts - Generation options including model, prompt/messages, and optional tools.
|
|
143
248
|
* @returns A promise that resolves to the final text, token usage, tool call log, and finish reason.
|
|
144
249
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateText.d.ts","sourceRoot":"","sources":["../../src/api/generateText.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateText.d.ts","sourceRoot":"","sources":["../../src/api/generateText.ts"],"names":[],"mappings":"AAeA,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAsB,KAAK,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAItF,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,kCAAkC;IAClC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,IAAI,EAAE,OAAO,CAAC;IACd,4EAA4E;IAC5E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;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