Skip to content

Plugins

DeepIntShield’s plugin system is built around five key principles that ensure extensibility without compromising performance or reliability:

PrincipleImplementationBenefit
Plugin-First DesignCore logic designed around plugin hook pointsMaximum extensibility without core modifications
Zero-Copy IntegrationDirect memory access to request/response objectsMinimal performance overhead
Lifecycle ManagementComplete plugin lifecycle with automatic cleanupResource safety and leak prevention
Interface-Based SafetyWell-defined interfaces for type safetyCompile-time validation and consistency
Failure IsolationPlugin errors don’t crash the core systemFault tolerance and system stability
graph TB
subgraph "Plugin Management Layer"
PluginMgr[Plugin Manager<br/>Central Controller]
Registry[Plugin Registry<br/>Discovery & Loading]
Lifecycle[Lifecycle Manager<br/>State Management]
end
subgraph "Plugin Execution Layer"
Pipeline[Plugin Pipeline<br/>Execution Orchestrator]
PreHooks[Pre-Processing Hooks<br/>Request Modification]
PostHooks[Post-Processing Hooks<br/>Response Enhancement]
end
subgraph "Plugin Categories"
Auth[Authentication<br/>& Authorization]
RateLimit[Rate Limiting<br/>& Throttling]
Transform[Data Transformation<br/>& Validation]
Monitor[Monitoring<br/>& Analytics]
Custom[Custom Business<br/>Logic]
end
PluginMgr --> Registry
Registry --> Lifecycle
Lifecycle --> Pipeline
Pipeline --> PreHooks
Pipeline --> PostHooks
PreHooks --> Auth
PreHooks --> RateLimit
PostHooks --> Transform
PostHooks --> Monitor
PostHooks --> Custom

Every plugin goes through a well-defined lifecycle that ensures proper resource management and error handling:

stateDiagram-v2
[*] --> PluginInit: Plugin Creation
PluginInit --> Registered: Add to DeepIntShieldConfig
Registered --> PreHookCall: Request Received
PreHookCall --> ModifyRequest: Normal Flow
PreHookCall --> ShortCircuitResponse: Return Response
PreHookCall --> ShortCircuitError: Return Error
ModifyRequest --> ProviderCall: Send to Provider
ProviderCall --> PostHookCall: Receive Response
ShortCircuitResponse --> PostHookCall: Skip Provider
ShortCircuitError --> PostHookCall: Pipeline Symmetry
PostHookCall --> ModifyResponse: Process Result
PostHookCall --> RecoverError: Error Recovery
PostHookCall --> FallbackCheck: Check AllowFallbacks
PostHookCall --> ResponseReady: Pass Through
FallbackCheck --> TryFallback: AllowFallbacks=true/nil
FallbackCheck --> ResponseReady: AllowFallbacks=false
TryFallback --> PreHookCall: Next Provider
ModifyResponse --> ResponseReady: Modified
RecoverError --> ResponseReady: Recovered
ResponseReady --> [*]: Return to Client
Registered --> CleanupCall: DeepIntShield Shutdown
CleanupCall --> [*]: Plugin Destroyed

Discovery Phase:

  • Purpose: Find and catalog available plugins
  • Sources: Command line, environment variables, JSON configuration, directory scanning
  • Validation: Basic existence and format checks
  • Output: Plugin descriptors with metadata

Loading Phase:

  • Purpose: Load plugin binaries into memory
  • Security: Digital signature verification and checksum validation
  • Compatibility: Interface implementation validation
  • Resource: Memory and capability assessment

Initialization Phase:

  • Purpose: Configure plugin with runtime settings
  • Timeout: Bounded initialization time to prevent hanging
  • Dependencies: External service connectivity verification
  • State: Internal state setup and resource allocation

Runtime Phase:

  • Purpose: Active request processing
  • Monitoring: Continuous health checking and performance tracking
  • Recovery: Automatic error recovery and degraded mode handling
  • Metrics: Real-time performance and health metrics collection

Plugin Lifecycle: Plugin Management →


The plugin pipeline ensures consistent, predictable execution while maintaining high performance:

