|
20 | 20 |
|
21 | 21 |
|
22 | 22 | @mcp.tool( |
23 | | - description="""Build context from a memory:// URI to continue conversations naturally. |
24 | | -
|
25 | | - Use this to follow up on previous discussions or explore related topics. |
| 23 | + description="""Navigates your knowledge graph by following relations from a starting point. Builds comprehensive context by traversing semantic connections, perfect for continuing conversations or exploring related concepts. |
| 24 | +
|
| 25 | +```yaml |
| 26 | +node: |
| 27 | + topic: build_context - Graph Traversal |
| 28 | + goal: Navigate knowledge graph via relations |
| 29 | + insight: Memory URLs enable conversation continuity |
| 30 | + context: |
| 31 | + traversal: Breadth-first with depth control |
| 32 | + patterns: ["memory://exact", "memory://folder/*", "memory://*"] |
| 33 | + performance: O(n^depth) complexity |
| 34 | + use_case: Continue discussions with full context |
| 35 | +``` |
| 36 | +
|
| 37 | +```baml |
| 38 | +class BuildContextInput { |
| 39 | + url string @pattern("memory://.*") @description("Memory URI pattern") |
| 40 | + project string? |
| 41 | + depth int @default(1) @range(1, 5) @description("Relation traversal depth") |
| 42 | + timeframe string @default("7d") @description("Period like '2 days ago'") |
| 43 | + types string[]? @description("Filter entity types") |
| 44 | + page int @default(1) |
| 45 | + page_size int @default(10) |
| 46 | + max_related int @default(10) |
| 47 | +} |
| 48 | +
|
| 49 | +class ContextResult { |
| 50 | + primary_results Note[] @description("Direct matches") |
| 51 | + related_results Note[] @description("Connected via relations") |
| 52 | + metadata ContextMetadata |
| 53 | +} |
| 54 | +
|
| 55 | +class ContextMetadata { |
| 56 | + depth int |
| 57 | + timeframe string |
| 58 | + primary_count int |
| 59 | + related_count int |
| 60 | + generated_at datetime |
| 61 | +} |
| 62 | +
|
| 63 | +function build_context(BuildContextInput) -> ContextResult { |
| 64 | + @description("Traverse knowledge graph from memory:// starting points") |
| 65 | + @complexity("O(n^depth)") |
| 66 | + @async(true) |
| 67 | +} |
| 68 | +``` |
| 69 | +
|
| 70 | +## Memory Patterns |
| 71 | +
|
| 72 | +- `memory://specs/search` - Exact note |
| 73 | +- `memory://specs/*` - All in folder |
| 74 | +- `memory://*` - Everything |
| 75 | +
|
| 76 | +## Traversal Examples |
| 77 | +```python |
| 78 | +# Continue discussion |
| 79 | +context = build_context("memory://discussions/api-design") |
| 80 | +
|
| 81 | +# Deep exploration (2 hops) |
| 82 | +context = build_context( |
| 83 | + "memory://architecture/microservices", |
| 84 | + depth=2, |
| 85 | + timeframe="30d" |
| 86 | +) |
26 | 87 |
|
27 | | - Memory URL Format: |
28 | | - - Use paths like "folder/note" or "memory://folder/note" |
29 | | - - Pattern matching: "folder/*" matches all notes in folder |
30 | | - - Valid characters: letters, numbers, hyphens, underscores, forward slashes |
31 | | - - Avoid: double slashes (//), angle brackets (<>), quotes, pipes (|) |
32 | | - - Examples: "specs/search", "projects/basic-memory", "notes/*" |
| 88 | +# Filtered traversal |
| 89 | +context = build_context( |
| 90 | + "memory://specs/*", |
| 91 | + types=["entity", "observation"] |
| 92 | +) |
| 93 | +``` |
33 | 94 |
|
34 | | - Timeframes support natural language like: |
35 | | - - "2 days ago", "last week", "today", "3 months ago" |
36 | | - - Or standard formats like "7d", "24h" |
37 | | - """, |
| 95 | +Performance: Depth 1: 100ms, Depth 2: 500ms, Depth 3+: May be slow""", |
38 | 96 | ) |
39 | 97 | async def build_context( |
40 | 98 | url: MemoryUrl, |
|
0 commit comments