Skip to content

Unify search_semantic: wire all params through local agent, align tool schema, update prompts #1086

Closed

Description

@malibio

Background

This is a recurring pattern in NodeSpace. Prior unification work:

The root cause identified in #1060 comments still applies: tool definitions live in two places (`packages/core/src/mcp/handlers/search.rs` and `packages/agent/src/local_agent/tools.rs`) with no single source of truth, so drift recurs every time a param is added.

Current State

`SearchSemanticParams` (defined in `packages/core/src/mcp/handlers/search.rs`, re-exported via `packages/core/src/mcp/params.rs`) has 11 fields:

Field MCP handler Local agent tool schema Local agent executor
`query` ✅ ✅ ✅
`limit` ✅ ✅ ✅
`include_markdown` ✅ ✅ ✅ (fixed in #1081)
`collection` ✅ ✅ ✅ (fixed in #1081)
`threshold` ✅ ❌ ❌ hardcoded to `SEMANTIC_THRESHOLD` constant
`scope` ✅ ❌ ❌ hardcoded to `None`
`include_archived` ✅ ❌ ❌ hardcoded to `None`
`node_types` ✅ ❌ ❌ not wired
`property_filters` ✅ ❌ ❌ not wired
`exclude_collections` ✅ ❌ ❌ not wired
`rerank` ✅ ❌ ❌ not wired

Additionally, future enhancements from #1085 (edge context, graph scoring) will add more params that need to be exposed on both paths simultaneously.

Problem

The local agent's `exec_search_semantic` deserializes into `SearchSemanticParams` (which has all 11 fields) but then manually cherry-picks only the fields it recognizes, hardcoding the rest. Since the tool schema only declares 4 parameters, the LLM cannot request the others even if the executor were fixed.

This means the local agent has materially weaker search capability than MCP clients, and every new param added to MCP silently becomes a no-op on the local agent path until someone notices.

Proposed Changes

1. Wire all existing params through `exec_search_semantic`

In `packages/agent/src/local_agent/tools.rs`, replace the manual field extraction in `exec_search_semantic` with full pass-through of all `SearchSemanticParams` fields into `SearchSemanticInput`. Remove the hardcoded `SEMANTIC_THRESHOLD` override — use the param value, falling back to the constant only when not provided.

2. Expand `def_search_semantic` tool schema

Add the missing parameters to the JSON schema in `def_search_semantic()` so the LLM can actually use them:

  • `threshold` (float, optional) — minimum similarity score
  • `scope` (string enum, optional) — e.g. "workspace", "collection"
  • `include_archived` (boolean, optional) — whether to include archived nodes
  • `node_types` (array of strings, optional) — filter by node type
  • `exclude_collections` (array of strings, optional) — collections to exclude
  • `rerank` (boolean, optional) — enable reranking

`property_filters` is complex (array of objects) — assess whether it's useful enough for the LLM to express; document the decision either way.

3. Update prompts and skills

The `search_semantic` description and relevant skills (Research & Search skill, Tool Strategy Guide) need to be updated to:

  • Document the new parameters with usage guidance for a local LLM
  • Explain when to use `node_types` vs `collection` filtering
  • Explain `threshold` tuning (when to lower it for broader recall)
  • Keep guidance concise — the 8B model has limited context

Relevant files:

  • `packages/agent/src/prompt_assembler.rs` — Tool Strategy Guide and system prompt
  • `packages/agent/src/local_agent/skills.rs` (or equivalent) — Research & Search skill definition

4. Add parity test

Add a test that asserts every field in `SearchSemanticParams` is represented in `def_search_semantic()`'s JSON schema. This prevents future drift.

Acceptance Criteria

  • All `SearchSemanticParams` fields are wired through `exec_search_semantic` (no hardcoded `None` or constant overrides)
  • `def_search_semantic()` tool schema exposes all params the LLM should be able to control, with clear descriptions
  • `property_filters` inclusion/exclusion is explicitly decided and documented in code comment
  • Prompt and skill guidance updated to explain the new params with usage examples
  • Parity test added: tool schema fields ↔ `SearchSemanticParams` fields
  • Existing `search_semantic` integration tests pass
  • This fix is forward-compatible with search_semantic: expose missing opt-in parameters in local agent tool and add graph-aware enhancements #1085 (new params from edge context / graph scoring should slot in without another unification pass)

Out of Scope

Related

Activity

  1. added
    enhancement
    on Apr 10, 2026
  2. malibio commented on Apr 11, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 128 files, 3918 tests passed (0 failed)

  3. self-assigned this
    on Apr 11, 2026
  4. added a commit that references this issue on Apr 11, 2026
    0bc2f98
  5. malibio commented on Apr 11, 2026

    @malibio
    CollaboratorAuthor

    PR created: #1099

    All acceptance criteria met:

    • All SearchSemanticParams fields wired through exec_search_semantic (no hardcoded None or constant overrides)
    • def_search_semantic() schema exposes 9 params (threshold, scope, include_archived, node_types, exclude_collections, plus existing 4)
    • property_filters: wired through executor but excluded from LLM schema (too complex for 8B model, documented in code comment and parity test)
    • Prompt guidance updated in prompt_assembler.rs Tool Strategy Guide
    • Parity test added: search_semantic_schema_parity_with_params prevents future schema drift
    • All tests pass: 3918 frontend, 289 agent unit, 1163 core unit tests
    • quality:fix clean (0 errors, 0 warnings)
  6. added a commit that references this issue on Apr 14, 2026
    6fff0b9
  7. malibio commented on Apr 14, 2026

    @malibio
    CollaboratorAuthor

    PR #1102 merged. All 7 acceptance criteria met. Most work was done in #1085 (PR #1101); this PR completed the prompt/skill documentation and fixed the stale property_filters comment.

  8. malibio commented on Apr 17, 2026

    @malibio
    CollaboratorAuthor

    PR #1104 merged. All acceptance criteria met. Review passed clean.

  9. added 2 commits that reference this issue on Jun 22, 2026
    6150e41
    9d565bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendenhancementmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions