Skip to content

fix: programmatic pronoun resolution for congressional trades#62

Merged
agarg5 merged 2 commits intomainfrom
feature/fix-pronoun-resolution
Mar 1, 2026
Merged

fix: programmatic pronoun resolution for congressional trades#62
agarg5 merged 2 commits intomainfrom
feature/fix-pronoun-resolution

Conversation

@agarg5
Copy link
Owner

@agarg5 agarg5 commented Mar 1, 2026

Summary

  • Adds _resolve_context() pre-processing step in agent/src/main.py that scans recent AI messages for politician names when the user's message contains pronouns (her/his/hers/she/he/their/them)
  • Injects an explicit [Context: the pronoun refers to {name}] note so the LLM resolves correctly instead of guessing
  • Uses word-boundary regex to avoid false positives (e.g. "therapist" won't trigger on "her")
  • Original message stored in chat history; only the enriched message goes to the agent

Test plan

  • 8 new unit tests in test_chat_history.py covering all edge cases
  • All 26 tests pass (pytest tests/test_chat_history.py -v)
  • Manual test: "Show me Nancy Pelosi's recent trades" → "How does my performance compare to hers?" should resolve to Pelosi

🤖 Generated with Claude Code

…ow-ups

When users ask about a politician's trades and follow up with pronouns
("hers", "his"), the agent incorrectly resolved to the wrong person.
Add a _resolve_context() pre-processing step that scans recent AI messages
for politician names and injects explicit context before the LLM sees the
message. Uses word-boundary matching to avoid false positives.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@agarg5
Copy link
Owner Author

agarg5 commented Mar 1, 2026

Code review

No issues found. Tests passing (26/26). Checked for bugs, regressions, and CLAUDE.md compliance.

Note: PR also includes a small adjacent fix — history_key and the /chat/history endpoints now use _extract_user_id(token) instead of raw token, so chat history persists across JWT reissues. This is bundled but low-risk.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@agarg5 agarg5 merged commit daccfad into main Mar 1, 2026
1 check passed
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.

1 participant