Skip to content

feat(mcp): add compact graph context discovery - #1516

Merged
phernandez merged 2 commits into
mainfrom
feat/686-compact-context
Sep 8, 2026
Merged

phernandez merged 2 commits into
mainfrom
feat/686-compact-context

Conversation

@phernandez

@phernandez phernandez commented Sep 8, 2026

Copy link
Copy Markdown
Member

Why

Graph discovery currently returns note and observation bodies before an agent chooses which notes to read. Refs #686; complements compact search in #1515.

What Changed

Adds opt-in build_context(compact=True). JSON omits content fields while preserving graph identities, observation categories, relation targets, counts and pagination. Observation labels use categories and their permalinks point to the owning file instead of repeating source prose. Text omits note bodies and the observation section. The default response remains unchanged.

Implementation Details

JSON uses Pydantic serialization exclusions at the MCP boundary, keeping API models and traversal unchanged. The existing Markdown formatter accepts the same compact flag. The manual and tool-signature contract describe the new argument.

Testing

  • uv run pytest test-int/mcp/test_compact_context_integration.py tests/mcp/test_tool_contracts.py tests/mcp/test_tool_build_context.py -q --no-cov: 17 passed.
  • BASIC_MEMORY_TEST_POSTGRES=1 uv run pytest test-int/mcp/test_compact_context_integration.py -q --no-cov: 1 passed.
  • uv run pytest tests/mcp/test_compact_context_labels.py -q --no-cov: 1 passed; primary and related observation labels preserve owner navigation without mutating the original graph.
  • The real MCP scenario creates linked notes and a long observation, compares graph/page data, verifies a response below half the original size on that fixture, and reads the selected note by returned UUID.
  • just man-regen, just fast-check, just doctor, and git diff --check: passed.

Risks / Follow-ups

This reduces MCP output, not API/database work. Titles and graph size still contribute tokens; it is not a fixed token budget. This does not implement all proposed L0/L1/L2 tiers or change defaults, so #686 remains open. CLI exposure is a separate follow-up.

Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez added this to the v0.24.0 milestone Sep 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T05:07:33.597478Z e99f67d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a56d6d8da3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/mcp/tools/build_context.py
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: e99f67dab7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@phernandez

Copy link
Copy Markdown
Member Author

CI follow-through: Windows lifecycle repetition 1 failed in test_concurrent_write_high_volume with QueuePool exhaustion and the test timeout. This probe does not call build_context or use compact responses. The other two Windows repetitions and all six Linux/macOS repetitions passed on the same head. Rerunning the failed job to check the intermittent failure; no source changes made.

@phernandez
phernandez merged commit 2e86b42 into main Sep 8, 2026
45 of 46 checks passed
@phernandez
phernandez deleted the feat/686-compact-context branch September 8, 2026 13:40
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