Skip to main content
Rilo automatically generates Python code for workflow blocks using AI-powered code generation. The BlockCodingAgent analyzes block instructions, config fields, and dependencies to create executable Python code.

Overview

Code generation in Rilo:
  • Automatic: Code is generated automatically after block verification
  • Python-based: All generated code is Python
  • Library Integration: Code uses Rilo’s library tools
  • Sandbox Execution: Code runs in secure E2B sandboxes
You don’t need to write code yourself. Just describe what you want in natural language, and Rilo generates the code for you.

How It Works

1. Block Creation

When you create a block, you provide:
  • Instructions: Natural language description
  • Config Fields: Configuration values
  • Required Tools: Tools the block needs

2. Verification

The VerificationAgent:
  • Discovers required config fields
  • Asks clarifying questions if needed
  • Validates tool availability

3. Code Generation

The BlockCodingAgent:
  • Analyzes block instructions
  • Identifies required tools and libraries
  • Generates Python code extending BaseBlock
  • Includes error handling and logging

4. Execution

Generated code:
  • Runs in secure E2B sandbox
  • Has access to library tools
  • Processes data from previous blocks
  • Returns output for next blocks

Generated Code Structure

BaseBlock Extension

All generated code extends the BaseBlock class:
from workflowapp.library.base_block import BaseBlock

class GeneratedBlock(BaseBlock):
    def execute(self, inputs, config):
        # Generated code here
        ...

Library Integration

Generated code imports and uses Rilo libraries:
from library.social_scraping_library import SocialScrapingLibrary
from library.llm_ops_library import LLMOpsLibrary

# Use tools
scraper = SocialScrapingLibrary()
llm = LLMOpsLibrary()

Data Flow

Code receives data from previous blocks via inputs:
def execute(self, inputs, config):
    # Get data from previous block
    previous_output = inputs.get("previous_block", {})
    posts = previous_output.get("posts", [])
    
    # Process data
    filtered_posts = [p for p in posts if p["upvotes"] > 50]
    
    # Return output
    return {"filtered_posts": filtered_posts}

Code Capabilities

What Generated Code Can Do

Execute library tools: Call methods from Rilo libraries ✅ Basic Python operations: Regex, string manipulation, data transformation ✅ File operations: Create PDF, XLSX, CSV files ✅ JSON processing: Parse and manipulate JSON data ✅ Conditionals and loops: Standard Python control flow ✅ Batch processing: Process multiple items efficiently

What Generated Code Cannot Do

Special languages: Cannot write JavaScript, HTML, CSS, React, FastAPI, etc. ❌ System access: Cannot access environment variables or system files ❌ Shell commands: Cannot execute shell commands or system calls ❌ Direct web scraping: Must use WebOpsLibrary for web operations
Generated code runs in isolated sandboxes. It cannot access system resources, credentials, or execute arbitrary commands.

Code Generation Examples

Example 1: Simple Data Processing

Instructions:
Filter Reddit posts with 50+ upvotes from the last 24 hours
Generated Code:
from workflowapp.library.base_block import BaseBlock
from datetime import datetime, timedelta

class FilterPostsBlock(BaseBlock):
    def execute(self, inputs, config):
        posts = inputs.get("posts", [])
        min_upvotes = config.get("min_upvotes", 50)
        
        # Filter by upvotes
        filtered = [p for p in posts if p.get("upvotes", 0) >= min_upvotes]
        
        # Filter by time (last 24 hours)
        cutoff = datetime.now() - timedelta(hours=24)
        recent = [p for p in filtered if p.get("created_at") > cutoff]
        
        return {"filtered_posts": recent}

Example 2: Library Tool Usage

Instructions:
Scrape Reddit posts from r/python and send email summary
Generated Code:
from workflowapp.library.base_block import BaseBlock
from library.social_scraping_library import SocialScrapingLibrary
from library.communication_tools_library import CommunicationToolsLibrary

class ScrapeAndEmailBlock(BaseBlock):
    def execute(self, inputs, config):
        scraper = SocialScrapingLibrary()
        email_tool = CommunicationToolsLibrary()
        
        # Scrape posts
        result = scraper.get_posts_best(
            subreddits=["r/python"],
            limit=10
        )
        posts = result.get("items", [])
        
        # Create summary
        summary = f"Found {len(posts)} posts from r/python"
        
        # Send email
        email_tool.send_email(
            to=config.get("notification_email"),
            subject="Reddit Summary",
            body=summary
        )
        
        return {"posts": posts, "summary": summary}

Code Generation Process

Step-by-Step

  1. Parse Instructions: Agent analyzes natural language instructions
  2. Identify Tools: Determines which library tools are needed
  3. Generate Structure: Creates BaseBlock class structure
  4. Add Logic: Generates Python code for the logic
  5. Add Error Handling: Includes try/except blocks and logging
  6. Validate: Checks code syntax and structure

Error Handling

Generated code includes error handling:
def execute(self, inputs, config):
    try:
        # Main logic
        result = some_operation()
        return {"success": True, "data": result}
    except Exception as e:
        rilo_logger.error(f"Error in block: {str(e)}")
        return {"success": False, "error": str(e)}

Best Practices

Write clear, specific instructions. Vague instructions lead to unclear code generation.
Mention which tools you need. The agent can infer, but being explicit helps.
Include examples in instructions when possible. This helps the agent understand your intent.
Review generated code before execution. You can regenerate if needed.

Regenerating Code

If generated code doesn’t meet your needs:
  1. Update Instructions: Modify block instructions to be more specific
  2. Adjust Config Fields: Add or modify config fields if needed
  3. Regenerate: Trigger code regeneration from the block editor
  4. Review: Check the new code and verify it matches your requirements
Code is regenerated automatically when you change block instructions or config fields that affect code generation.

Limitations

Code Generation Constraints

  • Python Only: Code is always Python, not other languages
  • Library Tools Only: Can only use tools from Rilo libraries
  • No System Access: Cannot access system resources or credentials
  • Sandbox Execution: Runs in isolated environment

What You Can’t Do

❌ Generate code in other languages (JavaScript, Go, etc.) ❌ Access environment variables or secrets ❌ Execute shell commands ❌ Direct database access (must use integration tools) ❌ Create custom libraries on the fly
If you need functionality not available in Rilo libraries, consider adding a custom integration or using an MCP server.

Troubleshooting

  • Check that instructions are clear and specific
  • Verify required tools are available
  • Ensure config fields are properly set
  • Try regenerating with more detailed instructions
  • Review the error message in execution logs
  • Update instructions to be more specific
  • Check that all required config fields are set
  • Regenerate code after fixing issues
  • Provide more detailed instructions
  • Include examples of expected behavior
  • Specify exact tool methods to use
  • Review and refine instructions
  • Configs - How config fields are used in code
  • AI Module - Multi-agent system that generates code
  • Integrations - Extend capabilities with custom tools

Code generation is continuously improving. The AI agent learns from examples and gets better at understanding your intent over time.