Examples
This is archived documentation for Robota SDK v2.0.0. For the latest version, see the current documentation.
Comprehensive examples demonstrating all aspects of the Robota SDK.
Basic Examples
Basic Conversation
Learn the fundamentals of Robota with simple AI conversations.
Features Demonstrated:
- OpenAI Provider setup and configuration
- Simple message exchange using
robota.run() - Agent statistics and monitoring
- Proper resource cleanup
AI with Tools
Integrate function calling capabilities with your AI agents.
Features Demonstrated:
- Function tool creation with JSON schemas
- Automatic tool calling by AI agents
- Tool execution results handling
- Tool usage statistics
Multi-Provider Support
Use multiple AI providers and models in a single application.
Features Demonstrated:
- OpenAI with different models (GPT-3.5, GPT-4o-mini)
- Model comparison and response analysis
- Independent agent instances
- Provider-specific configurations
Browser Usage 🌐
Use Robota SDK in browsers, WebWorkers, and modern JavaScript frameworks.
Features Demonstrated:
- Cross-platform compatibility (Node.js, browsers, WebWorkers)
- React and Vue integration examples
- Secure API key management with proxy servers
- Memory-based storage strategies
- Browser-specific configuration and optimization
- Zero breaking changes for existing Node.js code
Advanced Features
assignTask Tool Collection
Use the @robota-sdk/agent-team package as an assignTask MCP tool collection (no team creation APIs).
Features Demonstrated:
- Built-in template registry (bundled JSON)
- Template listing and detail lookup
- assignTask tool execution via Relay MCP Tool
Agent Templates
Use pre-built agent configurations (templates) for specialized tasks.
Features Demonstrated:
- Template-based agent creation
- Optimized AI provider selection per template
Execution Analytics
Monitor and analyze agent performance in real-time.
Features Demonstrated:
- Real-time performance tracking
- Execution statistics and metrics
- Error analysis and reporting
- Memory management and optimization
Agent System
Agents Basic Usage
Explore the comprehensive capabilities of the unified Robota Agent system.
Features Demonstrated:
- Unified agent architecture with plugins
- Real-time statistics and monitoring
- Runtime configuration updates
- Plugin ecosystem integration
Agents Streaming
Implement real-time streaming responses for interactive applications.
Features Demonstrated:
- Real-time response streaming
- Token-by-token processing
- Performance optimization for streaming
- Memory-efficient processing
Specialized Features
Session Management
Manage complex conversation sessions with advanced features.
Features Demonstrated:
- Multi-session conversation management
- Session persistence and restoration
- Context switching between sessions
Conversation History
Implement comprehensive conversation storage and retrieval.
Features Demonstrated:
- Memory, file, and database storage options
- Conversation search and filtering
- Message lifecycle management
- Batch processing and optimization
Function Calling with Zod
Create type-safe function tools using Zod schemas.
Features Demonstrated:
- Zod schema integration
- Runtime type validation
- Type-safe parameter handling
- Schema-to-JSON conversion
Provider Switching
Dynamically switch between AI providers during execution.
Features Demonstrated:
- Runtime provider switching
- Configuration preservation
- Fallback strategies
- Provider-specific optimizations
Token Limits
Implement intelligent token management and cost control.
Features Demonstrated:
- Token usage tracking
- Cost calculation and monitoring
- Limit enforcement strategies
- Budget management
MCP Integration
Connect to external tools using the Model Context Protocol.
Features Demonstrated:
- MCP client integration
- External tool discovery
- Protocol communication
- Tool schema handling
Module System Integration
Leverage the new Plugin-Module-Separation architecture for enhanced functionality.
Features Demonstrated:
- Enhanced plugin classification system
- Custom module development
- Event-driven module-plugin communication
- Module registry and lifecycle management
- Performance monitoring across modules and plugins
Configuration
Setup Guide
Complete setup instructions for all SDK components.
Covers:
- Environment configuration
- API key management
- Package installation
- Development setup
Real-World Applications
Each example includes:
- ✅ Complete working code - Ready to run examples
- ✅ Type safety - Full TypeScript support
- ✅ Error handling - Robust error management
- ✅ Best practices - Production-ready patterns
- ✅ Performance monitoring - Built-in analytics
- ✅ Resource management - Proper cleanup
Running Examples
Install dependencies:
bashnpm installConfigure environment:
bashcp .env.example .env # Add your API keysRun an example:
bashnpx tsx examples/01-basic-conversation.ts
Example Categories
By Complexity
- Beginner: Basic conversation, Simple tools
- Intermediate: Multi-provider, Team collaboration
- Advanced: Custom plugins, Complex workflows
By Use Case
- Chatbots: Basic conversation, Session management
- Research: Team collaboration, Analytics
- Development: Function calling, MCP integration
- Production: Error handling, Performance monitoring
All examples are production-ready and demonstrate best practices for building scalable AI applications with Robota SDK.
🚀 Getting Started
Quick Setup
Clone and Install:
bashgit clone https://github.com/your-org/robota.git cd robota pnpm installEnvironment Setup:
cd /path/to/robota
# Set environment variables (or use a root .env)
# OPENAI_API_KEY=...Run Examples:
bash
Run any example
npx tsx packages/agents/examples/basic-conversation.ts
## 🎯 Quick Feature Overview
### New Unified Architecture (`@robota-sdk/agent-core`)
The examples showcase the powerful new unified architecture:
- **Zero `any` Types**: Complete TypeScript safety
- **Plugin System**: Modular functionality with built-in plugins
- **Multi-Provider**: Seamless switching between OpenAI, Anthropic, Google
- **Advanced Analytics**: Built-in execution monitoring and performance tracking
- **Tool System**: Type-safe function calling with automatic schema conversion
- **Streaming Support**: Real-time response streaming with metadata
### Core Capabilities Demonstrated
| Feature | Examples | Description |
|---------|----------|-------------|
| **Basic AI Chat** | 01, 10 | Simple conversations and basic setup |
| **Function Calling** | 02 | Tool integration and automated function calls |
| **Multi-Provider** | 03, 07 | OpenAI, Anthropic, Google AI provider usage |
| **Streaming** | 11 | Real-time response streaming |
| **Team Coordination** | 05, 09 | Multi-agent collaboration |
| **Performance Analytics** | 08, 09 | Execution monitoring and optimization |
| **Template Patterns** | 07 | Reusable agent configurations |
## 🔧 Running Examples
### Prerequisites
```bash
# Required environment variables
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key # For multi-provider examples
GOOGLE_AI_API_KEY=your_google_key # For Google AI examplesIndividual Examples
# Package-owned examples (run from repo root)
npx tsx packages/agents/examples/basic-conversation.ts
npx tsx packages/agents/examples/tool-calling.ts
npx tsx packages/agents/examples/multi-providers.ts
npx tsx packages/openai/examples/payload-logging.ts
npx tsx packages/team/examples/assign-task-basic.tsRun All Examples
# Run a sequence of examples to see progression
npm run examples:basic # Basic examples (01, 02, 10)
npm run examples:advanced # Advanced examples (03, 07, 08, 11)
npm run examples:all # All examples in sequence🎨 Example Structure
Each example follows a consistent structure:
/**
* XX-example-name.ts
*
* Brief description of what this example demonstrates:
* - Key feature 1
* - Key feature 2
* - Key feature 3
*/
import {} from /* required imports */ '@robota-sdk/agent-core';
import dotenv from 'dotenv';
dotenv.config();
async function main() {
try {
// Example implementation
console.log('🚀 Example Started...');
// Create agents, configure providers, demonstrate features
console.log('✅ Example Completed!');
} catch (error) {
console.error('❌ Error:', error);
process.exit(1);
} finally {
// Cleanup resources
process.exit(0);
}
}
main();📊 Performance Considerations
The examples are optimized for learning and demonstration:
- Minimal Token Usage: Short queries to reduce API costs
- Error Handling: Robust error handling and recovery
- Resource Cleanup: Proper cleanup to prevent memory leaks
- Performance Monitoring: Built-in timing and analytics
🔗 Related Documentation
- Getting Started Guide - Initial setup and basic concepts
- Core Concepts - Understanding the architecture
- API Reference - Complete API documentation
- Provider Guides - Provider-specific documentation
💡 Tips for Learning
- Start Simple: Begin with basic conversation example
- Read Comments: Each example has detailed inline comments
- Experiment: Modify examples to explore different configurations
- Check Output: Expected output is documented for each example
- Use TypeScript: Examples showcase full type safety benefits
- Monitor Performance: Use analytics examples to optimize your usage
Happy coding with Robota! 🤖