ConnectOnionConnectOnion

Quick Start Guide

Get up and running with ConnectOnion in under 2 minutes.

Estimated time: 2 minutes to first working agent

1
Install ConnectOnion

Terminal
$pip install connectonion

2
Create Your First Agent

Create a new agent project with automatic setup:

Terminal
$co create my-agent
$cd my-agent

Files created:

my-agent/
├──🐍agent.py# Ready-to-run agent with example tools
├──.env# API keys (auto-configured)
├──co-vibecoding-principles-docs-contexts-all-in-one.md# Complete framework docs
├──.gitignore# Git config
└──.co/# ConnectOnion config
├──config.toml
└──docs/
└──co-vibecoding-principles-docs-contexts-all-in-one.md

✨ The CLI handles:

  • API key setup - Automatic detection from environment or interactive input
  • Project structure - All files created and configured
  • Documentation - Complete framework docs included
  • Git configuration - .gitignore ready for version control

3
Run Your Agent

Terminal
$python agent.py

Your agent is ready to use! The minimal template includes example tools to get you started.

4
Customize Your Agent

Your meta-agent can help you build ConnectOnion projects:

main.py
1# Learn about ConnectOnion 2result = agent.input("What is ConnectOnion and how do tools work?") 3print(result)
Python REPL
Interactive
>>> result = agent.input("What is ConnectOnion and how do tools work?")
>>> print(result)
ConnectOnion is a Python framework for building AI agents with a focus on simplicity.
Here's how it works:
 
1. **Agent Creation**: Create agents with a name, tools, and optional system prompt
2. **Tools**: Functions that agents can call. Any Python function can be a tool!
3. **Automatic Schema Generation**: Type hints are converted to OpenAI function schemas
4. **Iteration Control**: Use max_iterations to prevent infinite loops
5. **Built-in Logging**: All agent interactions are automatically logged to `.co/logs/`
 
Tools work by:
- Converting Python functions to OpenAI-compatible schemas
- The agent decides when to call tools based on the task
- Tool results are fed back to the agent for further processing
- Multiple tools can be called in sequence to complete complex tasks
main.py
1# Generate agent code 2result = agent.input("Create a web scraper agent") 3print(result[:500] + "...") # Show first 500 chars
Python REPL
Interactive
>>> result = agent.input("Create a web scraper agent")
>>> print(result[:500] + "...")
Here's a complete web scraper agent using ConnectOnion:
 
```python
from connectonion import Agent
import requests
from bs4 import BeautifulSoup
 
def scrape_url(url: str) -> str:
"""Scrape content from a URL."""
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
return soup.get_text()[:1000]
 
def extract_links(url: str) -> list[str]:
"""Extract all links from a webpage."""
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
return [a['href'] for a in soup.find_all('a', href=True)]...
main.py
1# Create tool functions 2result = agent.input("Generate a tool for sending emails") 3print(result)
Python REPL
Interactive
>>> result = agent.input("Generate a tool for sending emails")
>>> print(result)
Here's an email sending tool for your agent:
 
```python
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
 
def send_email(to: str, subject: str, body: str, from_email: str = "agent@example.com") -> str:
"""Send an email to the specified recipient.
Args:
to: Recipient email address
subject: Email subject line
body: Email body content
from_email: Sender email address
Returns:
Status message indicating success or failure
"""
try:
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
# Configure your SMTP server
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(from_email, 'your_app_password')
server.send_message(msg)
server.quit()
return f"Email sent successfully to {to}"
except Exception as e:
return f"Failed to send email: {str(e)}"
```
 
Usage: agent = Agent("mailer", tools=[send_email])

5
Alternative: Playwright Web Automation

For web automation tasks, use the Playwright template:

Terminal
$co create my-browser-bot --template playwright
$cd my-browser-bot

Stateful browser tools included:

start_browser() - Launch browser
navigate() - Go to URLs
scrape_content() - Extract content
fill_form() - Complete forms
take_screenshot() - Capture pages
extract_links() - Get all links
click() - Click elements
execute_javascript() - Run JS

Note: Requires pip install playwright && playwright install

6
Create a Custom Tool Agent

You can also create agents from scratch with custom tools:

main.py
1from connectonion import Agent 2 3def calculate(expression: str) -> str: 4 """Safely evaluate mathematical expressions.""" 5 try: 6 allowed_chars = set('0123456789+-*/()., ') 7 if all(c in allowed_chars for c in expression): 8 result = eval(expression) 9 return f"Result: {result}" 10 else: 11 return "Error: Invalid characters" 12 except Exception as e: 13 return f"Error: {str(e)}" 14 15# Create agent with the tool 16agent = Agent( 17 name="calculator", 18 tools=[calculate], 19 system_prompt="You are a helpful math tutor.", 20 max_iterations=5 # Simple calculations need few iterations 21) 22 23# Use the agent 24response = agent.input("What is 42 * 17 + 25?") 25print(response)
Python REPL
Interactive
Let me calculate that for you.
 
42 * 17 = 714
714 + 25 = 739
 
The answer is 739.

7
Debugging with @xray

Use the @xray decorator to see what your agent is thinking:

main.py
1from connectonion import Agent 2from connectonion.decorators import xray 3 4@xray 5def calculate(expression: str) -> str: 6 """Math tool with debugging enabled.""" 7 print(f"[SEARCH] Agent '{xray.agent.name}' is calculating: {expression}") 8 print(f"[SEARCH] User's original request: {xray.task}") 9 print(f"[SEARCH] This is iteration #{xray.iteration}" 10 11 result = eval(expression) 12 return f"Result: {result}" 13 14agent = Agent("debug_calc", tools=[calculate], max_iterations=5) 15response = agent.input("What's 50 + 30?") 16print(response)
Python REPL
Interactive
[SEARCH] Agent 'debug_calc' is calculating: 50 + 30
[SEARCH] User's original request: What's 50 + 30?
[SEARCH] This is iteration #1
Result: 80
 
The result is 80.

8
Interactive Debugging

Debug your agents interactively - pause at breakpoints, inspect state, and test "what if" scenarios:

main.py
1from connectonion import Agent 2from connectonion.decorators import xray 3 4@xray # Breakpoint: pause here for inspection 5def search_database(query: str) -> str: 6 results = db.search(query) 7 return f"Found {len(results)} results" 8 9agent = Agent( 10 name="search_bot", 11 tools=[search_database], 12 system_prompt="You are a helpful search assistant" 13) 14 15# Launch interactive debug session 16agent.auto_debug()
Python REPL
Interactive
🔍 Interactive Debug Session Started
Agent: search_bot | Tools: 1
 
💡 Quick Tips:
- Tools with @xray will pause for inspection
- Use arrow keys to navigate menus
- Press 'c' to continue
 
Type your message to the agent:
> Find recent Python tutorials
 
→ Tool: search_database({"query": "Python tutorials"})
← Result: Found 5 results
 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@xray BREAKPOINT: search_database
 
Local Variables:
query = "Python tutorials"
result = "Found 5 results"
 
What do you want to do?
→ Continue execution 🚀 [c or Enter]
Edit values 🔍 [e] ← Test "what if" scenarios
Quit debugging 🚫 [q]
 
> c
 
✓ Task complete

🔍 Why use interactive debugging?

Pause at breakpoints - Inspect state at any tool
Test edge cases - Modify variables to explore "what if"
Python REPL access - Full runtime inspection
Step through execution - See every tool call

What's Next?