ConnectOnion

Agent Building Examples

Master ConnectOnion through 8 progressive examples, from simple "Hello World" to enterprise-grade business applications. Each example introduces new concepts with complete working code and realistic outputs.

📚 Progressive Learning Path

1-3

Beginner

Basic concepts, single tools

4-5

Intermediate

State management, workflows

6-7

Advanced

System integration, APIs

8

Expert

Enterprise business logic

1

1. Hello World Agent

Beginner

The simplest possible agent - just one greeting tool

Basic tool creationAgent initializationSimple interactions
View Tutorial
Code Preview
1def greet(name: str) -> str:
2    return f"Hello, {name}!"
3
4agent = Agent(name="greeter", tools=[greet])
2

2. Basic Calculator

Beginner

Safe math operations with input validation and error handling

Input validationError handlingSafe expression evaluation
View Tutorial
Code Preview
1def calculate(expression: str) -> str:
2    # Validate input safety
3    allowed = set('0123456789+-*/()., ')
4    if not all(c in allowed for c in expression):
5        return "Error: Invalid characters"
3

3. Weather Bot

Beginner

Multi-city weather system with data processing and tool coordination

Data lookupTool coordinationStructured output
View Tutorial
Code Preview
1def get_weather(city: str) -> dict:
2    weather_db = {
3        "new york": {"temp": 72, "condition": "sunny"},
4        "london": {"temp": 65, "condition": "cloudy"}
5    }
4

4. Task Manager

Intermediate

Full-featured task management with priorities, due dates, and analytics

State managementCRUD operationsData filtering
View Tutorial
Code Preview
1def add_task(title: str, priority: str = "medium") -> str:
2    task = {
3        "id": task_counter,
4        "title": title,
5        "priority": priority
6    }
5

5. Math Tutor Agent

Intermediate

Interactive learning system with step-by-step explanations and encouragement

Educational patternsStep-by-step guidanceAnswer validation
View Tutorial
Code Preview
1def solve_equation(equation: str) -> str:
2    return """Let's solve 2x + 5 = 15 step by step:
3    Step 1: Subtract 5 from both sides
4    2x = 10
5    Step 2: Divide by 2
6    x = 5"""
6

6. File Analyzer

Advanced

System integration with file operations, security warnings, and directory traversal

File system integrationSecurity considerationsContent analysis
View Tutorial
Code Preview
1def analyze_file(filepath: str) -> str:
2    path = Path(filepath)
3    if not path.exists():
4        return f"File not found: {filepath}"
5    
6    # Security checks for executable files
7

7. API Client

Advanced

HTTP requests, external API integration, and comprehensive error handling

HTTP methodsAPI integrationNetwork error handling
View Tutorial
Code Preview
1def make_api_request(url: str, method: str = "GET") -> str:
2    try:
3        response = requests.get(url, timeout=10)
4        if response.status_code == 200:
5            return f"✅ Success: {response.text[:1000]}"
8

8. E-commerce Manager

Expert

Enterprise-grade business logic with inventory, orders, customers, and analytics

Business logicMulti-system coordinationEnterprise workflows
View Tutorial
Code Preview
1def process_order(customer_name: str, product: str, quantity: int) -> str:
2    # Calculate taxes, verify inventory, update customer records
3    subtotal = unit_price * quantity
4    tax = subtotal * 0.08
5    total = subtotal + tax