Skip to content

Experiment with fact shards to reduce token usage#2919

Draft
whabanks wants to merge 1 commit into
mainfrom
experiment/ai-fact-shards
Draft

Experiment with fact shards to reduce token usage#2919
whabanks wants to merge 1 commit into
mainfrom
experiment/ai-fact-shards

Conversation

@whabanks

@whabanks whabanks commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary | Résumé

This PR experiments with "fact shards" in an attempt to reduce token usage for the api-endpoint-builder agent. Patterns and code examples were pulled out of the base agent file and placed into individual fact shard files that are then referenced by that agent.md file.

Since the entire agent.md file is loaded into context with each new chat, a small amount of conditional loading was put in place to help guide the agent when it decides what shards to pull into context when responding to a prompt.

A full breakdown with 4 test cases can be read here: https://github.com/cds-snc/notification-api/wiki/Fact-shards-experiment-results. In short:

✅ When a prompt maps well to documented patterns / fact shards token usage seems to be significantly reduced
🔴 When the AI loads fact shards + has to perform it's own exploration of the codebase for patterns - token usage is negatively impacted
⚠️ When constraints are placed on exploration depth token usage is decreased - unclear how output quality is affected by exploration constraints

Related Issues | Cartes liées

Test instructions | Instructions pour tester la modification

TODO: Fill in test instructions for the reviewer.

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

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