Skip to content

feat: context assembly for building rich prompts from knowledge graph - #1022

Merged
malibio merged 1 commit into
mainfrom
feature/issue-1005-context-assembly
Apr 3, 2026
Merged

malibio merged 1 commit into
mainfrom
feature/issue-1005-context-assembly

Conversation

@malibio

@malibio malibio commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Implements GraphContextAssembler for packaging knowledge graph data into agent prompts
  • Semantic expansion, relationship traversal, token budget enforcement

Closes #1005

Co-Authored-By: Claude [email protected]

…closes #1005)

Implements GraphContextAssembler that gathers knowledge graph data and
packages it into structured prompts for external agents. Includes
semantic expansion, relationship traversal, and token budget enforcement.

Co-Authored-By: Claude <[email protected]>
@malibio
malibio force-pushed the feature/issue-1005-context-assembly branch from fda7ee9 to d76923e Compare April 3, 2026 22:57
@malibio
malibio merged commit 32929b6 into main Apr 3, 2026
@malibio
malibio deleted the feature/issue-1005-context-assembly branch April 3, 2026 22:57
@malibio

malibio commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator Author

Post-Merge Code Review: PR #1022 (Context assembly for agent prompts)

Verdict: Clean -- no critical issues found.

Findings

Suggested Improvements

  • Token budget accounting is slightly generous: In build_context_markdown(), the "### Selected Nodes\n\n" section header tokens are subtracted from remaining_budget after the seed nodes are already added. This means seed nodes might consume slightly more budget than intended. In practice, the header is small (~6 tokens) so this won't cause actual budget overruns, and the comprehensive test_budget_enforcement_never_exceeds test validates behavior across multiple budget values. Priority: Low.

  • make_context_node filters relationships by title string comparison (line ~418-421 in the diff), not by node ID. If two nodes share the same title, relationships could be misattributed. Consider matching on node.id instead of node_title(node).

Notes

  • Well-designed assembly pipeline: seed fetch -> semantic expansion -> relationship traversal -> budget enforcement.
  • Priority-based truncation (seeds > relationships > neighbors) is the right call.
  • Graceful degradation: embedding service unavailable = skip semantic expansion, missing seed nodes = skip with warning.
  • Character-safe truncation using floor_char_boundary() prevents panics on multi-byte content.
  • 20 unit tests including budget enforcement with multiple sizes.

No critical follow-up fixes required. The title-matching issue is worth filing as a low-priority bug.

malibio added a commit that referenced this pull request Jun 22, 2026
…closes #1005) (#1022)

Implements GraphContextAssembler that gathers knowledge graph data and
packages it into structured prompts for external agents. Includes
semantic expansion, relationship traversal, and token budget enforcement.

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
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.

Context assembly: build rich prompts from knowledge graph

1 participant