1
Hello World Agent
BeginnerBuild your first AI agent in 5 minutes. Learn the fundamentals of agent creation and tool integration.
What You'll Learn
Agent Creation
How to create your first ConnectOnion agent
Tool Functions
Turn regular Python functions into AI tools
Execution
Run agents with natural language commands
Communication
Understand agent-to-tool patterns
1. Installation
pip install connectonion
2. Basic Agent
1from connectonion import Agent
2
3def greet(name: str) -> str:
4 """Say hello to someone."""
5 return f"Hello, {name}! Nice to meet you!"
6
7# Create the simplest agent
8agent = Agent(
9 name="greeter",
10 tools=[greet]
11)
12
13# Use it
14response = agent.input("Say hello to Alice")
15print(response)
3. Complete Example
1# hello_world_agent.py
2import os
3from connectonion import Agent
4
5# Set your OpenAI API key
6os.environ['OPENAI_API_KEY'] = 'your-api-key-here'
7
8def greet(name: str) -> str:
9 """Say hello to someone by name."""
10 return f"Hello, {name}! Nice to meet you!"
11
12def say_goodbye(name: str) -> str:
13 """Say goodbye to someone by name."""
14 return f"Goodbye, {name}! It was great talking with you!"
15
16# Create your first agent
17agent = Agent(
18 name="greeter",
19 tools=[greet, say_goodbye]
20)
21
22if __name__ == "__main__":
23 # Test the agent
24 print("=== Hello World Agent ===")
25
26 # Simple greeting
27 response1 = agent.input("Say hello to Alice")
28 print(f"Response 1: {response1}")
29
30 # Say goodbye
31 response2 = agent.input("Say goodbye to Bob")
32 print(f"Response 2: {response2}")
33
34 # Interactive conversation
35 response3 = agent.input("Greet John and then say goodbye to him")
36 print(f"Response 3: {response3}")
Expected Output
=== Hello World Agent === Response 1: Hello, Alice! Nice to meet you! Response 2: Goodbye, Bob! It was great talking with you! Response 3: Hello, John! Nice to meet you! Goodbye, John! It was great talking with you!
How It Works
🔧 Tool Definition
Regular Python functions with docstrings become AI tools automatically.
🤖 Agent Creation
Pass your functions to Agent() constructor - ConnectOnion handles the rest.
💬 Natural Language
Agent understands instructions and chooses the right tools automatically.
Try It Yourself
💡 Experiment Ideas
- • Add more greeting functions in different languages
- • Create tools that take multiple parameters
- • Try complex multi-step instructions
Requirements
• Python 3.8+
• ConnectOnion v0.0.1
• OpenAI API key