Skip to main content
The Reference Sidecar handles large data in AgentScript without embedding it in the script. This prevents memory issues and improves security when tools return large responses.

How It Works

  1. Extraction: When a tool returns data with large strings (> extractionThreshold), those strings are stored in the sidecar and replaced with reference tokens (__ref_abc123)
  2. Lazy Resolution: When script code accesses a reference token, it’s resolved just-in-time to the actual data
  3. Safe Property Access: Only explicit property accesses trigger resolution, preventing data exfiltration

Basic Configuration

Configuration Options

Reference Token Format

Reference tokens follow this pattern:
For example: __ref_abc123def456 Scripts cannot distinguish between reference tokens and regular strings until they access the data.

Security: Composite Blocking

When allowComposites: false (default), the sidecar blocks string concatenation with reference tokens:
This prevents data exfiltration via string manipulation.

Use Cases

Large API Responses

Document Processing

Multi-Step Workflows

Memory Management

The sidecar helps manage memory in several ways:
  1. Bounded storage - maxTotalSize prevents unbounded growth
  2. Per-reference limits - maxReferenceSize caps individual entries
  3. Lazy loading - Data only loaded when accessed
  4. Automatic cleanup - References cleared after execution

Error Handling

Monitoring Sidecar Usage

Best Practices

  1. Set appropriate thresholds - Too low creates many references; too high defeats the purpose
  2. Monitor total size - Track sidecar usage to tune maxTotalSize
  3. Keep composites disabled - Unless you specifically need string concatenation
  4. Use with large tool responses - Most beneficial when tools return KB+ of data