Inline Tools are simple TypeScript functions that execute directly within the Pika agent runtime without requiring separate Lambda deployments. Perfect for rapid prototyping, testing tool concepts, and implementing simple utility functions.
What They Are
Section titled “What They Are”Unlike traditional Pika tools that deploy as separate AWS Lambda functions, Inline Tools embed their code directly into the agent's tool definition. When an agent needs to call an inline tool, the code executes immediately within the agent runtime environment.
This makes Inline Tools:
- Fast to develop - No deployment pipeline required
- Instant to execute - No cold start latency
- Simple to understand - Self-contained functions
- Perfect for prototyping - Quick iteration without infrastructure overhead
Why They Matter
Section titled “Why They Matter”Traditional tool development requires:
- Write Lambda function code
- Configure IAM roles and permissions
- Set up deployment pipeline
- Deploy to AWS
- Test and iterate (repeat 1-4)
With Inline Tools:
- Write TypeScript function
- Test immediately
For prototyping and simple utilities, this dramatically accelerates development.
How They Work
Section titled “How They Work”Write a Simple Function
Section titled “Write a Simple Function”Create a self-contained TypeScript function:
function randomNumber(event, params) { console.log('Random number generator called with:', params);
const min = params.min; const max = params.max; const range = max - min; const val = Math.random() * range + min; const factor = Math.pow(10, params.precision ?? 0);
return Math.round(val * factor) / factor;}Embed in Tool Configuration
Section titled “Embed in Tool Configuration”Include the function in your tool definition:
const inlineTool: ToolConfig = { toolId: 'random-number', toolName: 'Random Number Generator', description: 'Generate a random number within a specified range', executionType: 'inline', inlineCode: randomNumber.toString(), inputSchema: { type: 'object', properties: { min: { type: 'number', description: 'Minimum value' }, max: { type: 'number', description: 'Maximum value' }, precision: { type: 'number', description: 'Decimal places (optional)' } }, required: ['min', 'max'] }};Agent Invokes Tool
Section titled “Agent Invokes Tool”Agent calls inline tool like any other tool:
Agent determines tool is needed
Based on user query, agent decides to invoke tool
Inline code executes immediately
Function runs within agent runtime (no separate Lambda invocation)
Result returned instantly
No network latency, no cold starts
Agent uses result in response
Tool output integrated seamlessly
Key Benefits
Section titled “Key Benefits”Rapid Prototyping
Section titled “Rapid Prototyping”Test ideas without infrastructure:
// Idea: Maybe we need a tool to calculate discountsfunction calculateDiscount(event, params) { return params.price * (1 - params.discountPercent / 100);}
// Test with agent immediately - no deployment needed// Works? Great! Later convert to full Lambda with database accessZero Infrastructure Overhead
Section titled “Zero Infrastructure Overhead”No AWS resources to manage:
- No Lambda functions to deploy
- No IAM roles to configure
- No deployment pipelines to set up
- No cold starts to worry about
Instant Execution
Section titled “Instant Execution”Performance benefits:
- No cold start: Function is already loaded
- No network latency: Executes in same process
- Immediate response: Typical execution <1ms
Simple Development Flow
Section titled “Simple Development Flow”Clean, fast iteration:
- Edit function code
- Update tool configuration
- Test with agent
- Refine and repeat
Use Cases
Section titled “Use Cases”Ideal For
Section titled “Ideal For”Mathematical Operations:
function calculateCompoundInterest(event, params) { const { principal, rate, years, compound } = params; return principal * Math.pow(1 + rate / compound, compound * years);}String Manipulation:
function formatPhoneNumber(event, params) { const digits = params.number.replace(/\D/g, ''); return `(${digits.slice(0,3)}) ${digits.slice(3,6)}-${digits.slice(6)}`;}Data Transformation:
function convertUnits(event, params) { const conversions = { 'c-to-f': (c) => c * 9/5 + 32, 'f-to-c': (f) => (f - 32) * 5/9, 'km-to-mi': (km) => km * 0.621371, 'mi-to-km': (mi) => mi * 1.60934 }; return conversions[params.conversion](params.value);}Testing and Mocking:
function mockWeatherData(event, params) { // Return fake data for testing return { temperature: 72, conditions: 'Sunny', humidity: 65 };}Not Recommended For
Section titled “Not Recommended For”Production Workloads:
- Use Lambda-based tools for production systems
- Better monitoring and error handling
- Proper access controls and auditing
Complex Logic:
- Functions requiring many dependencies
- Code spanning multiple files
- Significant computation
External Integrations:
- Database access
- API calls to other services
- File system operations
Long-Running Operations:
- Operations taking >5 seconds
- Batch processing
- Heavy computations
Limitations
Section titled “Limitations”Code Constraints
Section titled “Code Constraints”Single Function:
- Must be one self-contained function
- No imports or external dependencies
- Can't split across multiple files
No External Access:
- Cannot access AWS services directly
- No database connections
- No HTTP requests to external APIs
Limited Execution Resources:
- Share resources with agent runtime
- Not suitable for CPU-intensive operations
- Memory limited to agent's allocation
TypeScript Support
Section titled “TypeScript Support”Basic Transpilation:
- You write in TypeScript
- Automatically transpiled to JavaScript
- Complex TypeScript features may not work
- Type checking at compile time only
No Type Definitions:
- Can't import type definitions
- No access to npm packages
- Pure logic only
Production Considerations
Section titled “Production Considerations”Not for Production Scale:
- Limited error handling capabilities
- No separate monitoring/logging
- Can't scale independently
- Harder to maintain long-term
Debugging Limitations:
- Can't set breakpoints
- Limited logging (console.log works)
- Errors may be less clear than Lambda
Example: Complete Implementation
Section titled “Example: Complete Implementation”The random-num-inline sample project demonstrates:
Function Definition
Section titled “Function Definition”export function randomNumber(event: any, params: any): number { console.log('Random number generator called:', params);
const { min, max, precision = 0 } = params; const range = max - min; const value = Math.random() * range + min; const factor = Math.pow(10, precision);
return Math.round(value * factor) / factor;}Tool Configuration
Section titled “Tool Configuration”const toolConfig: ToolConfig = { toolId: 'random-number', toolName: 'Random Number Generator', description: 'Generate a random number in a range with specified precision', executionType: 'inline', inlineCode: randomNumber.toString(), inputSchema: { type: 'object', properties: { min: { type: 'number' }, max: { type: 'number' }, precision: { type: 'number' } }, required: ['min', 'max'] }};Agent Configuration
Section titled “Agent Configuration”const agentConfig: AgentConfig = { agentId: 'random-agent', agentName: 'Random Number Agent', instructions: 'You help users generate random numbers using the random-number tool.', toolIds: ['random-number']};CDK Deployment
Section titled “CDK Deployment”import { PikaAgentRegistry } from '@pika/constructs';
new PikaAgentRegistry(this, 'Registry', { tools: [toolConfig], agents: [agentConfig], chatApps: [chatAppConfig]});Best Practices
Section titled “Best Practices”Start Inline, Move to Lambda
Section titled “Start Inline, Move to Lambda”Natural progression:
- Prototype: Inline tool to test concept
- Validate: Confirm tool adds value
- Enhance: Convert to Lambda when need:
- External service access
- Better monitoring
- Independent scaling
- Production reliability
Keep Functions Simple
Section titled “Keep Functions Simple”Complexity guidelines:
- Good: < 50 lines of code
- Acceptable: 50-100 lines
- Too complex: > 100 lines (use Lambda)
Use for Pure Logic
Section titled “Use for Pure Logic”Best when function is purely computational:
// Good: Pure calculationfunction calculateTax(event, params) { return params.amount * params.taxRate;}
// Bad: Needs external data (use Lambda)function getCurrentTaxRate(event, params) { // Would need to fetch from database // Can't do this in inline tool}Document Thoroughly
Section titled “Document Thoroughly”Clear descriptions help agents use tools correctly:
const tool: ToolConfig = { toolId: 'discount-calc', description: `Calculate discounted price given original price and discount percentage. Returns final price after applying discount. Example: price=100, discount=20 → returns 80`, // ... rest of config};Transitioning to Lambda
Section titled “Transitioning to Lambda”When inline tool outgrows limitations:
Step 1: Create Lambda Function
Section titled “Step 1: Create Lambda Function”export async function handler(event: any) { const { price, discountPercent } = event;
// Now can add: // - Database lookups // - External API calls // - Complex error handling // - Detailed logging
return { discountedPrice: price * (1 - discountPercent / 100) };}Step 2: Update Tool Configuration
Section titled “Step 2: Update Tool Configuration”const toolConfig: ToolConfig = { toolId: 'discount-calc', executionType: 'lambda', // Changed from 'inline' lambdaArn: discountLambda.functionArn, // Added Lambda reference // ... same schema and description};Step 3: Update Agent
Section titled “Step 3: Update Agent”No changes needed - agent uses tool the same way!
Getting Started
Section titled “Getting Started”Try the Sample
Deploy the random-num-inline sample to see inline tools in action.
Implementation Guide
Step-by-step instructions for creating inline tools.
Understanding Tools
Deep dive into tool architecture and patterns.
Related Capabilities
Section titled “Related Capabilities”MCP
Connect to external services with standardized protocols.
Agents as Config
Define tools declaratively as configuration.
Direct Agent Invocation
Call agents with inline tools programmatically.