@inbrowser/agent 0.2.0 → 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/README.md +2 -2
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/fixtures.d.ts +2 -2
- package/dist/cli/fixtures.d.ts.map +1 -1
- package/dist/cli/fixtures.js +7 -16
- package/dist/cli/fixtures.js.map +1 -1
- package/dist/cli/llm/openrouter.d.ts +4 -4
- package/dist/cli/llm/openrouter.d.ts.map +1 -1
- package/dist/cli/llm/openrouter.js +20 -31
- package/dist/cli/llm/openrouter.js.map +1 -1
- package/dist/diagnostics/truthfulness.js.map +1 -1
- package/dist/eval/runner.d.ts +4 -4
- package/dist/eval/runner.d.ts.map +1 -1
- package/dist/eval/runner.js +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/llm-adapter.d.ts +30 -34
- package/dist/llm-adapter.d.ts.map +1 -1
- package/dist/llm-adapter.js +61 -51
- package/dist/llm-adapter.js.map +1 -1
- package/dist/mcp/connect.d.ts +68 -0
- package/dist/mcp/connect.d.ts.map +1 -0
- package/dist/mcp/connect.js +111 -0
- package/dist/mcp/connect.js.map +1 -0
- package/dist/metrics.js +4 -4
- package/dist/metrics.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -1
- package/dist/retrieval.d.ts +74 -0
- package/dist/retrieval.d.ts.map +1 -0
- package/dist/retrieval.js +287 -0
- package/dist/retrieval.js.map +1 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +8 -2
- package/dist/session.js.map +1 -1
- package/dist/strategy.d.ts +2 -1
- package/dist/strategy.d.ts.map +1 -1
- package/dist/strategy.js +36 -26
- package/dist/strategy.js.map +1 -1
- package/dist/types/agent.d.ts +2 -3
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +1 -1
- package/dist/types/chat.d.ts +0 -15
- package/dist/types/chat.d.ts.map +1 -1
- package/dist/types/llm.d.ts +11 -64
- package/dist/types/llm.d.ts.map +1 -1
- package/dist/types/llm.js +7 -8
- package/dist/types/llm.js.map +1 -1
- package/dist/types/metrics.d.ts +2 -2
- package/dist/types/metrics.d.ts.map +1 -1
- package/dist/types/session.d.ts +2 -2
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/strategy.d.ts +13 -4
- package/dist/types/strategy.d.ts.map +1 -1
- package/dist/types/trace.d.ts +11 -9
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +5 -2
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createRetrievalStrategy()` — a code-orchestrated retrieve-then-read
|
|
3
|
+
* (RAG) `AgentStrategy`.
|
|
4
|
+
*
|
|
5
|
+
* Where `createReactLoopStrategy` lets the model drive — deciding when
|
|
6
|
+
* to call tools and when to stop — this strategy inverts the control
|
|
7
|
+
* flow. The *code* does the retrieval (search + read top-K docs); the
|
|
8
|
+
* model is invoked exactly ONCE, with NO tools advertised, to write a
|
|
9
|
+
* grounded answer from the retrieved excerpts. This is the
|
|
10
|
+
* "zero-agency" tier-1 shape from
|
|
11
|
+
* `plans/retrieval-strategy-and-eval.md`: a small model (e.g. SmolLM2
|
|
12
|
+
* 360M) that can't reliably emit tool calls or decide when to stop
|
|
13
|
+
* still does one thing well — grounded generation over stuffed context.
|
|
14
|
+
*
|
|
15
|
+
* Lifecycle (`run`):
|
|
16
|
+
*
|
|
17
|
+
* 1. SEARCH (code). Synthesize a tool-call id, emit `tool_call`
|
|
18
|
+
* for the search tool with `{ query: input.prompt }`, dispatch it
|
|
19
|
+
* through `input.tools.execute`, emit `tool_result`.
|
|
20
|
+
* 2. READ top-K (code). Pull routes from the search result via
|
|
21
|
+
* `extractRoutes`, take the first `topK`, and for each emit
|
|
22
|
+
* `tool_call`(read) → dispatch → `tool_result`. Collect the
|
|
23
|
+
* extracted text until `contextBudget` chars are reached.
|
|
24
|
+
* 3. COMPOSE. Build `[system, ...history, user(composeContext(...))]`
|
|
25
|
+
* the same way the ReAct loop's `buildMessages` does — except the
|
|
26
|
+
* final user message is the grounded context+question, not the
|
|
27
|
+
* raw prompt.
|
|
28
|
+
* 4. GENERATE. One `input.llm.chat({ messages, tools: [],
|
|
29
|
+
* toolUseEnabled: false })` call; map model `text` / `thinking` /
|
|
30
|
+
* `usage` / `error` events straight to `StrategyEvent`s.
|
|
31
|
+
* 5. `turn_complete` carrying the captured usage.
|
|
32
|
+
*
|
|
33
|
+
* It emits the SAME `tool_call` / `tool_result` / `text` event surface
|
|
34
|
+
* the ReAct loop does, so an existing host (cards, sources, streaming)
|
|
35
|
+
* works unchanged — the only difference is the events are driven by
|
|
36
|
+
* code, not the model.
|
|
37
|
+
*/
|
|
38
|
+
import type { AgentStrategy } from './types/strategy.js';
|
|
39
|
+
export interface RetrievalStrategyOpts {
|
|
40
|
+
/** Tool that returns candidate doc hits for a query. Default `'search_docs'`. */
|
|
41
|
+
searchTool?: string;
|
|
42
|
+
/** Tool that returns a single doc's content by route. Default `'get_doc'`. */
|
|
43
|
+
readTool?: string;
|
|
44
|
+
/** How many of the search hits to read. Default 3. */
|
|
45
|
+
topK?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Pull the routes to read from the search tool's `ToolResult.data`.
|
|
48
|
+
* Default: `(d as { hits: { route }[] }).hits.map((h) => h.route)`.
|
|
49
|
+
*/
|
|
50
|
+
extractRoutes?(searchData: unknown): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Pull the context text from a read tool's `ToolResult.data`.
|
|
53
|
+
* Default: from `{ route, title, body }`.
|
|
54
|
+
*/
|
|
55
|
+
extractText?(readData: unknown): {
|
|
56
|
+
route: string;
|
|
57
|
+
title: string;
|
|
58
|
+
text: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Build the grounded user message from the question + retrieved docs.
|
|
62
|
+
* Default: an instruction to answer ONLY from the excerpts and cite
|
|
63
|
+
* the route(s), the labeled excerpts, then the question.
|
|
64
|
+
*/
|
|
65
|
+
composeContext?(question: string, docs: {
|
|
66
|
+
route: string;
|
|
67
|
+
title: string;
|
|
68
|
+
text: string;
|
|
69
|
+
}[]): string;
|
|
70
|
+
/** Cap on total context chars fed to the model. Default ~6000. */
|
|
71
|
+
contextBudget?: number;
|
|
72
|
+
}
|
|
73
|
+
export declare function createRetrievalStrategy(opts?: RetrievalStrategyOpts): AgentStrategy;
|
|
74
|
+
//# sourceMappingURL=retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieval.d.ts","sourceRoot":"","sources":["../src/retrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAmC,MAAM,qBAAqB,CAAC;AAE1F,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,EAAE,CAAC;IAC9C;;;OAGG;IACH,WAAW,CAAC,CAAC,QAAQ,EAAE,OAAO,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAChF;;;;OAIG;IACH,cAAc,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,MAAM,CAAC;IAClG,kEAAkE;IAClE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAoHD,wBAAgB,uBAAuB,CAAC,IAAI,GAAE,qBAA0B,GAAG,aAAa,CA4JvF"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createRetrievalStrategy()` — a code-orchestrated retrieve-then-read
|
|
3
|
+
* (RAG) `AgentStrategy`.
|
|
4
|
+
*
|
|
5
|
+
* Where `createReactLoopStrategy` lets the model drive — deciding when
|
|
6
|
+
* to call tools and when to stop — this strategy inverts the control
|
|
7
|
+
* flow. The *code* does the retrieval (search + read top-K docs); the
|
|
8
|
+
* model is invoked exactly ONCE, with NO tools advertised, to write a
|
|
9
|
+
* grounded answer from the retrieved excerpts. This is the
|
|
10
|
+
* "zero-agency" tier-1 shape from
|
|
11
|
+
* `plans/retrieval-strategy-and-eval.md`: a small model (e.g. SmolLM2
|
|
12
|
+
* 360M) that can't reliably emit tool calls or decide when to stop
|
|
13
|
+
* still does one thing well — grounded generation over stuffed context.
|
|
14
|
+
*
|
|
15
|
+
* Lifecycle (`run`):
|
|
16
|
+
*
|
|
17
|
+
* 1. SEARCH (code). Synthesize a tool-call id, emit `tool_call`
|
|
18
|
+
* for the search tool with `{ query: input.prompt }`, dispatch it
|
|
19
|
+
* through `input.tools.execute`, emit `tool_result`.
|
|
20
|
+
* 2. READ top-K (code). Pull routes from the search result via
|
|
21
|
+
* `extractRoutes`, take the first `topK`, and for each emit
|
|
22
|
+
* `tool_call`(read) → dispatch → `tool_result`. Collect the
|
|
23
|
+
* extracted text until `contextBudget` chars are reached.
|
|
24
|
+
* 3. COMPOSE. Build `[system, ...history, user(composeContext(...))]`
|
|
25
|
+
* the same way the ReAct loop's `buildMessages` does — except the
|
|
26
|
+
* final user message is the grounded context+question, not the
|
|
27
|
+
* raw prompt.
|
|
28
|
+
* 4. GENERATE. One `input.llm.chat({ messages, tools: [],
|
|
29
|
+
* toolUseEnabled: false })` call; map model `text` / `thinking` /
|
|
30
|
+
* `usage` / `error` events straight to `StrategyEvent`s.
|
|
31
|
+
* 5. `turn_complete` carrying the captured usage.
|
|
32
|
+
*
|
|
33
|
+
* It emits the SAME `tool_call` / `tool_result` / `text` event surface
|
|
34
|
+
* the ReAct loop does, so an existing host (cards, sources, streaming)
|
|
35
|
+
* works unchanged — the only difference is the events are driven by
|
|
36
|
+
* code, not the model.
|
|
37
|
+
*/
|
|
38
|
+
const DEFAULT_SEARCH_TOOL = 'search_docs';
|
|
39
|
+
const DEFAULT_READ_TOOL = 'get_doc';
|
|
40
|
+
const DEFAULT_TOP_K = 3;
|
|
41
|
+
const DEFAULT_CONTEXT_BUDGET = 6000;
|
|
42
|
+
/** Default route extractor: `data.hits[].route`. Defensive against
|
|
43
|
+
* any non-conforming shape — returns `[]` rather than throwing so the
|
|
44
|
+
* strategy still completes (generating from whatever context it has). */
|
|
45
|
+
function defaultExtractRoutes(searchData) {
|
|
46
|
+
if (!searchData || typeof searchData !== 'object')
|
|
47
|
+
return [];
|
|
48
|
+
const hits = searchData.hits;
|
|
49
|
+
if (!Array.isArray(hits))
|
|
50
|
+
return [];
|
|
51
|
+
const routes = [];
|
|
52
|
+
for (const hit of hits) {
|
|
53
|
+
if (hit && typeof hit === 'object') {
|
|
54
|
+
const route = hit.route;
|
|
55
|
+
if (typeof route === 'string' && route.length > 0)
|
|
56
|
+
routes.push(route);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return routes;
|
|
60
|
+
}
|
|
61
|
+
/** Default text extractor: from `{ route, title, body }`. */
|
|
62
|
+
function defaultExtractText(readData) {
|
|
63
|
+
const obj = (readData && typeof readData === 'object' ? readData : {});
|
|
64
|
+
return {
|
|
65
|
+
route: typeof obj.route === 'string' ? obj.route : '',
|
|
66
|
+
title: typeof obj.title === 'string' ? obj.title : '',
|
|
67
|
+
text: typeof obj.body === 'string' ? obj.body : '',
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Default context composer: a tight grounding instruction, the
|
|
71
|
+
* labeled excerpts, then the question. Mirrors the wording in the
|
|
72
|
+
* plan: answer ONLY from the excerpts + cite the route(s). */
|
|
73
|
+
function defaultComposeContext(question, docs) {
|
|
74
|
+
const instruction = 'Answer the question using ONLY the documentation excerpts below. ' +
|
|
75
|
+
'Cite the route(s) you used. If the answer is not in the excerpts, say so.';
|
|
76
|
+
const excerpts = docs.map((doc) => `--- [${doc.route}] ${doc.title}\n${doc.text}`).join('\n\n');
|
|
77
|
+
const excerptBlock = excerpts.length > 0 ? excerpts : '(no documentation excerpts were retrieved)';
|
|
78
|
+
return `${instruction}\n\n${excerptBlock}\n\nQuestion: ${question}`;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build `[system, ...history, user(<groundedContext>)]`. Identical to
|
|
82
|
+
* the ReAct loop's `buildMessages` except the trailing user message is
|
|
83
|
+
* the grounded context rather than the raw prompt. This strategy never
|
|
84
|
+
* encodes assistant tool-calls of its own — the only tool activity is
|
|
85
|
+
* the code-driven retrieval, which the model never sees.
|
|
86
|
+
*/
|
|
87
|
+
function buildMessages(input, groundedUserText) {
|
|
88
|
+
const out = [];
|
|
89
|
+
out.push({ role: 'system', text: input.systemPrompt });
|
|
90
|
+
for (const m of input.history) {
|
|
91
|
+
if (m.role === 'system')
|
|
92
|
+
continue; // already emitted
|
|
93
|
+
if (m.role === 'assistant') {
|
|
94
|
+
const tc = m.toolCalls?.map((c) => ({
|
|
95
|
+
id: c.id,
|
|
96
|
+
name: c.name,
|
|
97
|
+
args: safeParse(c.argsJson),
|
|
98
|
+
...(c.signature ? { signature: c.signature } : {}),
|
|
99
|
+
})) ?? [];
|
|
100
|
+
out.push({
|
|
101
|
+
role: 'assistant',
|
|
102
|
+
text: m.text,
|
|
103
|
+
...(tc.length > 0 ? { toolCalls: tc } : {}),
|
|
104
|
+
});
|
|
105
|
+
for (const c of m.toolCalls ?? []) {
|
|
106
|
+
if (c.resultJson !== undefined) {
|
|
107
|
+
out.push({
|
|
108
|
+
role: 'tool',
|
|
109
|
+
toolCallId: c.id,
|
|
110
|
+
name: c.name,
|
|
111
|
+
resultJson: c.resultJson,
|
|
112
|
+
text: '',
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
out.push({ role: m.role, text: m.text });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
out.push({ role: 'user', text: groundedUserText });
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
function safeParse(s) {
|
|
125
|
+
try {
|
|
126
|
+
return JSON.parse(s);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return s;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
let idSeq = 0;
|
|
133
|
+
/** Per-call id for the synthetic, code-driven tool calls. Mirrors the
|
|
134
|
+
* ReAct loop's per-iteration `requestId` discipline — the host only
|
|
135
|
+
* needs the id to be stable + unique across a single run so it can
|
|
136
|
+
* pair `tool_call` with `tool_result`. */
|
|
137
|
+
function rid(prefix) {
|
|
138
|
+
idSeq += 1;
|
|
139
|
+
return `${prefix}-${Date.now().toString(36)}-${idSeq}`;
|
|
140
|
+
}
|
|
141
|
+
export function createRetrievalStrategy(opts = {}) {
|
|
142
|
+
const searchTool = opts.searchTool ?? DEFAULT_SEARCH_TOOL;
|
|
143
|
+
const readTool = opts.readTool ?? DEFAULT_READ_TOOL;
|
|
144
|
+
const topK = opts.topK ?? DEFAULT_TOP_K;
|
|
145
|
+
const extractRoutes = opts.extractRoutes ?? defaultExtractRoutes;
|
|
146
|
+
const extractText = opts.extractText ?? defaultExtractText;
|
|
147
|
+
const composeContext = opts.composeContext ?? defaultComposeContext;
|
|
148
|
+
const contextBudget = opts.contextBudget ?? DEFAULT_CONTEXT_BUDGET;
|
|
149
|
+
return {
|
|
150
|
+
id: 'retrieval',
|
|
151
|
+
async *run(input, signal) {
|
|
152
|
+
if (signal.aborted) {
|
|
153
|
+
yield { kind: 'error', message: 'aborted' };
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
// 1. SEARCH (code-driven). Emit the same `tool_call` /
|
|
157
|
+
// `tool_result` surface the ReAct loop emits for a model-driven
|
|
158
|
+
// call, so the host's "searching" UI + Sources work unchanged.
|
|
159
|
+
const searchId = rid('search');
|
|
160
|
+
yield { kind: 'tool_call', id: searchId, name: searchTool, args: { query: input.prompt } };
|
|
161
|
+
const searchResult = await input.tools.execute({ id: searchId, name: searchTool, args: { query: input.prompt } }, input.toolContext());
|
|
162
|
+
yield { kind: 'tool_result', id: searchId, result: searchResult };
|
|
163
|
+
// 2. READ top-K (code-driven). Even when search failed or
|
|
164
|
+
// returned no usable routes we still proceed to generate — the
|
|
165
|
+
// model grounds on whatever context we managed to collect (or
|
|
166
|
+
// on an explicit "nothing retrieved" note). It never crashes.
|
|
167
|
+
const routes = searchResult.ok ? extractRoutes(searchResult.data).slice(0, topK) : [];
|
|
168
|
+
const docs = [];
|
|
169
|
+
let usedChars = 0;
|
|
170
|
+
for (const route of routes) {
|
|
171
|
+
if (signal.aborted) {
|
|
172
|
+
yield { kind: 'error', message: 'aborted' };
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (usedChars >= contextBudget)
|
|
176
|
+
break;
|
|
177
|
+
const readId = rid('read');
|
|
178
|
+
yield { kind: 'tool_call', id: readId, name: readTool, args: { route } };
|
|
179
|
+
const readResult = await input.tools.execute({ id: readId, name: readTool, args: { route } }, input.toolContext());
|
|
180
|
+
yield { kind: 'tool_result', id: readId, result: readResult };
|
|
181
|
+
if (!readResult.ok)
|
|
182
|
+
continue;
|
|
183
|
+
const doc = extractText(readResult.data);
|
|
184
|
+
// Trim the excerpt so the running total never exceeds the
|
|
185
|
+
// budget — a small local model can't hold several full bodies.
|
|
186
|
+
const remaining = contextBudget - usedChars;
|
|
187
|
+
const text = doc.text.length > remaining ? doc.text.slice(0, remaining) : doc.text;
|
|
188
|
+
docs.push({ route: doc.route, title: doc.title, text });
|
|
189
|
+
usedChars += text.length;
|
|
190
|
+
}
|
|
191
|
+
if (signal.aborted) {
|
|
192
|
+
yield { kind: 'error', message: 'aborted' };
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// 3. COMPOSE. The model's only input is system + history + the
|
|
196
|
+
// grounded question. No tools are advertised → no tool-call
|
|
197
|
+
// parsing, no loop.
|
|
198
|
+
const groundedUserText = composeContext(input.prompt, docs);
|
|
199
|
+
const messages = buildMessages(input, groundedUserText);
|
|
200
|
+
const chatRequest = {
|
|
201
|
+
messages,
|
|
202
|
+
tools: [],
|
|
203
|
+
toolUseEnabled: false,
|
|
204
|
+
};
|
|
205
|
+
// Emit the trace BEFORE dispatch — same agent-layer view the
|
|
206
|
+
// ReAct loop captures. A single-iteration run, so iteration 0.
|
|
207
|
+
const turnIdForReq = input.turnId ?? 'turn-anon';
|
|
208
|
+
const requestId = `${turnIdForReq}#0`;
|
|
209
|
+
if (input.tracer) {
|
|
210
|
+
input.tracer.emit({
|
|
211
|
+
kind: 'llm_request',
|
|
212
|
+
data: {
|
|
213
|
+
requestId,
|
|
214
|
+
turnId: turnIdForReq,
|
|
215
|
+
iteration: 0,
|
|
216
|
+
ts: Date.now(),
|
|
217
|
+
systemPrompt: input.systemPrompt,
|
|
218
|
+
messages: messages.map((m) => ({ ...m })),
|
|
219
|
+
tools: [],
|
|
220
|
+
llm: { id: input.llm.id, supportsTools: input.llm.supportsTools },
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
// 4. GENERATE (the model's ONLY job).
|
|
225
|
+
let turnUsage;
|
|
226
|
+
const turnDetails = { requestedModel: input.llm.id };
|
|
227
|
+
let assistantText = '';
|
|
228
|
+
let assistantThinking = '';
|
|
229
|
+
for await (const ev of input.llm.chat(chatRequest, signal)) {
|
|
230
|
+
if (ev.kind === 'text') {
|
|
231
|
+
assistantText += ev.text;
|
|
232
|
+
yield { kind: 'text', chunk: ev.text };
|
|
233
|
+
}
|
|
234
|
+
else if (ev.kind === 'thinking') {
|
|
235
|
+
assistantThinking += ev.text;
|
|
236
|
+
yield { kind: 'thinking', chunk: ev.text };
|
|
237
|
+
}
|
|
238
|
+
else if (ev.kind === 'usage') {
|
|
239
|
+
turnUsage = ev.usage;
|
|
240
|
+
}
|
|
241
|
+
else if (ev.kind === 'error') {
|
|
242
|
+
yield { kind: 'error', message: ev.message };
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// `tool_call` events are impossible here (toolUseEnabled:false,
|
|
246
|
+
// no tools advertised); a misbehaving stub that emits one is
|
|
247
|
+
// ignored rather than dispatched — this is a zero-agency
|
|
248
|
+
// strategy and the code already retrieved everything.
|
|
249
|
+
}
|
|
250
|
+
// Pair the `llm_request` with its response — the closing endpoint
|
|
251
|
+
// of this run's language-model wall-clock segment.
|
|
252
|
+
if (input.tracer) {
|
|
253
|
+
input.tracer.emit({
|
|
254
|
+
kind: 'llm_response',
|
|
255
|
+
data: {
|
|
256
|
+
requestId,
|
|
257
|
+
ts: Date.now(),
|
|
258
|
+
text: assistantText,
|
|
259
|
+
thinking: assistantThinking,
|
|
260
|
+
toolCalls: [],
|
|
261
|
+
...(turnUsage
|
|
262
|
+
? {
|
|
263
|
+
usage: {
|
|
264
|
+
promptTokens: turnUsage.promptTokens,
|
|
265
|
+
outputTokens: turnUsage.outputTokens,
|
|
266
|
+
...(turnUsage.cachedTokens !== undefined
|
|
267
|
+
? { cachedTokens: turnUsage.cachedTokens }
|
|
268
|
+
: {}),
|
|
269
|
+
},
|
|
270
|
+
}
|
|
271
|
+
: {}),
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
// 5. turn_complete. Synthesize a zero-usage accounting when the
|
|
276
|
+
// stub never emitted a `usage` event so the strategy always
|
|
277
|
+
// terminates with a `turn_complete` (the contract a host
|
|
278
|
+
// relies on), matching the plan.
|
|
279
|
+
yield {
|
|
280
|
+
kind: 'turn_complete',
|
|
281
|
+
usage: turnUsage ?? { promptTokens: 0, outputTokens: 0 },
|
|
282
|
+
details: turnDetails,
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=retrieval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieval.js","sourceRoot":"","sources":["../src/retrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAiCH,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAC1C,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC;;0EAE0E;AAC1E,SAAS,oBAAoB,CAAC,UAAmB;IAC/C,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IAC7D,MAAM,IAAI,GAAI,UAAiC,CAAC,IAAI,CAAC;IACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACpC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACnC,MAAM,KAAK,GAAI,GAA2B,CAAC,KAAK,CAAC;YACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,6DAA6D;AAC7D,SAAS,kBAAkB,CAAC,QAAiB;IAC3C,MAAM,GAAG,GAAG,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAA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C,CAAC,CAAC,EAAE,YAAY,EAAE,SAAS,CAAC,YAAY,EAAE;wCAC1C,CAAC,CAAC,EAAE,CAAC;iCACR;6BACF;4BACH,CAAC,CAAC,EAAE,CAAC;qBACR;iBACF,CAAC,CAAC;YACL,CAAC;YAED,gEAAgE;YAChE,+DAA+D;YAC/D,4DAA4D;YAC5D,oCAAoC;YACpC,MAAM;gBACJ,IAAI,EAAE,eAAe;gBACrB,KAAK,EAAE,SAAS,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE;gBACxD,OAAO,EAAE,WAAW;aACrB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAgB,MAAM,oBAAoB,CAAC;AAOzF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAgB,MAAM,oBAAoB,CAAC;AAOzF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAsI3E"}
|
package/dist/session.js
CHANGED
|
@@ -47,7 +47,13 @@ export function createAgentSession(config) {
|
|
|
47
47
|
async function* run(prompt, signal) {
|
|
48
48
|
const turnId = `t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
|
|
49
49
|
yield { kind: 'turn_started', turnId };
|
|
50
|
-
//
|
|
50
|
+
// The strategy receives the PRE-prompt history — everything
|
|
51
|
+
// before this turn's prompt — and appends `prompt` itself when
|
|
52
|
+
// composing messages. Passing the post-append history here would
|
|
53
|
+
// make every LLM request carry the user prompt twice.
|
|
54
|
+
const priorHistory = history;
|
|
55
|
+
// Capture the user message in the session's own history so the
|
|
56
|
+
// next turn (and persistence) sees it.
|
|
51
57
|
const userMsg = {
|
|
52
58
|
id: `u-${turnId}`,
|
|
53
59
|
role: 'user',
|
|
@@ -58,7 +64,7 @@ export function createAgentSession(config) {
|
|
|
58
64
|
const systemPrompt = config.systemPromptBuilder(workspace, runtime);
|
|
59
65
|
const strategyEvents = config.strategy.run({
|
|
60
66
|
prompt,
|
|
61
|
-
history,
|
|
67
|
+
history: priorHistory,
|
|
62
68
|
workspace,
|
|
63
69
|
runtime,
|
|
64
70
|
llm: config.llm,
|
package/dist/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,IAAI,cAAc,GAAG,CAAC,CAAC;AAEvB,MAAM,UAAU,kBAAkB,CAAC,MAA0B;IAC3D,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,IAAI,WAAW,EAAE,cAAc,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IACjF,IAAI,SAAS,GAAc,eAAe,CACxC,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,gBAAgB,EAAE,CACjF,CAAC;IACF,IAAI,OAAO,GAAiB,cAAc,EAAE,CAAC;IAC7C,IAAI,OAAO,GAAkB,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,YAAY,GAA2B,IAAI,CAAC;IAEhD,MAAM,OAAO,GAAiB;QAC5B,EAAE;QACF,IAAI,SAAS;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,OAAO;YACT,OAAO,OAAO,CAAC;QACjB,C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CAAC,CAAwC;QAC/E,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAwC;KAChF,CAAiB,CAAC;AACrB,CAAC;AAED,uEAAuE;AACvE,SAAS,WAAW,CAAC,CAAc,EAAE,CAAc;IACjD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3B,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,UAAU,CAAC,MAAM,CAAC;IAC3B,CAAC;IACD,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,OAAO,UAAU,CAAC,MAAM,CAAC;AAC3B,CAAC"}
|
package/dist/strategy.d.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* 4. When the LLM produces tool calls, dispatch each one, append
|
|
11
11
|
* the result message, and loop back to step 2.
|
|
12
12
|
* 5. When the LLM produces no tool calls in a turn, emit
|
|
13
|
-
* `turn_complete`
|
|
13
|
+
* `turn_complete` (synthesized from the model `usage` event +
|
|
14
|
+
* the client id) and finish.
|
|
14
15
|
*
|
|
15
16
|
* Future strategies (planner-executor, graph-of-thoughts,
|
|
16
17
|
* parallel-branch ensembling) sit alongside this one — same
|
package/dist/strategy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAGhB,MAAM,qBAAqB,CAAC;AAG7B,UAAU,gBAAgB;IACxB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAKD,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,gBAAqB,GAAG,aAAa,CAgbrF"}
|