### Bash: First-Time User Setup with ConnectOnion Source: https://github.com/openonion/connectonion/blob/main/docs/cli/README.md Guides a first-time user through the installation and initial setup of ConnectOnion. This includes installing the package, creating a new agent project, authenticating with OpenOnion, and saving API keys. ```bash $ pip install connectonion $ co create my-first-agent 🚀 Welcome to ConnectOnion! ✨ Setting up global configuration... ✓ Generated master keypair ✓ Your address: 0x7a9f...7f8a ✓ Created ~/.co/config.toml ✓ Created ~/.co/keys.env 🔐 Authenticating with OpenOnion... ✓ Authenticated (Balance: $5.00) ✔ Paste API key (optional): sk-proj-xxx ✓ Detected OpenAI ✓ Saved to ~/.co/keys.env ✅ Created my-first-agent cd my-first-agent && python agent.py 💡 Vibe Coding: Use Claude/Cursor with co-vibecoding-principles-docs-contexts-all-in-one.md 📚 Resources: Docs → https://docs.connectonion.com Discord → https://discord.gg/4xfD9k8AUF GitHub → https://github.com/openonion/connectonion $ cd my-first-agent $ python agent.py ``` -------------------------------- ### Run Quick Start Example with Python Source: https://github.com/openonion/connectonion/blob/main/examples/README.md Executes the minimal ConnectOnion agent setup script. This script is ideal for beginners and demonstrates the simplest way to create an agent with basic tools like search, calculate, and get_time. ```bash # Quick start - minimal example python quick_start.py ``` -------------------------------- ### Create and Run a New Agent with CLI Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/quickstart.md Demonstrates how to create a new agent project, navigate into its directory, and run the agent using the ConnectOnion CLI. API key setup is handled automatically. ```bash # Create a new agent project co create my-agent # Navigate to the project cd my-agent # Run your agent (API key setup is automatic!) python agent.py ``` -------------------------------- ### Minimal ConnectOnion Agent Setup with Python Source: https://github.com/openonion/connectonion/blob/main/examples/README.md Demonstrates the simplest way to create a ConnectOnion agent. It includes a basic calculation tool and shows how to initialize the agent and get a response to a simple mathematical query. ```python from connectonion import Agent def calculate(expression: str) -> float: """Do math calculations.""" return eval(expression) agent = Agent("assistant", tools=[calculate]) result = agent.input("What is 42 * 17?") ``` -------------------------------- ### Manual Agent Setup with Python Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/quickstart.md Shows how to manually set up an AI agent using the ConnectOnion Python library. It includes defining a tool (calculate) and creating an agent instance that can use this tool for calculations. ```python from connectonion import Agent # Define what your agent can do def calculate(expression: str) -> str: """Do math calculations.""" return str(eval(expression)) # Create your agent agent = Agent( "assistant", tools=[calculate], max_iterations=5 # Simple calculations don't need many iterations ) # Use it! result = agent.input("What is 42 * 17?") print(result) ``` -------------------------------- ### ConnectOnion CLI Quick Start Examples (Bash) Source: https://github.com/openonion/connectonion/blob/main/docs/cli/create.md Provides several examples of how to quickly create agents using the 'co create' command with different levels of configuration. These examples illustrate using global identity, specifying agent names, selecting templates, and accepting all defaults. ```bash # Simplest form - uses global identity $ co create # With name - uses global identity $ co create my-bot # With template - uses global identity $ co create my-bot --template web-research # Accept all defaults $ co create quickbot -y ``` -------------------------------- ### ConnectOnion First-Time Setup Workflow Source: https://github.com/openonion/connectonion/wiki/CLI-Reference This bash script outlines the initial setup process for ConnectOnion, including installation via pip, creating a new project, following interactive prompts for configuration, and running the agent. ```bash # 1. Install ConnectOnion pip install connectonion # 2. Create your first project co create my-first-agent # 3. Follow interactive prompts # The CLI will guide you through: # - API key setup # - Template selection # - Configuration # 4. Run your agent cd my-first-agent python agent.py ``` -------------------------------- ### Python Quick Start for Tool Approval Source: https://github.com/openonion/connectonion/blob/main/docs/useful_plugins/tool_approval.md Demonstrates how to initialize an Agent with bash tool and tool_approval plugin, setting up WebSocket I/O for web-based approvals. It shows an example of installing dependencies, triggering an approval request, and the expected client response. ```python from connectonion import Agent, bash from connectonion.useful_plugins import tool_approval agent = Agent("assistant", tools=[bash], plugins=[tool_approval]) agent.io = my_websocket_io # Required for web mode agent.input("Install dependencies") # → Client receives: {"type": "approval_needed", "tool": "bash", "arguments": {"command": "npm install"}} # → Client responds: {"approved": true, "scope": "session"} # ✓ bash approved (session) ``` -------------------------------- ### Environment Setup and Dependency Installation Source: https://github.com/openonion/connectonion/blob/main/examples/browser-agent/CLAUDE.md Commands for initializing the project environment and installing required browser automation dependencies. ```bash pip install playwright playwright install ``` -------------------------------- ### ConnectOnion Quick Start Agent Setup Source: https://github.com/openonion/connectonion/blob/main/docs/connectonion.md Demonstrates how to define tools as Python functions, create an Agent instance with a system prompt and tools, and interact with it. ```python from connectonion import Agent # 1. Define tools as regular functions def search(query: str) -> str: """Search for information.""" return f"Found information about {query}" def calculate(expression: str) -> float: """Perform mathematical calculations.""" return eval(expression) # Use safely in production # 2. Create agent agent = Agent( name="my_assistant", system_prompt="You are a helpful assistant.", tools=[search, calculate] # max_iterations=10 (default) ) # 3. Use agent result = agent.input("What is 25 * 4?") print(result) ``` -------------------------------- ### Project Setup and Installation Source: https://github.com/openonion/connectonion/blob/main/connectonion/useful_prompts/coding_agent/README.md Basic shell commands to copy the coding agent template into a new project directory. ```bash cp -r coding_agent/ my-project/ cd my-project/coding_agent ``` -------------------------------- ### Install ConnectOnion CLI Source: https://github.com/openonion/connectonion/wiki/Quick-Start Installs the ConnectOnion command-line interface using pip. This is the first step to using ConnectOnion for building AI agents. ```bash pip install connectonion ``` -------------------------------- ### Development Environment Setup Source: https://github.com/openonion/connectonion/blob/main/CONTRIBUTING.md Commands to clone the repository, initialize a virtual environment, install dependencies, and configure pre-commit hooks for development. ```bash git clone https://github.com/your-username/connectonion.git cd connectonion python -m venv venv source venv/bin/activate pip install -e . pip install pytest pytest-cov pip install pre-commit pre-commit install ``` -------------------------------- ### ConnectOnion Template Selection and Help Source: https://github.com/openonion/connectonion/wiki/CLI-Reference Guides users on selecting appropriate templates for ConnectOnion projects and how to get help for template-specific options. It lists available templates and demonstrates how to use the `--help` flag for template configuration. ```bash # Get help for template options co init --help # Valid templates are: co init --template minimal co init --template playwright co init --template custom --description "your description" ``` -------------------------------- ### Python: Input API Configuration Example Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/tui/input.md Provides an example of configuring the Input component using its various API parameters. This includes prompt customization, trigger setup, hints, tips, and styling options. ```python Input( prompt=None, # Custom prompt text triggers=None, # {char: Provider} for autocomplete hints=None, # Always-visible hints tips=None, # Rotating tips divider=False, # Add horizontal dividers max_visible=8, # Max dropdown items console=None, style="modern", # "modern", "minimal", "classic" ).run() -> str ``` -------------------------------- ### Creating Agents with CLI Templates Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/quickstart.md Demonstrates using the ConnectOnion CLI to create new agent projects with different templates, including a minimal default and a specific 'playwright' template for browser automation. It also shows how to initialize an existing directory. ```bash # Create with minimal template (default) co create my-agent # Create with playwright template co create my-browser-bot --template playwright # Initialize in existing directory co init # Adds .co folder only co init --template playwright # Adds full template ``` -------------------------------- ### Setup and Run Tests via Pytest Source: https://github.com/openonion/connectonion/blob/main/tests/README.md Commands to install dependencies, configure the environment, and execute specific test categories using pytest markers. ```bash pip install -r requirements.txt cp tests/.env.example tests/.env pytest -m unit pytest -m integration pytest -m cli pytest -m e2e pytest -m real_api pytest -m "real_api and e2e_online" pytest -m "not real_api" ``` -------------------------------- ### Copying and Customizing Built-in Tools with CLI Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/quickstart.md Explains how to use the ConnectOnion CLI to copy built-in tools and plugins into your project for customization. It covers listing available items, copying specific tools or plugins, and copying multiple items at once. ```bash # See what's available co copy --list # Copy a tool to ./tools/ co copy Gmail # Copy a plugin to ./plugins/ co copy re_act # Copy multiple items co copy Gmail Shell memory ``` -------------------------------- ### Bash: Non-Interactive CI/CD Setup Source: https://github.com/openonion/connectonion/blob/main/docs/cli/README.md Provides an example of setting up ConnectOnion for non-interactive CI/CD pipelines. This involves exporting API keys as environment variables, using flags like `--yes` and `--template minimal` for automated project creation, and running tests. ```bash # Fully automated export OPENAI_API_KEY=sk-proj-xxx co create prod-agent --yes --template minimal cd prod-agent python agent.py --test ``` -------------------------------- ### Practical File Handling Agent Example Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/quickstart.md A concise example of an AI agent capable of reading and writing files. It defines `write_file` and `read_file` tools and demonstrates their use for saving and retrieving content. ```python from connectonion import Agent def write_file(filename: str, content: str) -> str: """Save content to a file.""" with open(filename, 'w') as f: f.write(content) return f"Saved to {filename}" def read_file(filename: str) -> str: """Read a file.""" with open(filename, 'r') as f: return f.read() # Create a file assistant assistant = Agent( "file_helper", tools=[write_file, read_file], max_iterations=8 # File operations are usually straightforward ) # Use it assistant.input("Save 'Hello World' to greeting.txt") assistant.input("What's in greeting.txt?") ``` -------------------------------- ### Bash Commands for Dependency Installation and API Key Setup Source: https://github.com/openonion/connectonion/wiki/Examples-Web-Scraping-Agent These bash commands guide the user through setting up the project environment. The first command installs necessary Python dependencies using pip. The second command creates a `.env` file and sets the OpenAI API key, which is crucial for the agent's operation. ```bash pip install connectonion beautifulsoup4 requests lxml ``` ```bash echo "OPENAI_API_KEY=sk-your-key-here" > .env ``` -------------------------------- ### Quick Init in Empty Directory with Defaults (Bash) Source: https://github.com/openonion/connectonion/blob/main/docs/cli/init.md This example shows a quick initialization of ConnectOnion in a new, empty directory using the `--yes` flag to accept all defaults. The command automatically creates a new `.env` file and populates it with API keys from the global configuration (`~/.co/keys.env`). ```bash mkdir my-new-agent cd my-new-agent co init --yes # Output: # ✓ Using global identity # ✓ Created new .env with API keys from ~/.co/keys.env # # ✅ ConnectOnion project initialized! ``` -------------------------------- ### Quick Start: Create and Use a Python Agent Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/concepts/tools.md Demonstrates how to quickly set up a ConnectOnion agent with a simple search tool and execute a query. This involves importing the Agent class, defining a tool function, and initializing the agent. ```python from connectonion import Agent def search(query: str) -> str: # your first tool return f"Found results for {query}" agent = Agent( "helper", tools=[search], max_iterations=5 # Simple search tasks ) ``` ```python >>> agent("Find Python tutorials") 'Found results for Python tutorials' ``` -------------------------------- ### ConnectOnion Quick Start Agent Initialization and Run Source: https://github.com/openonion/connectonion/blob/main/examples/playwright-agent/connectonion.md Provides the essential steps to set up and run a ConnectOnion agent after project initialization, including copying environment variables and adding the API key. ```bash # 1. Copy environment template cp .env.example .env # 2. Add your OpenAI API key to .env echo "OPENAI_API_KEY=sk-your-key-here" > .env # 3. Run your agent python agent.py ``` -------------------------------- ### Simple Agent Initialization (Python) Source: https://github.com/openonion/connectonion/wiki/How-To-Use-Managed-Keys Shows how to initialize a simple agent using managed keys, which requires no API key setup. This is ideal for getting started and prototyping quickly, leveraging the free tier for initial usage. ```python from connectonion import Agent # No API key setup needed! agent = Agent( "assistant", model="co/gpt-5-mini" # Fast and free to start ) response = agent.input("Explain quantum computing in simple terms") print(response) ``` -------------------------------- ### Install Python and Pip on Mac Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Installs Homebrew, Python, and Pip on macOS. This is a prerequisite for installing Python packages like ConnectOnion. ```bash # Install Homebrew first if needed /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Install Python brew install python ``` -------------------------------- ### Create a New AI Agent Project Source: https://github.com/openonion/connectonion/wiki/Quick-Start Creates a new AI agent project named 'my-agent' using the ConnectOnion CLI. This command scaffolds a complete project with example code and configuration files, including automated API key setup. ```bash co create my-agent ``` -------------------------------- ### First Time Global Configuration Setup (Bash) Source: https://github.com/openonion/connectonion/blob/main/docs/cli/init.md On the first run of `co init` (or `co create`), if the global configuration directory `~/.co/` does not exist, it is created automatically. This process includes generating a master keypair, assigning a unique address and email, and creating essential configuration files like `config.toml` and `keys.env`. ```bash $ co init # First time ever 🚀 Welcome to ConnectOnion! ✨ Setting up global configuration... ✓ Generated master keypair ✓ Your address: 0x7a9f3b2c8d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a ✓ Your email: 0x7a9f3b2c@mail.openonion.ai ✓ Created ~/.co/config.toml ✓ Created ~/.co/keys.env [continues with project initialization...] ``` -------------------------------- ### Loading ConnectOnion Guides Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/best-practices.md Demonstrates how to load guides within the ConnectOnion system. It suggests starting with 'best-practices' and then loading other relevant guides as needed for specific concepts. ```python load_guide("best-practices") # Load other guides as needed (tools, events, llm_do, etc.) ``` -------------------------------- ### Install and Initialize Project via CLI Source: https://github.com/openonion/connectonion/blob/main/README.md Provides instructions for installing the framework via pip and scaffolding a new agent project using the command-line interface. ```bash pip install connectonion co create my-agent cd my-agent python agent.py ``` -------------------------------- ### Activate Virtual Environment for ConnectOnion Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Creates and activates a Python virtual environment for installing ConnectOnion. This isolates project dependencies and is the recommended installation method. ```bash python -m venv venv source venv/bin/activate # Mac/Linux # or venv\Scripts\activate # Windows pip install connectonion ``` -------------------------------- ### Initialize Agent with Plugins Source: https://github.com/openonion/connectonion/blob/main/docs/README.md Demonstrates how to instantiate a ConnectOnion Agent with multiple plugins, including image formatting and reflection, to enhance agent capabilities. ```python from connectonion import Agent from connectonion.useful_plugins import reflection, react, image_result_formatter agent = Agent( name="visual_researcher", tools=[take_screenshot, search, analyze], plugins=[image_result_formatter, reflection, react] ) ``` -------------------------------- ### Install ConnectOnion with User Flag Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Installs the ConnectOnion package for the current user only, avoiding system-wide permission issues. This is an alternative to using a virtual environment. ```bash pip install --user connectonion ``` -------------------------------- ### Agent Configuration with Plugins Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/README.md Demonstrates how to initialize agents with specific tools and plugins. Plugins are defined as event lists that can hook into agent execution. ```python researcher = Agent("researcher", tools=[search], plugins=[reflection, logger]) writer = Agent("writer", tools=[generate], plugins=[reflection]) analyst = Agent("analyst", tools=[calculate], plugins=[logger]) ``` ```python # Define a plugin (an event list) my_plugin = [after_llm(handler1), after_tools(handler2)] # after_tools for message injection # Use it (plugins takes a list of event lists) agent = Agent("assistant", tools=[search], plugins=[my_plugin]) ``` -------------------------------- ### Install ConnectOnion Package Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Installs the ConnectOnion Python package using pip. Ensure you are using the correct package name and have a compatible Python version. ```bash pip install connectonion # Not "connect-onion" or "ConnectOnion" ``` -------------------------------- ### Install OpenAI Library using pip Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Installs the necessary OpenAI library if it's missing. This is often a prerequisite for using OpenAI-related functionalities within the project. ```bash pip install openai ``` -------------------------------- ### Install Python and Pip on Linux (Ubuntu/Debian) Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Installs Python 3 and Pip on Ubuntu/Debian-based Linux systems. This ensures the necessary tools are available for package management. ```bash sudo apt update sudo apt install python3 python3-pip ``` -------------------------------- ### Quick Start Chat Interface Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/tui/chat.md Initialize and run the ConnectOnion Chat interface with a given agent. This is the most straightforward way to get started with the TUI chat. ```python from connectonion import Agent from connectonion.tui import Chat agent = Agent("assistant", tools=[search, analyze]) chat = Chat(agent=agent) chat.run() ``` -------------------------------- ### Initialize ConnectOnion Project Source: https://github.com/openonion/connectonion/blob/main/docs/cli/init.md Demonstrates various ways to initialize a ConnectOnion project, including using defaults, specific templates, and updating documentation. ```bash # Basic initialization $ co init # Accept all defaults $ co init -y # Initialize with a specific template $ co init --template web-research # Update documentation only $ co init --update-docs # Initialize with a custom template and description $ co init --template custom --description "Discord bot integration" ``` -------------------------------- ### Initialize Agent with System Prompts Source: https://github.com/openonion/connectonion/blob/main/README.md Demonstrates how to initialize an Agent using direct string prompts, file paths via pathlib, or default system prompts. ```python from pathlib import Path # Load from file agent1 = Agent(name="support_agent", system_prompt="prompts/customer_support.md") # Using Path object agent2 = Agent(name="coder", system_prompt=Path("prompts") / "senior_developer.txt") # Default prompt agent3 = Agent("basic_agent") ``` -------------------------------- ### ConnectOnion Installation and Initialization Commands Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/vibe-coding-guide.md Essential shell commands to install the ConnectOnion library and initialize a new project directory for agent development. ```bash pip install connectonion co init ``` -------------------------------- ### Configure and Initialize ConnectOnion Agent Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/README.md Demonstrates how to set up the environment, define functional tools, and instantiate the Agent class to process user inputs. ```bash echo "OPENAI_API_KEY=sk-your-key-here" > .env python agent.py ``` ```python from connectonion import Agent def search(query: str) -> str: """Search for information.""" return f"Found information about {query}" def calculate(expression: str) -> float: """Perform mathematical calculations.""" return eval(expression) agent = Agent( name="my_assistant", system_prompt="You are a helpful assistant.", tools=[search, calculate] ) result = agent.input("What is 25 * 4?") print(result) ``` -------------------------------- ### Bash: Install Dependencies and Setup ConnectOnion Source: https://github.com/openonion/connectonion/blob/main/examples/browser-agent/CLAUDE.md Provides essential bash commands for setting up the development environment. This includes installing Python dependencies, Playwright, and authenticating with ConnectOnion to obtain an API key. ```bash # Install dependencies pip install python-dotenv playwright connectonion playwright install # Authenticate with ConnectOnion (creates .env with OPENONION_API_KEY) co auth ``` -------------------------------- ### Initialize Agent with Image Formatting Plugin Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/README.md Demonstrates how to initialize an Agent with multiple plugins, including `image_result_formatter`, `reflection`, and `react`. This setup enables features like image formatting for screenshots, agent reflection, and ReAct pattern for decision making. ```python from connectonion import Agent from connectonion.useful_plugins import reflection, react, image_result_formatter # Combine plugins for powerful agents agent = Agent( name="visual_researcher", tools=[take_screenshot, search, analyze], plugins=[image_result_formatter, reflection, react] ) ``` -------------------------------- ### ConnectOnion CLI Custom Template Examples (Bash) Source: https://github.com/openonion/connectonion/blob/main/docs/cli/create.md Shows how to create an agent using the 'custom' template, either interactively or by providing a descriptive text. This allows for AI-generated agent configurations based on user-defined requirements. ```bash # Interactive $ co create --template custom # With description $ co create slack-bot -t custom -d "Slack bot for answering questions" ``` -------------------------------- ### Manage Dependencies and Imports Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Resolve common installation and import path issues for the ConnectOnion library. ```bash pip install connectonion pip install python-dotenv ``` ```python # Correct import path from connectonion.decorators import xray ``` -------------------------------- ### Configuring Agent Plugins Source: https://github.com/openonion/connectonion/blob/main/docs/README.md Demonstrates how to initialize an agent with built-in plugins like reflection and ReAct. It shows how plugins are passed as a list of event lists to the Agent constructor. ```python from connectonion import Agent from connectonion.useful_plugins import reflection, react # Add built-in plugins to any agent agent = Agent( name="assistant", tools=[search, calculate], plugins=[reflection, react] # One line adds both! ) agent.input("Search for Python and calculate 15 * 8") ``` -------------------------------- ### Check Python Version Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Verifies the installed Python version. ConnectOnion requires Python 3.9 or newer. ```bash python --version # Must be 3.9+ ``` -------------------------------- ### Initialize Agent with Tools Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/connectonion.md Demonstrates how to define an Agent instance with a system prompt and associated tools. ```python calculator = Agent( name="calc", system_prompt="You are a helpful calculator. Always show your work step by step.", tools=[calculate] ) ``` -------------------------------- ### Enforce One Task In Progress Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/useful_tools/todo_list.md Highlights the rule that only one task can be in the 'in_progress' state at a time. The example shows how attempting to start a second task before completing the first will result in an error, and how completing the first task allows the second to start. ```python todo.add("Task A", "Doing A") todo.add("Task B", "Doing B") todo.start("Task A") todo.start("Task B") # Error: Another task is in progress todo.complete("Task A") todo.start("Task B") # Now works ``` -------------------------------- ### LangChain Traditional Approach Setup Source: https://github.com/openonion/connectonion/wiki/How-To-Use-Managed-Keys Shows the traditional setup for LangChain, which requires installing multiple libraries and exporting API keys for different providers (OpenAI, Anthropic, Google) as environment variables before initializing an agent. ```python # 1. Install pip install langchain openai anthropic google-generativeai # 2. Set multiple keys export OPENAI_API_KEY=sk-... export ANTHROPIC_API_KEY=sk-ant-... export GOOGLE_API_KEY=... # 3. Create agent from langchain import agents agent = agents.initialize_agent(...) ``` -------------------------------- ### Configure and Initialize ConnectOnion Agent Source: https://github.com/openonion/connectonion/blob/main/docs/README.md Demonstrates how to set the OpenAI API key, define custom tool functions, and instantiate an agent with specific system prompts and tools. ```bash echo "OPENAI_API_KEY=sk-your-key-here" > .env python agent.py ``` ```python from connectonion import Agent def search(query: str) -> str: """Search for information.""" return f"Found information about {query}" def calculate(expression: str) -> float: """Perform mathematical calculations.""" return eval(expression) agent = Agent( name="my_assistant", system_prompt="You are a helpful assistant.", tools=[search, calculate] ) result = agent.input("What is 25 * 4?") print(result) ``` -------------------------------- ### Good Agent Configuration Example (Python) Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/connectonion.md Shows an example of correctly configuring an Agent instance in Python. It emphasizes using clear naming, referencing markdown files for system prompts, including relevant tools, and setting appropriate iteration limits. ```python # Clear purpose, markdown prompts, appropriate limits data_analyst = Agent( name="data_analyst", system_prompt="prompts/data_scientist.md", # Use markdown files! tools=[load_data, analyze_stats, create_visualization], max_iterations=20 # Data analysis can be multi-step ) ``` -------------------------------- ### Create Multi-Tool Assistant Agent with Python Source: https://github.com/openonion/connectonion/blob/main/connectonion/cli/co_ai/prompts/connectonion/examples.md Shows how to build an agent capable of using multiple tools, such as getting the current time, saving notes, and listing saved notes. This example highlights the flexibility of combining different functionalities within a single agent. ```python from connectonion import Agent from datetime import datetime import json def get_time() -> str: """Get the current time.""" return datetime.now().strftime("%I:%M %p") def save_note(title: str, content: str) -> str: """Save a note to a file.""" filename = f"notes/{title.replace(' ', '_')}.txt" with open(filename, 'w') as f: f.write(content) return f"Note saved to {filename}" def list_notes() -> str: """List all saved notes.""" import os if not os.path.exists("notes"): return "No notes found" notes = os.listdir("notes") return "Notes: " + ", ".join(notes) agent = Agent( "assistant", tools=[get_time, save_note, list_notes], system_prompt="You are a helpful note-taking assistant." ) # Use multiple tools agent.input("Save a note titled 'Meeting' with the current time") agent.input("What notes do I have?") ``` -------------------------------- ### Upgrade Python to 3.9 on Linux Source: https://github.com/openonion/connectonion/wiki/Troubleshooting Installs Python 3.9 on Linux systems using apt. This ensures compatibility with ConnectOnion requirements. ```bash # Linux sudo apt install python3.9 ``` -------------------------------- ### Run Your AI Agent Source: https://github.com/openonion/connectonion/wiki/Quick-Start Navigates into the agent's project directory and executes the main agent script ('agent.py') using Python. This command starts your AI agent and shows its output. ```bash cd my-agent python agent.py ``` -------------------------------- ### Enhance System Prompt with Tool Usage Examples Source: https://github.com/openonion/connectonion/wiki/How-To-Debug-Agent-Errors Shows how to update the system prompt with concrete examples of when to use specific tools. This guides the AI agent's decision-making process, especially when tool functionalities overlap. ```string system_prompt=""" Use search_web for: "What's the weather?" "Latest news about AI" Use search_database for: "Find employee John" "Customer records" """ ``` -------------------------------- ### ConnectOnion Starting a New Project Workflow Source: https://github.com/openonion/connectonion/wiki/CLI-Reference These bash commands demonstrate how to quickly start a new ConnectOnion project, either using default settings with the '--yes' flag or specifying a particular template like 'playwright'. ```bash # Quick start with defaults co create my-project --yes # Or with specific template co create my-project --template playwright ``` -------------------------------- ### Bash: Setting Up Keys Once for Future Projects Source: https://github.com/openonion/connectonion/blob/main/docs/cli/README.md Illustrates the convenience of setting up API keys once for the first project, which are then automatically used for all subsequent projects. The `--yes` flag can be used to bypass prompts for fully automated setups. ```bash # First project - enter key co create first-project # (paste key) # All future projects - automatic co create second-project --yes # No prompt! ```