Skip to content

Format all agent RAG tool results as human-readable text#173

Merged
asim merged 3 commits intomainfrom
copilot/fix-markets-card-data-issue
Mar 2, 2026
Merged

Format all agent RAG tool results as human-readable text#173
asim merged 3 commits intomainfrom
copilot/fix-markets-card-data-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

The AI synthesizer was claiming it had no data (e.g. "I don't have access to the current bitcoin price") even when tools had successfully returned results, because raw JSON (or raw HTML from the search tool) was being passed into the RAG context — hard for the model to reliably extract values from.

Changes

agent/agent.go

  • Replaced the ad-hoc if/else RAG-formatting chain with a central formatToolResult(toolName, result, args) dispatcher covering every tool
  • Added human-readable text formatters for all previously unformatted tools:
    • formatNewsResult — handles both {"feed":[...]} and {"results":[...], "query":"..."} shapes
    • formatVideoResult — numbered titles + channel names
    • formatWeatherResult — current conditions + 5-day forecast; uses PascalCase field names matching actual WeatherForecast struct serialization
    • formatReminderResult — name of Allah, verse, hadith, message
    • formatSearchResult — tries JSON; falls back to stripHTMLTags since /search returns a full HTML page
    • formatBlogResult — numbered posts with author, tags, content snippet
    • formatWebSearchResult — numbered results with title and snippet
  • Added stripHTMLTags helper (collapses whitespace, caps at 2000 chars)

Example output passed to the synthesizer for a markets query:

Live crypto market prices:
- BTC: $97,000.12 (24h change: +1.23%)
- ETH: $3456.78 (24h change: -0.45%)

agent/agent_test.go

  • Added tests for each new formatter covering the normal, empty-data, and invalid-JSON/fallback cases, plus the central dispatcher and stripHTMLTags

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: asim <17530+asim@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix data access issue in markets card Fix agent treating live market data as unavailable in synthesized response Mar 2, 2026
Copilot finished work on behalf of asim March 2, 2026 20:37
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Copilot AI changed the title Fix agent treating live market data as unavailable in synthesized response Format all agent RAG tool results as human-readable text Mar 2, 2026
Copilot finished work on behalf of asim March 2, 2026 20:56
@asim asim marked this pull request as ready for review March 2, 2026 21:04
@asim asim merged commit 0bffb0c into main Mar 2, 2026
@asim asim deleted the copilot/fix-markets-card-data-issue branch March 2, 2026 21:05
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