sequenceDiagram
participant Client
participant DeepIntShield
participant Plugin1
participant Plugin2
participant Provider
Client->>DeepIntShield: Request
DeepIntShield->>Plugin1: PreLLMHook(request)
Plugin1-->>DeepIntShield: modified request
DeepIntShield->>Plugin2: PreLLMHook(request)
Plugin2-->>DeepIntShield: modified request
DeepIntShield->>Provider: API Call
Provider-->>DeepIntShield: response
DeepIntShield->>Plugin2: PostLLMHook(response)
Plugin2-->>DeepIntShield: modified response
DeepIntShield->>Plugin1: PostLLMHook(response)
Plugin1-->>DeepIntShield: modified response
DeepIntShield-->>Client: Final Response

Execution Order:

  1. PreHooks: Execute in registration order (1 → 2 → N)
  2. Provider Call: If no short-circuit occurred
  3. PostHooks: Execute in reverse order (N → 2 → 1)
sequenceDiagram
participant Client
participant DeepIntShield
participant Cache
participant Auth
participant Provider
Client->>DeepIntShield: Request
DeepIntShield->>Auth: PreLLMHook(request)
Auth-->>DeepIntShield: modified request
DeepIntShield->>Cache: PreLLMHook(request)
Cache-->>DeepIntShield: LLMPluginShortCircuit{Response}
Note over Provider: Provider call skipped
DeepIntShield->>Cache: PostLLMHook(response)
Cache-->>DeepIntShield: modified response
DeepIntShield->>Auth: PostLLMHook(response)
Auth-->>DeepIntShield: modified response
DeepIntShield-->>Client: Cached Response

For streaming responses, the plugin pipeline executes post-hooks for every delta/chunk received from the provider:

sequenceDiagram
participant Client
participant DeepIntShield
participant Plugin1
participant Plugin2
participant Provider
Client->>DeepIntShield: Stream Request
DeepIntShield->>Plugin1: PreLLMHook(request)
Plugin1-->>DeepIntShield: modified request
DeepIntShield->>Plugin2: PreLLMHook(request)
Plugin2-->>DeepIntShield: modified request
DeepIntShield->>Provider: Stream API Call
loop For Each Delta
Provider-->>DeepIntShield: stream delta
DeepIntShield->>Plugin2: PostLLMHook(delta)
Plugin2-->>DeepIntShield: modified delta
DeepIntShield->>Plugin1: PostLLMHook(delta)
Plugin1-->>DeepIntShield: modified delta
DeepIntShield-->>Client: Send Delta
end
Provider-->>DeepIntShield: final chunk (finish reason)
DeepIntShield->>Plugin2: PostLLMHook(final)
Plugin2-->>DeepIntShield: modified final
DeepIntShield->>Plugin1: PostLLMHook(final)
Plugin1-->>DeepIntShield: modified final
DeepIntShield-->>Client: Final Chunk

Streaming Execution Characteristics:

  1. Delta Processing:

    • Each stream delta (chunk) goes through all post-hooks
    • Plugins can modify/transform each delta before it reaches the client
    • Deltas can contain: text content, tool calls, role changes, or usage info
  2. Special Delta Types:

    • Start Event: Initial delta with role information
    • Content Delta: Regular text or tool call content
    • Usage Update: Token usage statistics (if enabled)
    • Final Chunk: Contains finish reason and any final metadata
  3. Plugin Considerations:

    • Plugins must handle streaming responses efficiently
    • Each delta should be processed quickly to maintain stream responsiveness
    • Plugins can track state across deltas using context
    • Heavy processing should be done asynchronously
  4. Error Handling:

    • If a post-hook returns an error, it’s sent as an error stream chunk
    • Stream is terminated after error chunks
    • Plugins can recover from errors by providing valid responses
  5. Performance Optimization:

    • Lightweight delta processing to minimize latency
    • Object pooling for common data structures
    • Non-blocking operations for logging and metrics
    • Efficient memory management for stream processing

Streaming Details: Streaming Guide →

Short-Circuit Rules:

  • Provider Skipped: When plugin returns short-circuit response/error
  • PostLLMHook Guarantee: All executed PreHooks get corresponding PostLLMHook calls
  • Reverse Order: PostHooks execute in reverse order of PreHooks

Short-Circuit Error Flow (Allow Fallbacks)

