Skip to content

[FEATURE][PLUGIN]: Create Cached Tool Result plugin #994

@crivetimihai

Description

@crivetimihai

Overview

Create a Cached Tool Result Plugin that caches idempotent tool results in-memory to improve performance and reduce redundant API calls.

Plugin Requirements

Plugin Details

  • Name: CachedToolResultPlugin
  • Type: Self-contained (native) plugin
  • File Location: plugins/cached_tool_result/
  • Complexity: Medium

Functionality

  • Cache tool results in-memory based on configurable cache keys
  • Support TTL (Time To Live) expiration for cached entries
  • Configurable cache key generation from tool arguments
  • Cache hit/miss metrics for observability
  • Thread-safe caching implementation

Hook Integration

  • Primary Hooks: tool_pre_invoke, tool_post_invoke
  • Purpose: Cache and retrieve tool results for idempotent operations
  • Behavior: Check cache before tool execution, store results after execution

Configuration Schema

plugins:
  - name: "CachedToolResult"
    kind: "plugins.cached_tool_result.cache.CachedToolResultPlugin"
    description: "Cache idempotent tool results in-memory"
    version: "0.1.0"
    hooks: ["tool_pre_invoke", "tool_post_invoke"]
    mode: "permissive"
    priority: 10
    conditions:
      - tool_names: ["web_search", "api_call", "database_query"]
    config:
      cacheable_tools:
        - name: "web_search"
          cache_key_fields: ["query", "limit"]
          ttl_seconds: 3600
        - name: "api_call" 
          cache_key_fields: ["url", "method", "headers.Authorization"]
          ttl_seconds: 300
        - name: "database_query"
          cache_key_fields: ["sql", "parameters"]
          ttl_seconds: 900
      ttl: 300
      max_entries: 1000
      key_fields:
        default: ["tool_name", "arguments"]
        ignore_fields: ["timestamp", "request_id"]
      cache_behavior:
        include_user_context: true
        include_server_context: false
        hash_large_values: true
        hash_threshold_bytes: 1024
      metrics:
        enabled: true
        include_tool_stats: true
        log_cache_operations: false

Acceptance Criteria

  • Plugin implements CachedToolResultPlugin class
  • Supports configurable cache key generation
  • Implements TTL-based expiration
  • Thread-safe cache operations
  • LRU eviction when max entries reached
  • Cache hit/miss metrics collection
  • Per-tool and global configuration support
  • Plugin manifest and documentation created
  • Unit tests with >90% coverage
  • Performance benchmarks for cache operations

Priority

Medium - Performance optimization feature

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions