Skip to content

feat: fact_types and mental model exclusion filters for reflect#615

Merged
nicoloboschi merged 13 commits intomainfrom
reflect
Mar 19, 2026
Merged

feat: fact_types and mental model exclusion filters for reflect#615
nicoloboschi merged 13 commits intomainfrom
reflect

Conversation

@nicoloboschi
Copy link
Collaborator

Summary

  • Adds fact_types filter to restrict which fact types (world, experience, observation) are retrieved during reflect — disabled tools are removed from the agent's tool list entirely (no wasted tokens)
  • Adds exclude_mental_models flag to skip the search_mental_models tool altogether
  • Adds exclude_mental_model_ids to exclude specific mental models by ID (merged with the existing self-exclusion during mental model refresh)
  • All three options are available on both the /reflect endpoint and mental model create/update — stored in the existing trigger JSONB column so they apply automatically on every refresh
  • Fixes pg0_db_url test fixture to correctly resolve pg0:// URLs and run migrations, which was causing all DB-dependent tests to fail with relation "public.banks" does not exist

Test plan

  • TestMentalModelReflectOptions — trigger field roundtrip for all three new options (create + update)
  • TestReflectFactTypeFiltering — verifies correct tools are excluded from agent loop
  • TestReflectRequestValidation — HTTP 422 for empty fact_types=[]
  • All existing reflect/mental model tests pass (126 passed locally)

…d mental models

Adds three new filtering options to both the reflect endpoint and mental model creation/refresh:

- `fact_types`: restrict which fact types (world, experience, observation) are retrieved.
  Disables irrelevant agent tools entirely (no wasted tokens).
- `exclude_mental_models`: skip the search_mental_models tool altogether.
- `exclude_mental_model_ids`: exclude specific mental models by ID (merged with the
  existing self-exclusion logic during mental model refresh).

For mental models, options are persisted in the existing `trigger` JSONB column so they
are automatically applied on every refresh. The `UpdateMentalModelRequest` already
proxies `trigger`, so no extra endpoint changes are needed.

Also fixes the test fixture (`pg0_db_url` in conftest.py) to correctly resolve pg0://
URLs and run migrations before tests, which was causing all DB-dependent tests to fail
with "relation public.banks does not exist" when HINDSIGHT_API_DATABASE_URL=pg0://uuuu.
- Add enabled_tools guard in reflect agent: if an LLM calls a tool that
  was excluded (e.g. recall when fact_types=["observation"]), return an
  error result instead of executing it
- Regenerate OpenAPI spec and all SDK clients (Go, Python, TypeScript)
  to include new fact_types / exclude_mental_models fields
@nicoloboschi nicoloboschi merged commit ea662d0 into main Mar 19, 2026
39 of 40 checks passed
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