Skip to main content
Glama
portel-dev

NCP - Natural Context Provider

by portel-dev
README-AUTOMATION.md8.11 kB
# Automation Powerhouse: Code-Mode + Scheduler **98% token savings. Unlimited possibilities. True AI automation.** ## Quick Start ```bash # 1. View the demo node examples/automation-demo.cjs # 2. Run interactive test node tests/manual/test-automation-powerhouse.cjs # 3. Create your first automation ncp run schedule:create ``` ## What Makes This Powerful? ### Traditional AI Automation Every time AI needs to do something, it makes multiple calls: - `find("what I need")` → 2000 tokens - `run(tool, params)` → 500 tokens - **Total: 2500 tokens per execution** ### Code-Mode + Scheduler Schedule code once, run it forever automatically: - Setup once → 1500 tokens (one-time) - Each execution → 50 tokens (automated) - **98% cost reduction!** ## Real Numbers ### Daily Health Monitoring (every minute) **Traditional:** 3.6M tokens/day = $450/month **Code-Mode:** 72K tokens/day = $9/month **💰 Savings: $441/month** ### Weekly Reports (Mondays at 9am) **Traditional:** 2500 tokens/week = $0.50/month **Code-Mode:** 50 tokens/week = $0.01/month **💰 Savings: $0.49/month** ### E-Commerce Automation (every 2 hours) **Traditional:** 120K tokens/day = $150/month **Code-Mode:** 600 tokens/day = $0.75/month **💰 Savings: $149.25/month (99.5%!)** ## Documentation 1. **[automation-powerhouse.md](./automation-powerhouse.md)** - Complete guide with 20+ examples - Real-world use cases - Best practices & security 2. **[automation-comparison.md](./automation-comparison.md)** - Visual cost comparisons - ROI calculations - Feature matrices 3. **[automation-demo.cjs](./automation-demo.cjs)** - Interactive demo script - See examples in action ## Example Use Cases ### 📊 Data Pipeline ```javascript // Fetch, transform, load - daily at 3 AM await schedule.create({ name: "etl-pipeline", schedule: "0 3 * * *", tool: "code:run", parameters: { code: ` const data = await fetch('api.com/data').then(r => r.json()); const transformed = data.map(processRecord); await saveToDatabase(transformed); return { processed: transformed.length }; ` } }); ``` **Savings:** $8.70/month ### 🔍 Health Monitoring ```javascript // Check services every 5 minutes await schedule.create({ name: "health-check", schedule: "*/5 * * * *", tool: "code:run", parameters: { code: ` const services = await checkAllServices(); if (services.some(s => !s.healthy)) { await rollback(); return { alert: true }; } return { status: 'healthy' }; ` } }); ``` **Savings:** $250/month ### 📧 Weekly Reports ```javascript // Generate report every Monday at 9 AM await schedule.create({ name: "weekly-report", schedule: "0 9 * * 1", tool: "code:run", parameters: { code: ` const stats = await aggregateWeeklyStats(); const report = generateMarkdownReport(stats); await sendReport(report); return { sent: true }; ` } }); ``` **Savings:** $0.49/month ### 🤖 DevOps Automation ```javascript // Monitor deployments every 10 minutes await schedule.create({ name: "deployment-monitor", schedule: "*/10 * * * *", tool: "code:run", parameters: { code: ` const health = await checkDeployments(); if (health.api.status === 'unhealthy') { execSync('kubectl rollout undo deployment/api'); return { action: 'ROLLBACK' }; } return { status: 'ok' }; ` } }); ``` **Savings:** $180/month ## Capabilities Unlocked ### ❌ Traditional Limitations - Limited to pre-built tools - Cannot chain operations easily - High token cost per execution - Need multiple schedules for workflows - No access to Node.js ecosystem ### ✅ Code-Mode Capabilities - Execute any Node.js code - Chain unlimited operations - Use npm packages & built-ins - Full file system access - Custom HTTP clients - Complex conditional logic - Error handling & retries - Self-adjusting workflows - 98% cost savings ## Getting Started ### 1. Enable Code-Mode Edit your NCP profile: ```json { "workflowMode": "find-and-code" } ``` ### 2. Create Your First Automation ```bash ncp run schedule:create ``` Follow the prompts to: - Name your automation - Set the schedule (cron or natural language) - Write your code - Set parameters ### 3. Monitor Your Automations ```bash # List all schedules ncp run schedule:list # View analytics ncp run analytics:overview # Check specific schedule ncp run schedule:get --job_id my-automation # View logs tail -f ~/.ncp/logs/schedule-my-automation.log ``` ## Advanced Patterns ### Conditional Execution ```javascript if (new Date().getHours() < 9) { return { skipped: true, reason: 'outside business hours' }; } // Continue with main logic... ``` ### Error Handling & Retries ```javascript async function withRetry(fn, maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { try { return await fn(); } catch (error) { if (i === maxRetries - 1) throw error; await new Promise(r => setTimeout(r, 1000 * Math.pow(2, i))); } } } ``` ### Multi-Step Workflows ```javascript // Extract const data = await fetchFromAPI(); // Transform const processed = data.map(transform); // Load await saveToDatabase(processed); // Analyze const stats = calculateStats(processed); // Report await sendReport(stats); return stats; ``` ### Dynamic Scheduling ```javascript const load = await checkSystemLoad(); if (load > 0.8) { // Increase monitoring frequency await schedule.update({ job_id: "my-monitor", schedule: "* * * * *" // Every minute }); } ``` ## Security Considerations When scheduling code execution: ✅ **DO:** - Use network policies for external access - Validate inputs and sanitize data - Set execution timeouts - Monitor resource usage - Use audit logging (Phase 5) - Test with `testRun: true` first ❌ **DON'T:** - Execute untrusted code - Store credentials in code - Skip input validation - Ignore error handling See [docs/code-mode-phase5-audit.md](../docs/code-mode-phase5-audit.md) for details. ## ROI Calculator **Your Automation:** - Execution frequency: _____ times/day - Operations per execution: _____ - Traditional cost: _____ × 2500 tokens = _____ tokens/day - Code-Mode cost: 1500 (setup) + (_____ × 50) tokens/day **Monthly Savings:** ``` Traditional: (tokens/day × 30 × $0.005 / 1000) Code-Mode: (tokens/day × 30 × $0.005 / 1000) Savings: Traditional - Code-Mode ``` ## Examples by Industry ### E-Commerce - Inventory management - Price optimization - Order processing - Customer alerts ### DevOps - Health monitoring - Auto-rollback - Log analysis - Performance tracking ### Data Science - Model retraining - Data pipeline - Report generation - Anomaly detection ### Finance - Transaction monitoring - Risk assessment - Compliance reporting - Market analysis ## Troubleshooting ### Schedule not running? ```bash # Check schedule status ncp run schedule:list # Check logs tail -f ~/.ncp/logs/schedule-*.log ``` ### Code errors? ```bash # Test before scheduling ncp run schedule:create --testRun true ``` ### High resource usage? - Add execution timeouts - Use network policies - Monitor with analytics ## Community Examples Share your automations! Create a PR with your example: ``` examples/community/ ├── your-automation-name.md └── your-automation-code.js ``` ## Next Steps 1. ✅ Run the demo: `node examples/automation-demo.cjs` 2. ✅ Read the guide: [automation-powerhouse.md](./automation-powerhouse.md) 3. ✅ See comparisons: [automation-comparison.md](./automation-comparison.md) 4. ✅ Create automation: `ncp run schedule:create` 5. ✅ Monitor results: `ncp run analytics:overview` ## Support - 📖 Docs: [docs/workflow-modes.md](../docs/workflow-modes.md) - 🔒 Security: [docs/code-mode-phase5-audit.md](../docs/code-mode-phase5-audit.md) - 💬 Issues: [GitHub Issues](https://github.com/your-repo/issues) --- **The future of AI automation: Schedule intelligence, not just tools.** 🚀 98% savings. Unlimited possibilities. True automation.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/portel-dev/ncp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server