Improve chat agent prompts, citation linking, and tool-call handling#177
Merged
Conversation
sandragjacinto
force-pushed
the
feat/improve-chat-prompts
branch
from
July 15, 2026 12:45
7d9eb1c to
61e3844
Compare
sandragjacinto
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This branch covers several rounds of chat-agent behavior fixes:
cd5cef0,6c540c6): rewrote the agent system prompt, fixed language detection, added citation grounding, and fixed a multi-tool-call issue.7bdcfc7, revertedc8a562c, reapplied37ce28e): caps the retrieval tool to one call per turn, and stops follow-up turns without a tool call from clearing the frontend's docs panel.fix(chat): enforce response brevity as a hard constraint— responses were producing full course structures from minimal context (e.g. a user just stating their role).fix(chat): forbid links outside retrieved documents— the agent was still emitting links from its own training data, often stale/dead URLs.feat(chat): add Socratic clarifying-question behavior— the agent now asks up to 3 targeted clarifying questions at the start of a conversation or on a topic shift, instead of answering at length on minimal context.fix(chat): reorient follow-up questions to WeLearn's pedagogical use case— both the agent's own follow-up question and the separate/reformulate/questionssuggestions now focus on moving a professor from understanding a topic to applying it in their teaching, instead of generic "keep learning about SDGs" framing.fix(chat): auto-link citations the model forgets to format— adds a regex-based fallback (linkify_missing_citations) that catches citation markers the model left unlinked and wraps them using the URL already returned by the retrieval tool, applied to both the streaming and non-streaming chat endpoints.src/app/tutor/service/agents.py.Two issues investigated but not addressed in this branch (documented, deferred):
Test plan
flake8/isort/blackclean on all changed fileslinkify_missing_citationsinsrc/app/tests/services/test_helpers.pymake test-poetryrun (blocked locally by an unrelatedtransformers/huggingface_hubversion mismatch tied to an in-progress dependency bump — re-run once that's resolved)make run-poetry: confirm short responses + clarifying questions on a minimal prompt, no external links, and citations render as clickable links🤖 Generated with Claude Code