Fix: Connect resource extraction to main chat flow for @document_name mentions #40
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.
Problem Statement
The resource extraction functionality was implemented but completely disconnected from the main chat flow. When users typed queries like
"Tell me about @report.pdf"
, the system would:@
mentions in code ✅The
_extract_resources()
and_process_query()
methods existed but were never called, causing the AI to receive raw queries without document context.What Was Broken Before:
Original Problem:
The resource extraction code existed but was completely disconnected from the main chat flow. Here's what happened:
The
_extract_resources()
and_process_query()
methods existed incli_chat.py
but were NEVER CALLED!Root Cause:
Instead of using resources, the system was incorrectly trying to use tools with the "@" symbol included in the document ID, which doesn't exist.
What I Changed to Fix It:
Key Fix: Override the
run()
method inCliChat
After (working):
Current Working Flow:
Complete Step-by-Step Flow:
Detailed Code Changes:
1. Added
run()
method override inCliChat
(core/cli_chat.py
):Why It Works Now:
Method Inheritance Chain:
Key Insight:
The original code had all the right pieces (
_extract_resources
,_process_query
) but they were like disconnected functions that never got called. By overriding therun()
method inCliChat
, I connected the resource processing pipeline to the main chat flow.Most importantly, this fix ensures that:
Testing Results:
Before Fix:
(System was trying to call tool with ID "@report.pdf" which doesn't exist)
After Fix:
$ uv run main.py > Tell me about @report.pdf Response: The report details the state of a 20m condenser tower.
Multiple Resources:
Impact:
✅ Before: AI tried to use tools with "@report.pdf" → tool failed → "document not found"
✅ After: AI gets enhanced prompt with document content via resources → answers perfectly
What Now Works:
@document_name
mentions are properly extracted and @ is stripped@
mentions in single queryNo Breaking Changes:
Files Modified:
core/cli_chat.py
:run()
method override to connect resource processingThe fix was essentially connecting the dots between the existing resource extraction code and the main chat execution flow by overriding the
run()
method inCliChat
. This ensures that the system properly uses MCP resources (not tools) for document access, making the functionality work as intended for the learn-agentic-ai course materials.