Section titled “Short-Circuit Error Flow (Allow Fallbacks)”
sequenceDiagram
participant Client
participant DeepIntShield
participant Plugin1
participant Provider1
participant Provider2
Client->>DeepIntShield: Request (Provider1 + Fallback Provider2)
DeepIntShield->>Plugin1: PreLLMHook(request)
Plugin1-->>DeepIntShield: LLMPluginShortCircuit{Error, AllowFallbacks=true}
Note over Provider1: Provider1 call skipped
DeepIntShield->>Plugin1: PostLLMHook(error)
Plugin1-->>DeepIntShield: error unchanged
Note over DeepIntShield: Try fallback provider
DeepIntShield->>Plugin1: PreLLMHook(request for Provider2)
Plugin1-->>DeepIntShield: modified request
DeepIntShield->>Provider2: API Call
Provider2-->>DeepIntShield: response
DeepIntShield->>Plugin1: PostLLMHook(response)
Plugin1-->>DeepIntShield: modified response
DeepIntShield-->>Client: Final Response
sequenceDiagram
participant Client
participant DeepIntShield
participant Plugin1
participant Plugin2
participant Provider
participant RecoveryPlugin
Client->>DeepIntShield: Request
DeepIntShield->>Plugin1: PreLLMHook(request)
Plugin1-->>DeepIntShield: modified request
DeepIntShield->>Plugin2: PreLLMHook(request)
Plugin2-->>DeepIntShield: modified request
DeepIntShield->>RecoveryPlugin: PreLLMHook(request)
RecoveryPlugin-->>DeepIntShield: modified request
DeepIntShield->>Provider: API Call
Provider-->>DeepIntShield: error
DeepIntShield->>RecoveryPlugin: PostLLMHook(error)
RecoveryPlugin-->>DeepIntShield: recovered response
DeepIntShield->>Plugin2: PostLLMHook(response)
Plugin2-->>DeepIntShield: modified response
DeepIntShield->>Plugin1: PostLLMHook(response)
Plugin1-->>DeepIntShield: modified response
DeepIntShield-->>Client: Recovered Response

Error Recovery Features:

  • Error Transformation: Plugins can convert errors to successful responses
  • Graceful Degradation: Provide fallback responses for service failures
  • Context Preservation: Error context is maintained through recovery process

Real-world plugin interactions involving authentication, rate limiting, and caching with different decision paths:

graph TD
A["Client Request"] --> B["DeepIntShield"]
B --> C["Auth Plugin PreLLMHook"]
C --> D{"Authenticated?"}
D -->|No| E["Return Auth Error<br/>AllowFallbacks=false"]
D -->|Yes| F["RateLimit Plugin PreLLMHook"]
F --> G{"Rate Limited?"}
G -->|Yes| H["Return Rate Error<br/>AllowFallbacks=nil"]
G -->|No| I["Cache Plugin PreLLMHook"]
I --> J{"Cache Hit?"}
J -->|Yes| K["Return Cached Response"]
J -->|No| L["Provider API Call"]
L --> M["Cache Plugin PostLLMHook"]
M --> N["Store in Cache"]
N --> O["RateLimit Plugin PostLLMHook"]
O --> P["Auth Plugin PostLLMHook"]
P --> Q["Final Response"]
E --> R["Skip Fallbacks"]
H --> S["Try Fallback Provider"]
K --> T["Skip Provider Call"]

Symmetric Execution Pattern:

  • Pre-processing: Plugins execute in priority order (high to low)
  • Post-processing: Plugins execute in reverse order (low to high)
  • Rationale: Ensures proper cleanup and state management (last in, first out)

Performance Optimizations:

  • Timeout Boundaries: Each plugin has configurable execution timeouts
  • Panic Recovery: Plugin panics are caught and logged without crashing the system
  • Resource Limits: Memory and CPU limits prevent runaway plugins
  • Circuit Breaking: Repeated failures trigger plugin isolation

Error Handling Strategies:

  • Continue: Use original request/response if plugin fails
  • Fail Fast: Return error immediately if critical plugin fails
  • Retry: Attempt plugin execution with exponential backoff
  • Fallback: Use alternative plugin or default behavior

Plugin Execution: Request Flow →


Plugin security operates at multiple layers to ensure system integrity:

graph TB
subgraph "Security Validation Layers"
L1[Layer 1: Binary Validation<br/>Signature & Checksum]
L2[Layer 2: Interface Validation<br/>Type Safety & Compatibility]
L3[Layer 3: Runtime Validation<br/>Resource Limits & Timeouts]
L4[Layer 4: Execution Isolation<br/>Panic Recovery & Error Handling]
end
subgraph "Security Benefits"
Integrity[Code Integrity<br/>Verified Authenticity]
Safety[Type Safety<br/>Compile-time Checks]
Stability[System Stability<br/>Isolated Failures]
Performance[Performance Protection<br/>Resource Limits]
end
L1 --> Integrity
L2 --> Safety
L3 --> Performance
L4 --> Stability

