fix(reflect): disable source facts in search_observations to prevent context overflow#669
Merged
nicoloboschi merged 1 commit intovectorize-io:mainfrom Mar 24, 2026
Conversation
…context overflow search_observations in the reflect agent hardcoded include_source_facts=True with max_source_facts_tokens=-1 (unlimited). For banks with many observations backed by thousands of facts, a single tool call could produce 300K+ tokens, exceeding the default 100K context budget and causing forced synthesis with an empty 'Retrieved Data' section. The reflect agent synthesizes from observations, not raw backing facts. Disable source facts to keep payloads proportional to observation count (~6K vs ~310K in the reporter's case). The consolidation path already has configurable source fact limits (PR vectorize-io#509, v0.4.17). The reflect path was not updated. Fixes vectorize-io#668
nicoloboschi
approved these changes
Mar 24, 2026
Collaborator
nicoloboschi
left a comment
There was a problem hiding this comment.
LGTM
but I will probably add a configurable option in the future
nicoloboschi
added a commit
that referenced
this pull request
Mar 25, 2026
The recent fix (#669) hardcoded include_source_facts=False in search_observations to prevent context overflow. This makes it configurable via HINDSIGHT_API_REFLECT_SOURCE_FACTS_MAX_TOKENS (env/tenant/bank), defaulting to -1 (disabled). - -1: source facts disabled (current behavior, default) - 0: source facts enabled with no token limit - >0: source facts enabled with a token budget
4 tasks
nicoloboschi
added a commit
that referenced
this pull request
Mar 25, 2026
…688) * feat(reflect): make source facts in search_observations configurable The recent fix (#669) hardcoded include_source_facts=False in search_observations to prevent context overflow. This makes it configurable via HINDSIGHT_API_REFLECT_SOURCE_FACTS_MAX_TOKENS (env/tenant/bank), defaulting to -1 (disabled). - -1: source facts disabled (current behavior, default) - 0: source facts enabled with no token limit - >0: source facts enabled with a token budget * docs: add reflect_source_facts_max_tokens to configuration reference * fix: update configurable fields count in tests and regenerate docs skill
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
The reflect agent's
search_observationshardcodesinclude_source_facts=Truewithmax_source_facts_tokens=-1(unlimited). For banks with many observations backed by thousands of facts, a single tool call produces 300K+ tokens, exceeding the default 100K context budget. This forces early synthesis with an empty "Retrieved Data" section, causing reflect to return "No information available" despite the data existing.Fixes #668.
Root Cause
search_observations()inhindsight-api-slim/hindsight_api/engine/reflect/tools.pyunconditionally includes all source facts with no token limit. The consolidation path already has configurable limits (PR #509, v0.4.17), but the reflect path was not updated.Fix
Set
include_source_facts=Falsein the reflect agent'ssearch_observations. The reflect agent synthesizes from observations, not raw backing facts — source facts are unnecessary overhead here.This reduces payload from ~310K tokens to ~6K tokens for the reporter's bank (230 observations, ~2,400 facts).
Changes
hindsight-api-slim/hindsight_api/engine/reflect/tools.py: 1 file, +2/-3 linesAlternative Considered
Adding per-bank config (
reflect_source_facts_max_tokens) to mirror the consolidation path. Opted for the simpler fix since reflect does not use source facts in its synthesis prompt.