<proposed_plan>
# Assistant Prompt Context Plan
Summary
Before changing assistant behavior, first add a prompt-context helper that injects known dataset briefing/profile content into the main assistant prompt when a session has dataset context. This gives the main agent the facts it already has, so it can stop asking the user to restate schema, dataset IDs, coverage, or existing limitations.
Exact Prompt Changes
Current RESEARCH_AGENT_INSTRUCTIONS in src/worker.ts includes:
'If the user input is gibberish, a greeting, or too vague to identify an action, do not call tools. Ask a concise clarifying question instead.',
'Do not inspect datasets or runs just to recover from unclear input.',
'Prefer lightweight dataset queries before launching heavy transforms or analyses when the user wants examples, top records, or simple slices.',
'Do not answer with generic numbered menus when you can inspect the user datasets or runs and propose one concrete next action.',
Planned replacement:
'If the user input is gibberish, a greeting, or too vague to identify a research/data action, do not call tools. Ask one concise clarifying question instead.',
'When a dataset is named, implied, or attached to the current page/session, use the provided dataset context first. Do not ask the user for dataset ids, schema, coverage, or briefing facts that are already present in the prompt.',
'If the request is underspecified but the dataset context supports a likely next step, propose one concrete default action with assumptions instead of asking a multi-question menu.',
'Prefer lightweight dataset queries before launching heavy transforms or analyses when the user wants examples, top records, simple slices, schema checks, or field availability.',
'Do not answer with generic numbered menus when you can inspect the user datasets or runs, use provided dataset context, and propose one concrete next action.',
No ACS/PUMS-specific prompting change will be made in this first step.
Add Dataset Contents Helper
Add a helper near the existing session/prompt helpers in src/worker.ts:
async function datasetContentsForPrompt(env: Env, datasetId: string) {
// Fetch /datasets/:id/profile.
// Return an empty string if there is no profile or no useful contents.
// Include one or more bounded sections:
// - Dataset briefing markdown
// - Dataset profile JSON
// - Schema JSON
// - Sample rows JSON
// - Notes
}
The helper will format content like:
Dataset context files:
<dataset_briefing_markdown>
...
</dataset_briefing_markdown>
<dataset_profile_json>
...
</dataset_profile_json>
<dataset_schema_json>
...
</dataset_schema_json>
<dataset_sample_rows_json>
...
</dataset_sample_rows_json>
It will be conditional:
- Include
briefingMarkdown when present.
- Include
profile when present.
- Include
schema and sampleRows when present.
- Include
notes when present.
- Return nothing when none exist.
- Apply size caps per section and total prompt budget so a large briefing cannot dominate the whole request.
Wire Into Main Agent Prompt
Current dataset-page prompt construction is:
assistantInput = [
`Current dataset context: ${datasetName} (${datasetId}).`,
datasetDescription ? `Dataset summary: ${datasetDescription}` : null,
'The user started from this dataset page, so treat this dataset as the default context and do not ask them to restate the dataset id.',
'If the request is broad or ambiguous, clarify scope before inspecting more data or starting an expensive run.',
'',
`User request: ${input}`,
].filter(Boolean).join('\n')
Planned replacement:
const datasetPromptContents = await datasetContentsForPrompt(env, datasetId)
assistantInput = [
`Current dataset context: ${datasetName} (${datasetId}).`,
datasetDescription ? `Dataset summary: ${datasetDescription}` : null,
'The user started from this dataset page, so treat this dataset as the default context and do not ask them to restate the dataset id.',
datasetPromptContents || null,
'Use the dataset context above before asking the user for schema, coverage, field availability, briefing, or dataset identity details.',
'If the request is broad or ambiguous, propose a concrete scoped next step with assumptions before asking for more information.',
'',
`User request: ${input}`,
].filter(Boolean).join('\n')
Fallback path when dataset fetch fails will stay mostly unchanged, except the ambiguity sentence becomes:
'If the request is broad or ambiguous, propose a concrete scoped next step with assumptions before asking for more information.',
Tests
Add harness validation in scripts/validate-harness.mjs to assert:
datasetContentsForPrompt exists.
- Main assistant prompt includes dataset briefing/profile context.
- Prompt text says not to ask for schema/coverage/field availability already present in prompt.
- Existing
plan_remote_run approval gate remains present.
Run:
pnpm build
pnpm test
pnpm run qa:dashboard
Assumptions
- “Briefing files” means the persisted dataset profile fields already available from
/datasets/:id/profile: briefingMarkdown, profile, schema, sampleRows, and notes.
- This first change improves grounding without yet adding ACS/PUMS-specific resolver logic.
- Prompt-injected dataset contents should be bounded, not full unbounded artifacts.</proposed_plan>