Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

/research gathers first (notes hidden), nudges once when no page was opened, then writes the answer in the fixed shape; /research in the slash menu

Niko1221c937aeb1df89
diff --git a/apps/host/scripts/agent-http.mjs b/apps/host/scripts/agent-http.mjs
index cd111a301..6779e1c78 100644
--- a/apps/host/scripts/agent-http.mjs
+++ b/apps/host/scripts/agent-http.mjs
@@ -62,6 +62,7 @@ async function stream(body, { quiet = false, path = '/api/chat/stream', onFrame
else if (f.type === 'plan-step') out = `PLAN-STEP ${f.line}${f.summary ? ' | summary: ' + f.summary : ''}`;
else if (f.type === 'queued-message') out = `QUEUED-MESSAGE ${f.state} "${f.message.text.slice(0, 50)}" deliverAt=${f.message.deliverAt}${f.afterStep ? ' afterStep=' + f.afterStep : ''} queue=${f.queue.length}`;
else if (f.type === 'queued-release') out = `QUEUED-RELEASE ${f.messages.map(m => m.text.slice(0, 40)).join(' | ')}`;
+ else if (f.type === 'research') out = `RESEARCH sources=${f.sources.map(x => x.n + ':' + x.url).join(' ')}`;
else if (f.type === 'done') out = `done ${f.finishReason} tokensOut=${f.tokensOut}`;
else if (f.type === 'error') out = `ERROR ${f.message}`;
if (!quiet && out !== lastLine) console.log(`${stamp()} ${out}`);
@@ -71,6 +72,7 @@ async function stream(body, { quiet = false, path = '/api/chat/stream', onFrame
if (done) break;
}
flushCounters();
+ if (process.env.SHOWTEXT && !quiet) console.log(['---- answer text ----', frames.filter(f => f.type === 'delta').map(f => f.text).join(''), '---- end ----'].join(String.fromCharCode(10)));
return frames;
}
diff --git a/apps/host/server/agent/agent-bridge.mjs b/apps/host/server/agent/agent-bridge.mjs
index 01e82113e..d335601f8 100644
--- a/apps/host/server/agent/agent-bridge.mjs
+++ b/apps/host/server/agent/agent-bridge.mjs
@@ -23,7 +23,7 @@ import { StatusReporter } from './status.mjs';
import { buildProfile, routeFor, MODE_PRESETS, modeOf, effortOf } from './profile.mjs';
import { TurnProjector, parseArguments as parseArgs } from './events.mjs';
import { ChildProjector } from './children.mjs';
-import { PlanStore, planPrompt, parsePlan, parsePoints, stepObjective, stepLine, firstSentence, planAsPrompt, editedSteps, planView, researchPrompt, parseSources } from './plan.mjs';
+import { PlanStore, planPrompt, parsePlan, parsePoints, stepObjective, stepLine, firstSentence, planAsPrompt, editedSteps, planView, researchPrompt, researchWritePrompt, RESEARCH_NUDGE, parseSources } from './plan.mjs';
/**
* A failure the person can read. `message` is a plain sentence with the next step; `details` keeps the technical
@@ -248,11 +248,13 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
async function runTurnInner(c, { chatId, message, workspacePath, choice = null, mode = null, history = [], onFrame, requestId = `req-${randomUUID()}`, signal, goal = null, thinking = null, planTask = null, planRun = null, researchTopic = null }) {
let send = onFrame; let attached = true;
+ // A research run gathers first; what the assistant writes while gathering is notes, not the answer, so it is not shown.
+ let hideDeltas = !!researchTopic;
signal?.addEventListener('abort', () => { send = () => {}; attached = false; }, { once: true });
// What the assistant itself wrote in this run (not our own step lines): a plan turn reads its plan from it, a step reads its summary.
const written = { all: '', step: '' };
const emit = frame => {
- if (frame.type === 'delta' && !frame.own) { written.all += frame.text; written.step += frame.text; }
+ if (frame.type === 'delta' && !frame.own) { written.all += frame.text; written.step += frame.text; if (hideDeltas) return; }
if (frame.own) { const { own, ...rest } = frame; frame = rest; }
try { send(frame); } catch { send = () => {}; attached = false; }
};
@@ -295,6 +297,7 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
// Helper agents (subagents) the Harness started for this chat, and the state of the run around them.
children: new Map(), subagentCalls: new Map(), parentOpen: false, stopping: false, settleTimer: null, mode: appliedMode,
plan: null, advancing: false, goalRun: false,
+ research: researchTopic ? { phase: 'gather', nudged: false, waitingStart: false } : null,
};
c.turn = turn;
function finishTurn(failure) {
@@ -404,6 +407,7 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
switch (e.type) {
case 'turn/start':
turn.parentOpen = true;
+ if (turn.research) turn.research.waitingStart = false;
clearTimeout(turn.settleTimer);
// After Stop, a helper's report would start a new turn that nobody asked for.
if (turn.stopping) void runtime.gw.rpc('session/cancel', { request: { sessionId } }).catch(() => {});
@@ -547,6 +551,21 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
const current = await goalGet();
if (turn.finished || turn.parentOpen) return;
if (current && current.phase === 'active' && current.activation === 'armed') { turn.settleTimer = after(700, armSettle); return; }
+ // Research: gather (search and read pages), then write the answer in the fixed shape. A step that did not open pages is sent back once.
+ if (turn.research && !turn.stopping) {
+ const r = turn.research;
+ if (r.waitingStart) { turn.settleTimer = after(300, armSettle); return; }
+ const opened = [...projector.tools.values()].filter(x => x.card?.name === 'web_fetch' && x.card.state === 'done').length;
+ const prompt = r.phase === 'write' ? null : (opened < 2 && !r.nudged) ? RESEARCH_NUDGE : researchWritePrompt(researchTopic);
+ if (prompt) {
+ if (prompt !== RESEARCH_NUDGE) { r.phase = 'write'; hideDeltas = false; written.all = ''; reporter.set({ phase: 'waiting', code: 'research-writing', text: 'Writing the answer…', key: 'Writing the answer…', values: [], args: {} }); } else r.nudged = true;
+ r.waitingStart = true;
+ try { await runtime.gw.rpc('session/prompt', { request: { requestId: `research-${randomUUID()}`, sessionId, mode: 'queue', content: [{ type: 'text', text: prompt }] } }); }
+ catch { r.waitingStart = false; hideDeltas = false; finishTurn(null); return; }
+ turn.settleTimer = after(500, armSettle);
+ return;
+ }
+ }
// A plan step's goal is complete: record it, deliver queued messages, start the next step.
if (turn.plan && current && current.phase === 'complete' && !turn.advancing) {
turn.advancing = true;
diff --git a/apps/host/server/agent/plan.mjs b/apps/host/server/agent/plan.mjs
index aeca32484..f2b072473 100644
--- a/apps/host/server/agent/plan.mjs
+++ b/apps/host/server/agent/plan.mjs
@@ -190,24 +190,34 @@ export const planView = plan => (plan ? JSON.parse(JSON.stringify(plan)) : null)
// ---- /research ------------------------------------------------------------------------------------------------------------------
-/** The instruction a research turn gets in front of the person's topic. */
+/** The first research prompt: find and read pages, take notes. What the assistant writes here is not shown; the answer is written in a second step. */
export function researchPrompt(topic) {
return [
- `Research this topic for me using the web: ${topic}`,
+ `Research task: ${topic}`,
'',
- 'How to work:',
- '1. Search the web with the web_search tool (try two or three different searches).',
- '2. Open the most useful pages with the web_fetch tool and read them. Use at least three different sources when you can find them.',
- '3. Write only what the pages say. If sources disagree or you could not find something, say so plainly.',
- '',
- 'Then write your answer in exactly this shape, in plain words:',
+ 'Do these steps in order. Do not skip a step.',
+ '1. Call web_search to find pages about the task.',
+ '2. Call web_fetch to open at least two of the pages you found, and read them. Do not rely on the search results alone.',
+ '3. When you have read them, reply with short notes: the facts you found, each with the web address of the page it came from.',
+ ].join('\n');
+}
+
+/** Sent when the assistant answered without opening pages. */
+export const RESEARCH_NUDGE = 'You have not opened enough pages yet. Call web_fetch now on at least two of the pages from your search, read them, then reply with short notes and the web address of each page.';
+
+/** The second research prompt: write the answer in the fixed shape. */
+export function researchWritePrompt(topic) {
+ return [
+ `Now write the final answer to the research task: ${topic}`,
+ 'Use only what you read on the pages. Do not call any tool. Start your reply with the line "## Summary" and use exactly these three headings:',
'## Summary',
- 'Three to five sentences.',
+ 'Three to five sentences, in plain words. If the sources disagree or something could not be found, say so.',
'## Key findings',
'- One finding per line, each ending with its source number in square brackets, like [1].',
'## Sources',
'1. Page title - web address',
'2. Page title - web address',
+ 'List only pages you opened.',
].join('\n');
}
@@ -215,7 +225,7 @@ export function researchPrompt(topic) {
export function parseSources(text) {
const lines = String(text ?? '').replace(/\r/g, '').split('\n');
const at = lines.map(l => /^\s{0,3}#{1,6}\s*sources\b/i.test(l) || /^\s*\*{0,2}sources\*{0,2}:?\s*$/i.test(l)).lastIndexOf(true);
- if (at < 0) return [];
+ if (at < 0) return linkSources(text);
const out = [];
for (const line of lines.slice(at + 1)) {
if (/^\s{0,3}#{1,6}\s/.test(line)) break;
@@ -228,3 +238,17 @@ export function parseSources(text) {
}
return out.slice(0, 20);
}
+
+/** No Sources section: the pages the answer links to, in the order they appear, so the page can still list where it came from. */
+function linkSources(text) {
+ const out = [];
+ const re = /\[([^\]]{1,160})\]\((https?:\/\/[^\s)]+)\)|(https?:\/\/[^\s)>\]"']+)/g;
+ let m;
+ while ((m = re.exec(String(text ?? ''))) && out.length < 8) {
+ const url = (m[2] ?? m[3]).replace(/[.,;]+$/, '');
+ if (out.some(x => x.url === url)) continue;
+ let host = url; try { host = new URL(url).hostname; } catch { /* keep the address */ }
+ out.push({ n: out.length + 1, title: clip(clean(m[1] ?? '') || host, 120), url });
+ }
+ return out;
+}
diff --git a/apps/host/src/screens/Chat.tsx b/apps/host/src/screens/Chat.tsx
index 9a1f7eb4a..1b898ef3c 100644
--- a/apps/host/src/screens/Chat.tsx
+++ b/apps/host/src/screens/Chat.tsx
@@ -424,6 +424,7 @@ function useSlashCommands(clear: () => void, setDraft: (value: string) => void):
{ id: 'time-skip', label: '/time-skip', hint: 'Try a change on a copy, check it, and keep it only if it is better', icon: 'branch', run: () => setDraft('/time-skip ') },
{ id: 'goal', label: '/goal', hint: 'Set a goal and let the assistant keep working until it is done', icon: 'bolt', run: () => setDraft('/goal ') },
{ id: 'plan', label: '/plan', hint: 'Have the assistant write a plan first; nothing runs until you approve it', icon: 'check', run: () => setDraft('/plan ') },
+ { id: 'research', label: '/research', hint: 'Search the web, read the pages and answer with sources', icon: 'search', run: () => setDraft('/research ') },
{ id: 'loop', label: '/loop', hint: 'Repeat a message every few minutes while this chat is open', icon: 'refresh', run: () => setDraft('/loop 10m ') },
{ id: 'website', label: '/website', hint: 'Open a website in the preview sidebar', icon: 'link', run: () => { clear(); window.dispatchEvent(new Event('strata:open-website')); } },
{ id: 'preview', label: '/preview', hint: 'Open a local file in the preview sidebar', icon: 'file', run: () => { clear(); window.dispatchEvent(new Event('strata:open-preview')); } },
diff --git a/apps/host/tests/agent-plan-run.test.mjs b/apps/host/tests/agent-plan-run.test.mjs
index c2ccdd87c..147eb117b 100644
--- a/apps/host/tests/agent-plan-run.test.mjs
+++ b/apps/host/tests/agent-plan-run.test.mjs
@@ -132,3 +132,23 @@ test('Stop in the middle of a plan pauses it with the finished steps kept; Resum
await r.bridge.stop('p4'); await second;
assert.equal(r.bridge.planState('p4').state, 'paused');
});
+
+test('/research: gathering is not shown, a run that opened no pages is sent back once, and the answer is written in a second step with its sources listed', { skip }, async (t) => {
+ const r = await rig(t);
+ const out = [];
+ await r.bridge.researchCommand({ ...r.base('rs1', f => out.push(f)), line: 'SCRIPT:echo Fact one [1]. https://a.example/x' });
+ const shown = words(out);
+ assert.equal(shown.split('Fact one').length - 1, 1, 'only the final answer is shown, not the notes of the first two replies: ' + JSON.stringify(shown));
+ const asked = r.worker.requests.filter(q => q.raw.includes('Research task:') || q.raw.includes('You have not opened enough pages') || q.raw.includes('Now write the final answer'));
+ assert.ok(asked.length >= 3, 'gather, nudge (no pages were opened), write');
+ const last = r.worker.requests.at(-1).raw;
+ assert.ok(last.includes('Now write the final answer to the research task') && last.includes('## Summary'), 'the last request carries the writing prompt');
+ const research = out.find(f => f.type === 'research');
+ assert.deepEqual(research.sources, [{ n: 1, title: 'a.example', url: 'https://a.example/x' }]);
+ assert.ok(out.findIndex(f => f.type === 'research') < out.findIndex(f => f.type === 'done'));
+ assert.equal(out.at(-1).type, 'done');
+ // without a topic, or with search turned off, nothing runs
+ const help = [];
+ await r.bridge.researchCommand({ ...r.base('rs2', f => help.push(f)), line: '' });
+ assert.match(words(help), /Type \/research followed by/);
+});
diff --git a/apps/host/tests/agent-plan.test.mjs b/apps/host/tests/agent-plan.test.mjs
index 9f9fd1646..85b76f9a2 100644
--- a/apps/host/tests/agent-plan.test.mjs
+++ b/apps/host/tests/agent-plan.test.mjs
@@ -96,5 +96,6 @@ test('research: the answer shape is asked for, and the sources are read back as
{ n: 2, title: 'Costs explained', url: 'https://costs.example.com/page?x=1' },
{ n: 3, title: 'plain.example.net', url: 'https://plain.example.net/a' },
]);
- assert.deepEqual(parseSources('No sources section here, see https://x.example'), []);
+ assert.deepEqual(parseSources('No sources section here, see https://x.example'), [{ n: 1, title: 'x.example', url: 'https://x.example' }], 'without a Sources section the linked pages are listed');
+ assert.deepEqual(parseSources('Nothing to link.'), []);
});