PolicyEngine / PolicyEngine/policyengine-uk-chat
Conversation memory layer: persist households/scenarios across turns
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1
- Forks
- 1
- Avg merge
- 16h 46m
- Merged PRs (30d)
- 2
Description
Motivation
Today, every turn is a one-shot. If a user says "For a single earner, £45,000, in Scotland, what's the marginal rate at £60k?" and then asks a follow-up "What if they were married?", the agent has to re-derive the household from the conversation transcript, often imperfectly.
This kills comparative conversations — the killer feature of a tax/benefits chatbot. The user can't iteratively build up a scenario; they have to restate the full household in every turn.
Goal
Persist a structured active scenario across turns within a conversation:
{
"household": {
"earners": [{"employment_income": 45000, "marital_status": "single"}],
"children": 0,
"country": "Scotland",
"year": 2025
},
"reform": null,
"comparison_baseline": "current_law"
}
The agent reads from and writes to this slot every turn. Follow-up questions like "What if they were married?" mutate marital_status and re-run, instead of re-extracting the entire household from scrollback.
Scope sketch (for discussion before implementation)
- Backend: add an
active_scenariofield to the conversation (server-side state, persisted alongside messages in Supabase). New toolupdate_scenario(patch)for the agent to mutate it. New toolget_scenario()exposes the current state. - System prompt: tell the agent to read
active_scenarioat the top of every turn and callupdate_scenariowhenever the user introduces or modifies household/reform parameters. Default policy: ambiguous changes get a Plan-mode-style clarifying question. - Frontend: subtle "Active scenario: single earner, £45k, Scotland" pill above the input chrome with an X to clear. Click → modal showing the structured state, with a "reset scenario" button.
- Conversation save/load: round-trip
active_scenariothrough the conversation document so it survives reloads and sharing.
Open questions
- Granularity: scenario per conversation, or per message? Likely per-conversation, with the agent able to fork it.
- Display: how much of the scenario to show in the pill (one-line summary) vs. modal (full structure)?
- Conflict with Plan mode: Plan mode asks clarifying questions before tools run; scenario memory wants the agent to use existing state. Probably composable but worth a careful look.
- Vs. typed tools (PR #55): typed tools already accept structured
household+reformargs; this issue is about persisting them across calls, not just typing them.
Why this is the next big lever
The chat-box UX is now saturated (10 features shipped in the last 24h). The next leap in user value comes from making conversations actually compositional — "like the household I described 3 messages ago, but bump UC by 10%" should just work.
Related: depends on / composes with #81 typed reform tools (typed-args make the scenario easier to express), and benefits from #85 reform recipes (recipes inform what to memoize).
Suggested next step
This is bigger than the recent batch — recommend a short design doc / discussion before implementation. Tag this as needs-design and discuss in PR form before code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the conversation document and message persistence, the typed tools in issue #81, and the Supabase save/load path described here; then review the system-prompt and frontend scope. Done means a design decision covers scenario ownership, mutation and reset behavior, Plan mode interaction, display, and round-tripping before implementation begins.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, supabase
- Domain
- backend, database, frontend, full-stack
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100