Binary Security:

  • Digital Signatures: Cryptographic verification of plugin authenticity
  • Checksum Validation: File integrity verification
  • Source Verification: Trusted source requirements

Interface Security:

  • Type Safety: Interface implementation verification
  • Version Compatibility: Plugin API version checking
  • Memory Safety: Safe memory access patterns

Runtime Security:

  • Resource Quotas: Memory and CPU usage limits
  • Execution Timeouts: Bounded execution time
  • Sandbox Execution: Isolated execution environment

Operational Security:

  • Health Monitoring: Continuous plugin health assessment
  • Error Tracking: Plugin error rate monitoring
  • Automatic Recovery: Failed plugin restart and recovery

DeepIntShield provides detailed metrics for plugin performance and health monitoring:

graph TB
subgraph "Execution Metrics"
ExecTime[Execution Time<br/>Latency per Plugin]
ExecCount[Execution Count<br/>Request Volume]
SuccessRate[Success Rate<br/>Error Percentage]
Throughput[Throughput<br/>Requests/Second]
end
subgraph "Resource Metrics"
MemoryUsage[Memory Usage<br/>Per Plugin Instance]
CPUUsage[CPU Utilization<br/>Processing Time]
IOMetrics[I/O Operations<br/>Network/Disk Activity]
PoolUtilization[Pool Utilization<br/>Resource Efficiency]
end
subgraph "Health Metrics"
ErrorRate[Error Rate<br/>Failed Executions]
PanicCount[Panic Recovery<br/>Crash Events]
TimeoutCount[Timeout Events<br/>Slow Executions]
RecoveryRate[Recovery Success<br/>Failure Handling]
end
subgraph "Business Metrics"
AddedLatency[Added Latency<br/>Plugin Overhead]
SystemImpact[System Impact<br/>Overall Performance]
FeatureUsage[Feature Usage<br/>Plugin Utilization]
CostImpact[Cost Impact<br/>Resource Consumption]
end

Plugin Execution Performance:

  • Typical Overhead: 1-10μs per plugin for simple operations
  • Authentication Plugins: 1-5μs for key validation
  • Rate Limiting Plugins: 500ns for quota checks
  • Monitoring Plugins: 200ns for metric collection
  • Transformation Plugins: 2-10μs depending on complexity

Resource Usage Patterns:

  • Memory Efficiency: Object pooling reduces allocations
  • CPU Optimization: Minimal processing overhead
  • Network Impact: Configurable external service calls
  • Storage Overhead: Minimal for stateless plugins

1. Authentication & Authorization

  • Pre-processing Hook: Validate API keys or JWT tokens
  • Configuration: External identity provider integration
  • Error Handling: Return 401/403 responses for invalid credentials
  • Performance: Sub-5μs validation with caching

2. Rate Limiting & Quotas

  • Pre-processing Hook: Check request quotas and limits
  • Storage: Redis or in-memory rate limit tracking
  • Algorithms: Token bucket, sliding window, fixed window
  • Responses: 429 Too Many Requests with retry headers

3. Request/Response Transformation

  • Dual Hooks: Pre-processing for requests, post-processing for responses
  • Use Cases: Data format conversion, field mapping, content filtering
  • Performance: Streaming transformations for large payloads
  • Compatibility: Provider-specific format adaptations

4. Monitoring & Analytics

  • Post-processing Hook: Collect metrics and logs after request completion
  • Destinations: Prometheus, DataDog, custom analytics systems
  • Data: Request/response metadata, performance metrics, error tracking
  • Privacy: Configurable data sanitization and filtering

Plugin-to-Plugin Communication:

  • Shared Context: Plugins can store data in request context for downstream plugins
  • Event System: Plugin can emit events for other plugins to consume
  • Data Passing: Structured data exchange between related plugins

Plugin-to-External Service Communication:

  • HTTP Clients: Built-in HTTP client pools for external API calls
  • Database Connections: Connection pooling for database access
  • Message Queues: Integration with message queue systems
  • Caching Systems: Redis, Memcached integration for state storage

📖 Integration Examples: Plugin Development Guide →


  • Request Flow - Plugin execution in request processing pipeline
  • Concurrency Model - Plugin concurrency and threading considerations
  • Benchmarks - Plugin performance characteristics and optimization
  • MCP System - Integration between plugins and MCP system