Skip to content

Version-1 changes for Maple Chatbot pr_2198_bot - #2218

Open
vkavith wants to merge 7 commits into
codeforboston:mainfrom
vkavith:maple_pr_2198_bot
Open

Version-1 changes for Maple Chatbot pr_2198_bot#2218
vkavith wants to merge 7 commits into
codeforboston:mainfrom
vkavith:maple_pr_2198_bot

Conversation

@vkavith

@vkavith vkavith commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Maple Chatbot where a User can ask Questions about Bill/Policy issue question answering chat

ReAct AI agent with tool calling and reasoning loop capability

Access to firebase vector index search

Add a short summary of the changes, and a reference to the original issue using # and the issue number, like #1

Checklist

  • On the frontend, I've made my strings translate-able.
  • If I've added shared components, I've added a storybook story.
  • I've made pages responsive and look good on mobile.
  • If I've added new Firestore queries, I've added any new required indexes to firestore.indexes.json (Please do not only create indexes through the Firebase Web UI, even though the error messages may reccommend it - indexes created this way may be obliterated by subsequent deploys)

Screenshots

Add some screenshots highlighting your changes.

Known issues

If you've run against limitations or caveats, include them here. Include follow-up issues as well.

Steps to test/reproduce

For each feature or bug fix, create a step by step list for how a reviewer can test it out. E.g.:

  1. Go to the home page
  2. Click on a testimony
  3. See that it's loaded with a loading spinner

@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
maple-dev Ready Ready Preview Aug 28, 2026 7:36pm

Request Review

Comment thread .venv/bin/activate Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

venv to be removed

Comment thread llm/requirements.txt

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code in llm/ not relevant to this PR, so I recommend not modifying the requirements here

@nesanders nesanders left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is initial high level feedback.

@@ -0,0 +1,104 @@
import { useState, useRef, useEffect } from "react"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big open question is if we should be authoring our own chat widget or adopting a framework like copilotkit instead.

Comment thread docs/REACT_AGENT_ARCHITECTURE.md

// Logged-in users: persistent monthly token budget, tracked in the
// top-level `llmUsage` collection (see usage.ts).
loggedInMonthlyTokenBudget: 50_000

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These default budgets might be too small to be useful for either logged in or anonymous users, but we can modify later

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed that we can decide on changing this later

---

## Backfilling Existing Documents

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything we actually need to backfill? I think we already have the relevant embeddings for bills, questions, and testimony in the index.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From our discussion, sounds liek this is extraneous and can be deleted

Comment thread functions/package.json Outdated
"rimraf": "^3.0.2",
"ts-jest": "^29.2.5",
"typescript": "4.5.5"
"typescript": "^5.5.4"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we will update typescript version as part of this PR, though w may do so later for other reasons

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You updated this - thanks! However, you are adding the carrot in ("^") - I don't think we need to do that, either.

Comment thread functions/package.json Outdated
Comment thread functions/src/llm/vectorSearchTools.ts Outdated
Comment thread functions/src/llm/vectorSearchTools.ts Outdated
import { httpsCallable } from "firebase/functions"
import { functions } from "components/firebase"
import { useAuth } from "components/auth"
import styles from "./ChatWidget.module.css"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to add a mock frontend pag that just exposes this widget on a placeholder page for initial testing purposes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is outstanding

Comment thread functions/src/llm/agent.ts
Comment thread functions/src/llm/policySearch.ts Outdated

// Merge by interleaving: pick the lower-rank item from each list at each
// step, which preserves the relative relevance ordering from Firestore.
const merged: string[] = []

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document the design decision of why we are returnign interleaved resuls for bills and BQs. If this is the same logic as the MCP server, we should import from there or modularize the function into a different module. If it is different logic, we should explain why.

@nesanders

nesanders commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Just noting - this PR does not yet introduce a data model for storing user chat histories. We should either introduce a basic framework for this here or capture an issue to do so later.

We should be able to use https://reference.langchain.com/python/langchain-community/chat_message_histories/firestore/FirestoreChatMessageHistory for this. We will need to decide whether to add this as a separate firestore db or as a new collection or something else. it is a top priority to enforce user-level access so each user can only access their own conversation history.

@nesanders

Copy link
Copy Markdown
Collaborator

To keep the context size limited and avoid spending a lot of tokens, the bill retrieval search tool should by default retrieve only the summary field of the bill document. The fulltext should be retrievable by the tool, too, but not by default.

Comment thread firestore.rules
allow read: if true;
allow write: if false;
}
<<<<<<< HEAD

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a dangling merge error that needs to be cleaned up.

@@ -0,0 +1,25 @@
export const LLM_CONFIG = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: We also need a top level circuit breaker. Regardless of the individual usage limits below, we need to configure a limit on the total monthly spend of the feature so it doesn't go out of control. We could potentially configure that at the google cloud project level, not necessarily in the code here.

*/
export const askQuestion = functions
.runWith({ timeoutSeconds: 120, memory: "512MB" })
.https.onCall(async (data, context) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need some limit to scaling here to prevent overuse. A maxinstances limit here might help.

}

return merged.slice(0, topK * 2).join("\n\n")
// Merge all results and sort by relevance score descending — same approach

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we don't modularize the relevance score logic between the MCP server and chat agent tools, can we at least cite the alignment betwen them by linking here?

// Bills (H1234) and ballot questions (25-12) have structurally distinct IDs —

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be ideal to modularize and import this logic from a single function def, but it is ok if we do not do that in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants