Skip to content

fix(reflect): disable source facts in search_observations to prevent context overflow#669

Merged
nicoloboschi merged 1 commit intovectorize-io:mainfrom
kagura-agent:fix/reflect-source-facts-overflow
Mar 24, 2026
Merged

fix(reflect): disable source facts in search_observations to prevent context overflow#669
nicoloboschi merged 1 commit intovectorize-io:mainfrom
kagura-agent:fix/reflect-source-facts-overflow

Conversation

@kagura-agent
Copy link
Contributor

Summary

The reflect agent's search_observations hardcodes 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 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() in hindsight-api-slim/hindsight_api/engine/reflect/tools.py unconditionally 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=False in the reflect agent's search_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 lines

Alternative 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.

…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
Copy link
Collaborator

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

but I will probably add a configurable option in the future

@nicoloboschi nicoloboschi merged commit 8e2e2d5 into vectorize-io:main Mar 24, 2026
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
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
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.

Reflect search_observations hardcodes unlimited source facts, silently breaking reflect on any non-trivial bank

2 participants