Skip to content

Agent tool executor: graph operation tools for local agent #1007

Closed

Description

@malibio

Overview

Implement the AgentToolExecutor that exposes NodeSpace graph operations as tools the local agent can call. Each tool wraps a NodeService or NodeEmbeddingService method with JSON schema validation and result formatting optimized for the local model's context budget.

Can be developed against mock NodeService in parallel with the agent loop (#1005).

Acceptance Criteria

  • AgentToolExecutor trait from Shared types, traits, and interface contracts for agent subsystems #998 fully implemented
  • All 7 tools implemented with correct JSON Schema definitions
  • Argument validation rejects invalid inputs with helpful error messages (model can self-correct)
  • Results formatted concisely (token-efficient for 8k context budget)
  • Long node bodies truncated to 500 chars with [truncated] indicator
  • Node IDs always included in results for follow-up tool calls
  • Error handling: missing node, invalid ID, search failures all return structured errors
  • Never panics — all errors returned as ToolResult { success: false }
  • Unit tests with mock NodeService for each tool
  • Integration test: execute search_nodes against real NodeService with test data
  • Code passes bun run quality:fix

Technical Specifications

New Module

  • packages/desktop-app/src-tauri/src/local_agent/tools.rs

Tool Definitions

1. search_nodes

  • Description: Search for nodes by keyword or structured query
  • Params: { query: string, node_type?: string, limit?: integer (default 10) }
  • Returns: Array of node summaries (id, title, type, snippet)

2. search_semantic

  • Description: Find nodes semantically related to a query
  • Params: { query: string, limit?: integer (default 5), collection?: string }
  • Returns: Ranked results with similarity scores

3. get_node

  • Description: Get full content of a node by ID
  • Params: { id: string }
  • Returns: Complete node (title, body truncated to 2000 chars, properties, type)

4. create_node

  • Description: Create a new node with content
  • Params: { title: string, body?: string, node_type: string, properties?: object, parent_id?: string }
  • Returns: Created node ID

5. update_node

  • Description: Update an existing node
  • Params: { id: string, title?: string, body?: string, properties?: object }
  • Returns: Success confirmation

6. create_relationship

  • Description: Create a relationship between two nodes
  • Params: { from_id: string, to_id: string, relationship_type: string }
  • Returns: Success confirmation

7. get_related_nodes

  • Description: Get all nodes related to a given node
  • Params: { id: string, relationship_type?: string, direction?: "in" | "out" | "both" (default "both") }
  • Returns: Array of related nodes with relationship info

Argument Validation

  • Validate incoming JSON against each tool's schema before executing
  • Return structured error if validation fails:
    ToolResult { success: false, output: "Error: 'query' is required for search_nodes. Expected: { query: string, limit?: number }" }
    
  • Model can use error message to self-correct on next iteration

Result Formatting

  • Optimize for token efficiency (local model has 8k context budget)
  • Node summaries: [id:abc123] "Title" (type) — first 100 chars of body
  • Full nodes: include properties as key: value pairs, body truncated to 2000 chars
  • Search results: include match count, ranked list
  • Always include node IDs so model can reference them in follow-up calls

Dependency Injection

  • GraphToolExecutor receives NodeService and NodeEmbeddingService references
  • References obtained per-operation from AppServices (survive database hot-swaps)
  • No service references stored long-term

Reference Files

  • packages/core/src/services/ — NodeService API
  • packages/core/src/services/embedding_service.rs — NodeEmbeddingService API
  • packages/core/src/mcp/handlers/search.rs — existing search implementation patterns
  • packages/core/src/mcp/handlers/tools.rs — existing tool definition patterns

Exports

  • GraphToolExecutor struct implementing AgentToolExecutor

Dependencies

Related Issues

Activity

  1. malibio commented on Apr 3, 2026

    @malibio
    CollaboratorAuthor

    Baseline: Frontend tests fail in worktree due to missing .svelte-kit/tsconfig.json (pre-existing env issue). This is a Rust-only task — proceeding with cargo check/test baseline.

  2. self-assigned this
    on Apr 3, 2026
  3. added a commit that references this issue on Apr 3, 2026
    8a805cb
  4. added a commit that references this issue on Apr 3, 2026
    e41cf1a
  5. added a commit that references this issue on Jun 22, 2026
    18c739f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions