Overview
Script components enable you to:- Reuse code logic across multiple agents and ensembles
- Version scripts with semantic versioning for reproducibility
- A/B test different implementations
- Organize complex JavaScript/TypeScript code separately from YAML
- Deploy scripts independently from ensembles
- Collaborate by sharing utility functions across teams
Quick Start
1. Create a Script Component
Create a JavaScript/TypeScript file that exports a default function:2. Add to Edgit
3. Reference in Your Ensemble
URI Format and Versioning
All script components use the standardized URI format:script://- Protocol identifier for script components{path}- Logical path to the script (e.g.,transform-data,utils/validation)[@{version}]- Optional version identifier (defaults to@latest)
@latest- Always uses the most recent version@v1- Uses latest patch of major version (v1.x.x)@v1.0.0- Specific semantic version (immutable)@prod- Custom tag for production versions@staging- Custom tag for staging versions
Example URIs
Script Format
Scripts must export a default function that receives the agent execution context:TypeScript Support
How to Reference in Ensembles
There are three ways to reference scripts in your ensembles:1. URI Format (Recommended)
Use thescript:// URI format to reference versioned script components:
2. Template Expression Format
Use${components.script_name@version} to embed script references in code:
3. Inline Code
For simple operations or during development, use inline code directly:Using Script Components
With Caching Options
Multiple Scripts in Workflow
Caching and Performance
Script components are automatically cached for 1 hour (3600 seconds) after first load.Default Caching
- First load: Fetched from KV and compiled (~10-20ms)
- Subsequent loads: Served from edge cache (~0.1ms)
- Cache per version: Each version cached independently
Custom Cache TTL
Bypass Cache
Code Operation Patterns
Code agents enable you to execute JavaScript/TypeScript logic within ensembles. They’re useful for:- Data transformation - Processing and normalizing data
- Business logic - Custom calculations and rules
- Integration - Connecting multiple data sources
- Validation - Checking data quality and constraints
Basic Code Agent
Multi-Step Code Workflow
Best Practices (Today)
1. Keep Code Modular
Break complex logic into multiple code agents:2. Add Error Handling
3. Use Meaningful Variable Names
4. Add Comments for Complex Logic
5. Validate Input Data
Integration Patterns
With Think Agents
With Data Agents
JavaScript Runtime Environment
Code agents execute in a secure JavaScript runtime with:- Full ES6+ support - All modern JavaScript features
- Built-in objects - Array, Object, Math, Date, JSON, etc.
- Safe execution - Isolated from other agents
- Input access - Access via
inputobject - Output requirement - Must return a value
Available Globals
Troubleshooting
Syntax Errors
Issue: Code doesn’t execute Solutions:- Check JavaScript syntax (use
nodelocally to test) - Ensure all variables are defined
- Check for missing parentheses or braces
Runtime Errors
Issue: Code throws an error during execution Solutions:- Add error handling with try/catch
- Validate input data before processing
- Check that referenced properties exist
Type Errors
Issue: Cannot perform operation on undefined value Solutions:- Check input structure
- Add null/undefined checks
- Use optional chaining:
obj?.property

