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
Beginner
Basic concepts, single tools
Intermediate
State management, workflows
Advanced
System integration, APIs
Expert
Enterprise business logic
1. Hello World Agent
BeginnerThe simplest possible agent - just one greeting tool
1def greet(name: str) -> str:
2 return f"Hello, {name}!"
3
4agent = Agent(name="greeter", tools=[greet])
2. Basic Calculator
BeginnerSafe math operations with input validation and error handling
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. Weather Bot
BeginnerMulti-city weather system with data processing and tool coordination
1def get_weather(city: str) -> dict:
2 weather_db = {
3 "new york": {"temp": 72, "condition": "sunny"},
4 "london": {"temp": 65, "condition": "cloudy"}
5 }
4. Task Manager
IntermediateFull-featured task management with priorities, due dates, and analytics
1def add_task(title: str, priority: str = "medium") -> str:
2 task = {
3 "id": task_counter,
4 "title": title,
5 "priority": priority
6 }
5. Math Tutor Agent
IntermediateInteractive learning system with step-by-step explanations and encouragement
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. File Analyzer
AdvancedSystem integration with file operations, security warnings, and directory traversal
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. API Client
AdvancedHTTP requests, external API integration, and comprehensive error handling
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. E-commerce Manager
ExpertEnterprise-grade business logic with inventory, orders, customers, and analytics
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
🎯 What's Next?
Ready to take your ConnectOnion skills to the next level? Here are some great next steps: