-
Notifications
You must be signed in to change notification settings - Fork 113
Troubleshooting
Quick fixes for common errors and issues with ConnectOnion. Find your error message, get the solution.
Cause: Python/pip not installed or not in PATH
Solutions:
Mac:
# Install Homebrew first if needed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Python
brew install pythonWindows:
- Download Python from python.org
- Important: Check "Add Python to PATH" during installation
- Restart terminal
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install python3 python3-pipCause: Python version too old or typo in package name
Solutions:
-
Check Python version:
python --version # Must be 3.9+ -
Upgrade Python:
# Mac brew install python@3.9 # Linux sudo apt install python3.9
-
Use correct package name:
pip install connectonion # Not "connect-onion" or "ConnectOnion"
Cause: Trying to install system-wide without permissions
Solutions:
Option 1: Use --user flag:
pip install --user connectonionOption 2: Use virtual environment (recommended):
python -m venv venv
source venv/bin/activate # Mac/Linux
# or
venv\Scripts\activate # Windows
pip install connectonionFull Error:
Error: No OpenAI API key found. Set OPENAI_API_KEY environment variable.
Solutions:
1. Create .env file:
# In your project directory
echo "OPENAI_API_KEY=sk-your-key-here" > .env2. Set environment variable:
# Mac/Linux
export OPENAI_API_KEY=sk-your-key-here
# Windows PowerShell
$env:OPENAI_API_KEY="sk-your-key-here"
# Windows CMD
set OPENAI_API_KEY=sk-your-key-here3. Verify it's set:
import os
print(os.getenv("OPENAI_API_KEY")) # Should print your keyFull Error:
AuthenticationError: Incorrect API key provided
Solutions:
-
Check key format:
- OpenAI keys start with
sk- - Must be complete (usually 48-51 characters)
- OpenAI keys start with
-
Get new key:
- Go to OpenAI API Keys
- Create new secret key
- Copy entire key
- Update
.envfile
-
Check for extra spaces:
# ✗ Wrong (has space) OPENAI_API_KEY= sk-abc123 # ✓ Correct OPENAI_API_KEY=sk-abc123
Full Error:
RateLimitError: You exceeded your current quota, please check your plan and billing details
Cause: No credits in OpenAI account
Solutions:
-
Add payment method:
- Go to OpenAI Billing
- Add credit card
- Add credits
-
Check usage:
- Visit Usage Dashboard
- See how much you've used
-
Use cheaper model:
agent = Agent("assistant", model="gpt-4o-mini") # Much cheaper
Symptom: Agent gives text responses but doesn't use your tools
Causes & Solutions:
1. Missing or bad docstring:
# ✗ Bad - no description
def my_tool(param):
return result
# ✓ Good - clear description
def my_tool(param: str) -> str:
"""
Clear description of what this tool does.
Use this when: [explain when to use it]
Args:
param: What this parameter is for
Returns:
What this returns
"""
return result2. Tool name too vague:
# ✗ Unclear
def process(data):
pass
# ✓ Clear and descriptive
def search_customer_database(name: str):
pass3. System prompt discourages tool use:
# ✗ Discourages tools
system_prompt="Answer all questions directly"
# ✓ Encourages tools
system_prompt="Use available tools to help answer questions"4. Missing type hints:
# ✗ No type information
def calculate(a, b):
return a + b
# ✓ Clear types
def calculate(a: float, b: float) -> float:
"""Add two numbers"""
return a + bSymptom: Agent uses tool A when it should use tool B
Solution: Improve tool descriptions:
def search_web(query: str) -> str:
"""
Search the INTERNET for current information.
Use this for:
- Current events and news
- General knowledge from the web
- External information
Do NOT use for:
- Company internal data (use search_database)
- Historical company records
"""
pass
def search_database(query: str) -> str:
"""
Search INTERNAL company database.
Use this for:
- Employee information
- Customer records
- Company documents
Do NOT use for:
- External information (use search_web)
- Current news or events
"""
passSolutions:
1. Improve system prompt:
system_prompt="""You are a helpful assistant.
Rules:
- Always cite sources for factual claims
- If unsure, say "I don't know" instead of guessing
- Use search tool for current information
- Verify facts before presenting them
"""2. Use better model:
# More accurate but slower/expensive
agent = Agent("assistant", model="gpt-4o")3. Improve tool output:
# ✗ Unclear result
def search(query):
return data # Raw dump
# ✓ Formatted result
def search(query):
results = api.search(query)
return f"""
Search Results for '{query}':
1. {results[0].title}
{results[0].summary}
2. {results[1].title}
{results[1].summary}
Source: {results[0].url}
"""Cause: Tool not added to agent's tools list
Solution:
# Make sure tool is in the list
agent = Agent(
"assistant",
tools=[my_tool_1, my_tool_2, my_tool_3] # Include all tools
)Symptom: Tool receives incorrect or unexpected parameters
Solutions:
1. Add parameter documentation:
def send_email(to: str, subject: str, body: str) -> str:
"""
Send an email.
Args:
to: Recipient email (e.g., "user@example.com")
subject: Email subject (e.g., "Meeting Reminder")
body: Complete email message
Example:
send_email("user@example.com", "Hello", "This is a test")
"""
pass2. Add validation with helpful errors:
def send_email(to: str, subject: str, body: str) -> str:
"""Send an email"""
if "@" not in to:
return f"Error: '{to}' is not a valid email. Format: user@example.com"
if not subject:
return "Error: Subject cannot be empty"
if len(body) < 10:
return "Error: Email body too short (minimum 10 characters)"
# Send email...Cause: Unhandled exception in tool
Solution: Add try/except:
def my_tool(param: str) -> str:
"""My tool description"""
try:
# Your code here
result = some_operation(param)
return f"Success: {result}"
except ValueError as e:
return f"Error: Invalid input - {str(e)}"
except Exception as e:
# Log the error
logging.error(f"Tool error: {e}", exc_info=True)
return f"Error: Operation failed - {str(e)}"Causes & Solutions:
1. Using slow model:
# ✗ Slow
model="gpt-4o"
# ✓ Fast
model="gpt-4o-mini" # 2-3x faster2. Long system prompt:
# ✗ Slow (long prompt sent every time)
system_prompt="""[5000 words of instructions]"""
# ✓ Fast (concise)
system_prompt="Be helpful. Use tools when needed."3. Slow tools:
# Add caching
from functools import lru_cache
@lru_cache(maxsize=100)
def slow_api_call(query: str) -> str:
# Results cached for repeated queries
time.sleep(2) # Slow operation
return results4. Too many tool calls:
# Limit iterations
agent = Agent(
"assistant",
tools=[...],
max_iterations=5 # Stop after 5 tool calls
)Solutions:
1. Use cheaper model:
agent = Agent("assistant", model="gpt-4o-mini") # 60x cheaper2. Shorter prompts:
# Reduce system prompt length
# Reduce tool docstring length
# Keep conversation history short3. Monitor usage:
# Check OpenAI usage dashboard
# Set spending limitsCause: ConnectOnion not installed
Solutions:
# Install
pip install connectonion
# Verify
pip list | grep connectonionCause: Optional dependency not installed
Solution:
pip install python-dotenvCause: Wrong import path
Solution:
# ✗ Wrong
from connectonion import xray
# ✓ Correct
from connectonion.decorators import xrayCause: OpenAI library not installed (should be automatic)
Solution:
pip install openaiCauses:
1. Missing @xray decorator:
# ✗ Won't pause
def my_tool():
pass
# ✓ Will pause
from connectonion.decorators import xray
@xray
def my_tool():
pass2. Forgot to call auto_debug():
agent = Agent("assistant", tools=[my_tool])
agent.auto_debug() # Don't forget this!3. Tool not being called:
- Agent might not think it needs the tool
- Improve tool docstring
Solution:
# After modifying variables:
>>> result = "new value"
>>> /continue # Required to apply changes!-
Enable debug logging:
import logging logging.basicConfig(level=logging.DEBUG)
-
Use auto_debug():
agent.auto_debug() # See exactly what's happening
-
Check examples:
-
Ask the community:
Please open an issue or ask in Discord so we can add it to this guide!
Related Guides:
- Debug Agent Errors - Detailed debugging guide
- FAQ - Common questions
- Interactive Debugging - Learn auto_debug()