connectonion 0.0.1b2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- connectonion-0.0.1b2/PKG-INFO +373 -0
- connectonion-0.0.1b2/README.md +334 -0
- connectonion-0.0.1b2/connectonion/__init__.py +11 -0
- connectonion-0.0.1b2/connectonion/agent.py +245 -0
- connectonion-0.0.1b2/connectonion/decorators.py +811 -0
- connectonion-0.0.1b2/connectonion/history.py +119 -0
- connectonion-0.0.1b2/connectonion/llm.py +85 -0
- connectonion-0.0.1b2/connectonion/prompts.py +93 -0
- connectonion-0.0.1b2/connectonion/tools.py +60 -0
- connectonion-0.0.1b2/connectonion.egg-info/PKG-INFO +373 -0
- connectonion-0.0.1b2/connectonion.egg-info/SOURCES.txt +27 -0
- connectonion-0.0.1b2/connectonion.egg-info/dependency_links.txt +1 -0
- connectonion-0.0.1b2/connectonion.egg-info/requires.txt +3 -0
- connectonion-0.0.1b2/connectonion.egg-info/top_level.txt +2 -0
- connectonion-0.0.1b2/setup.cfg +4 -0
- connectonion-0.0.1b2/setup.py +45 -0
- connectonion-0.0.1b2/tests/__init__.py +0 -0
- connectonion-0.0.1b2/tests/conftest.py +206 -0
- connectonion-0.0.1b2/tests/integration/__init__.py +0 -0
- connectonion-0.0.1b2/tests/integration/test_agent_workflows.py +370 -0
- connectonion-0.0.1b2/tests/performance/__init__.py +0 -0
- connectonion-0.0.1b2/tests/performance/test_benchmarks.py +306 -0
- connectonion-0.0.1b2/tests/test_agent.py +201 -0
- connectonion-0.0.1b2/tests/test_agent_prompts.py +137 -0
- connectonion-0.0.1b2/tests/test_decorators.py +380 -0
- connectonion-0.0.1b2/tests/test_prompts.py +189 -0
- connectonion-0.0.1b2/tests/unit/__init__.py +0 -0
- connectonion-0.0.1b2/tests/utils/__init__.py +0 -0
- connectonion-0.0.1b2/tests/utils/mock_helpers.py +233 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: connectonion
|
|
3
|
+
Version: 0.0.1b2
|
|
4
|
+
Summary: A simple Python framework for creating AI agents with behavior tracking
|
|
5
|
+
Home-page: https://github.com/connectonion/connectonion
|
|
6
|
+
Author: ConnectOnion Team
|
|
7
|
+
Author-email: pypi@connectonion.com
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/connectonion/connectonion/issues
|
|
9
|
+
Project-URL: Source, https://github.com/connectonion/connectonion
|
|
10
|
+
Project-URL: Documentation, https://github.com/connectonion/connectonion#readme
|
|
11
|
+
Keywords: ai,agent,llm,tools,openai,automation
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: openai>=1.0.0
|
|
26
|
+
Requires-Dist: pydantic>=2.0.0
|
|
27
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: keywords
|
|
35
|
+
Dynamic: project-url
|
|
36
|
+
Dynamic: requires-dist
|
|
37
|
+
Dynamic: requires-python
|
|
38
|
+
Dynamic: summary
|
|
39
|
+
|
|
40
|
+
# ConnectOnion
|
|
41
|
+
|
|
42
|
+
> **π§ Private Beta** - ConnectOnion is currently in private beta. [Join our waitlist](https://connectonion.com) to get early access!
|
|
43
|
+
|
|
44
|
+
A simple Python framework for creating AI agents that can use tools and track their behavior.
|
|
45
|
+
|
|
46
|
+
## β¨ What's New
|
|
47
|
+
|
|
48
|
+
- **π― Function-Based Tools**: Just write regular Python functions - no classes needed!
|
|
49
|
+
- **π System Prompts**: Define your agent's personality and role
|
|
50
|
+
- **π Automatic Conversion**: Functions become OpenAI-compatible tools automatically
|
|
51
|
+
- **π Smart Schema Generation**: Type hints become function schemas
|
|
52
|
+
|
|
53
|
+
## π Quick Start
|
|
54
|
+
|
|
55
|
+
### Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install -r requirements.txt
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Basic Usage
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import os
|
|
65
|
+
from connectonion import Agent
|
|
66
|
+
|
|
67
|
+
# Set your OpenAI API key
|
|
68
|
+
os.environ["OPENAI_API_KEY"] = "your-api-key-here"
|
|
69
|
+
|
|
70
|
+
# 1. Define tools as simple functions
|
|
71
|
+
def search(query: str) -> str:
|
|
72
|
+
"""Search for information."""
|
|
73
|
+
return f"Found information about {query}"
|
|
74
|
+
|
|
75
|
+
def calculate(expression: str) -> float:
|
|
76
|
+
"""Perform mathematical calculations."""
|
|
77
|
+
return eval(expression) # Use safely in production
|
|
78
|
+
|
|
79
|
+
# 2. Create an agent with tools and personality
|
|
80
|
+
agent = Agent(
|
|
81
|
+
name="my_assistant",
|
|
82
|
+
system_prompt="You are a helpful and friendly assistant.",
|
|
83
|
+
tools=[search, calculate]
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# 3. Use the agent
|
|
87
|
+
result = agent.run("What is 25 * 4?")
|
|
88
|
+
print(result) # Agent will use the calculate function
|
|
89
|
+
|
|
90
|
+
result = agent.run("Search for Python tutorials")
|
|
91
|
+
print(result) # Agent will use the search function
|
|
92
|
+
|
|
93
|
+
# 4. View behavior history (automatic!)
|
|
94
|
+
print(agent.history.summary())
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## π§ Core Concepts
|
|
98
|
+
|
|
99
|
+
### Agent
|
|
100
|
+
The main class that orchestrates LLM calls and tool usage. Each agent:
|
|
101
|
+
- Has a unique name for tracking purposes
|
|
102
|
+
- Can be given a custom personality via `system_prompt`
|
|
103
|
+
- Automatically converts functions to tools
|
|
104
|
+
- Records all behavior to JSON files
|
|
105
|
+
|
|
106
|
+
### Function-Based Tools
|
|
107
|
+
**NEW**: Just write regular Python functions! ConnectOnion automatically converts them to tools:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
def my_tool(param: str, optional_param: int = 10) -> str:
|
|
111
|
+
"""This docstring becomes the tool description."""
|
|
112
|
+
return f"Processed {param} with value {optional_param}"
|
|
113
|
+
|
|
114
|
+
# Use it directly - no wrapping needed!
|
|
115
|
+
agent = Agent("assistant", tools=[my_tool])
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Key features:
|
|
119
|
+
- **Automatic Schema Generation**: Type hints become OpenAI function schemas
|
|
120
|
+
- **Docstring Integration**: First line becomes tool description
|
|
121
|
+
- **Parameter Handling**: Supports required and optional parameters
|
|
122
|
+
- **Type Conversion**: Handles different return types automatically
|
|
123
|
+
|
|
124
|
+
### System Prompts
|
|
125
|
+
Define your agent's personality and behavior with flexible input options:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
# 1. Direct string prompt
|
|
129
|
+
agent = Agent(
|
|
130
|
+
name="helpful_tutor",
|
|
131
|
+
system_prompt="You are an enthusiastic teacher who loves to educate.",
|
|
132
|
+
tools=[my_tools]
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# 2. Load from file (any text file, no extension restrictions)
|
|
136
|
+
agent = Agent(
|
|
137
|
+
name="support_agent",
|
|
138
|
+
system_prompt="prompts/customer_support.md" # Automatically loads file content
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
# 3. Using Path object
|
|
142
|
+
from pathlib import Path
|
|
143
|
+
agent = Agent(
|
|
144
|
+
name="coder",
|
|
145
|
+
system_prompt=Path("prompts") / "senior_developer.txt"
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# 4. None for default prompt
|
|
149
|
+
agent = Agent("basic_agent") # Uses default: "You are a helpful assistant..."
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Example prompt file (`prompts/customer_support.md`):
|
|
153
|
+
```markdown
|
|
154
|
+
# Customer Support Agent
|
|
155
|
+
|
|
156
|
+
You are a senior customer support specialist with expertise in:
|
|
157
|
+
- Empathetic communication
|
|
158
|
+
- Problem-solving
|
|
159
|
+
- Technical troubleshooting
|
|
160
|
+
|
|
161
|
+
## Guidelines
|
|
162
|
+
- Always acknowledge the customer's concern first
|
|
163
|
+
- Look for root causes, not just symptoms
|
|
164
|
+
- Provide clear, actionable solutions
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### History
|
|
168
|
+
Automatic tracking of all agent behaviors including:
|
|
169
|
+
- Tasks executed
|
|
170
|
+
- Tools called with parameters and results
|
|
171
|
+
- Agent responses and execution time
|
|
172
|
+
- Persistent storage in `~/.connectonion/agents/{name}/behavior.json`
|
|
173
|
+
|
|
174
|
+
## π― Example Tools
|
|
175
|
+
|
|
176
|
+
You can still use the traditional Tool class approach, but the new functional approach is much simpler:
|
|
177
|
+
|
|
178
|
+
### Traditional Tool Classes (Still Supported)
|
|
179
|
+
```python
|
|
180
|
+
from connectonion.tools import Calculator, CurrentTime, ReadFile
|
|
181
|
+
|
|
182
|
+
agent = Agent("assistant", tools=[Calculator(), CurrentTime(), ReadFile()])
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### New Function-Based Approach (Recommended)
|
|
186
|
+
```python
|
|
187
|
+
def calculate(expression: str) -> float:
|
|
188
|
+
"""Perform mathematical calculations."""
|
|
189
|
+
return eval(expression) # Use safely in production
|
|
190
|
+
|
|
191
|
+
def get_time(format: str = "%Y-%m-%d %H:%M:%S") -> str:
|
|
192
|
+
"""Get current date and time."""
|
|
193
|
+
from datetime import datetime
|
|
194
|
+
return datetime.now().strftime(format)
|
|
195
|
+
|
|
196
|
+
def read_file(filepath: str) -> str:
|
|
197
|
+
"""Read contents of a text file."""
|
|
198
|
+
with open(filepath, 'r') as f:
|
|
199
|
+
return f.read()
|
|
200
|
+
|
|
201
|
+
# Use them directly!
|
|
202
|
+
agent = Agent("assistant", tools=[calculate, get_time, read_file])
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The function-based approach is simpler, more Pythonic, and easier to test!
|
|
206
|
+
|
|
207
|
+
## π¨ Creating Custom Tools
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from connectonion.tools import Tool
|
|
211
|
+
|
|
212
|
+
class WeatherTool(Tool):
|
|
213
|
+
def __init__(self):
|
|
214
|
+
super().__init__(
|
|
215
|
+
name="weather",
|
|
216
|
+
description="Get current weather for a city"
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
def run(self, city: str) -> str:
|
|
220
|
+
# Your weather API logic here
|
|
221
|
+
return f"Weather in {city}: Sunny, 22Β°C"
|
|
222
|
+
|
|
223
|
+
def get_parameters_schema(self):
|
|
224
|
+
return {
|
|
225
|
+
"type": "object",
|
|
226
|
+
"properties": {
|
|
227
|
+
"city": {
|
|
228
|
+
"type": "string",
|
|
229
|
+
"description": "Name of the city"
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
"required": ["city"]
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
# Use with agent
|
|
236
|
+
agent = Agent(name="weather_agent", tools=[WeatherTool()])
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## π Project Structure
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
connectonion/
|
|
243
|
+
βββ connectonion/
|
|
244
|
+
β βββ __init__.py # Main exports
|
|
245
|
+
β βββ agent.py # Agent class
|
|
246
|
+
β βββ tools.py # Tool interface and built-ins
|
|
247
|
+
β βββ llm.py # LLM interface and OpenAI implementation
|
|
248
|
+
β βββ history.py # Behavior tracking
|
|
249
|
+
βββ examples/
|
|
250
|
+
β βββ basic_example.py
|
|
251
|
+
βββ tests/
|
|
252
|
+
β βββ test_agent.py
|
|
253
|
+
βββ requirements.txt
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## π§ͺ Running Tests
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
python -m pytest tests/
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Or run individual test files:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
python -m unittest tests.test_agent
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## π Behavior Tracking
|
|
269
|
+
|
|
270
|
+
All agent behaviors are automatically tracked and saved to:
|
|
271
|
+
```
|
|
272
|
+
~/.connectonion/agents/{agent_name}/behavior.json
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Each record includes:
|
|
276
|
+
- Timestamp
|
|
277
|
+
- Task description
|
|
278
|
+
- Tool calls with parameters and results
|
|
279
|
+
- Final result
|
|
280
|
+
- Execution duration
|
|
281
|
+
|
|
282
|
+
View behavior summary:
|
|
283
|
+
```python
|
|
284
|
+
print(agent.history.summary())
|
|
285
|
+
# Agent: my_assistant
|
|
286
|
+
# Total tasks completed: 5
|
|
287
|
+
# Total tool calls: 8
|
|
288
|
+
# Total execution time: 12.34 seconds
|
|
289
|
+
# History file: ~/.connectonion/agents/my_assistant/behavior.json
|
|
290
|
+
#
|
|
291
|
+
# Tool usage:
|
|
292
|
+
# calculator: 5 calls
|
|
293
|
+
# current_time: 3 calls
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## π Configuration
|
|
297
|
+
|
|
298
|
+
### OpenAI API Key
|
|
299
|
+
Set your API key via environment variable:
|
|
300
|
+
```bash
|
|
301
|
+
export OPENAI_API_KEY="your-api-key-here"
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Or pass directly to agent:
|
|
305
|
+
```python
|
|
306
|
+
agent = Agent(name="test", api_key="your-api-key-here")
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Model Selection
|
|
310
|
+
```python
|
|
311
|
+
agent = Agent(name="test", model="gpt-5") # Default: gpt-5-mini
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## π οΈ Advanced Usage
|
|
315
|
+
|
|
316
|
+
### Multiple Tool Calls
|
|
317
|
+
Agents can chain multiple tool calls automatically:
|
|
318
|
+
```python
|
|
319
|
+
result = agent.run(
|
|
320
|
+
"Calculate 15 * 8, then tell me what time you did this calculation"
|
|
321
|
+
)
|
|
322
|
+
# Agent will use calculator first, then current_time tool
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Custom LLM Providers
|
|
326
|
+
```python
|
|
327
|
+
from connectonion.llm import LLM
|
|
328
|
+
|
|
329
|
+
class CustomLLM(LLM):
|
|
330
|
+
def complete(self, messages, tools=None):
|
|
331
|
+
# Your custom LLM implementation
|
|
332
|
+
pass
|
|
333
|
+
|
|
334
|
+
agent = Agent(name="test", llm=CustomLLM())
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## π§ Current Limitations (MVP)
|
|
338
|
+
|
|
339
|
+
This is an MVP version with intentional limitations:
|
|
340
|
+
- Single LLM provider (OpenAI)
|
|
341
|
+
- Synchronous execution only
|
|
342
|
+
- JSON file storage only
|
|
343
|
+
- Basic error handling
|
|
344
|
+
- No multi-agent collaboration
|
|
345
|
+
|
|
346
|
+
## πΊοΈ Future Roadmap
|
|
347
|
+
|
|
348
|
+
- Multiple LLM provider support (Anthropic, Local models)
|
|
349
|
+
- Async/await support
|
|
350
|
+
- Database storage options
|
|
351
|
+
- Advanced memory systems
|
|
352
|
+
- Multi-agent collaboration
|
|
353
|
+
- Web interface for behavior monitoring
|
|
354
|
+
- Plugin system for tools
|
|
355
|
+
|
|
356
|
+
## π License
|
|
357
|
+
|
|
358
|
+
MIT License - see LICENSE file for details.
|
|
359
|
+
|
|
360
|
+
## π€ Contributing
|
|
361
|
+
|
|
362
|
+
This is an MVP. For the full version roadmap:
|
|
363
|
+
1. Fork the repository
|
|
364
|
+
2. Create a feature branch
|
|
365
|
+
3. Add tests for new functionality
|
|
366
|
+
4. Submit a pull request
|
|
367
|
+
|
|
368
|
+
## π Support
|
|
369
|
+
|
|
370
|
+
For issues and questions:
|
|
371
|
+
- Create an issue on GitHub
|
|
372
|
+
- Check the examples/ directory for usage patterns
|
|
373
|
+
- Review the test files for implementation details
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# ConnectOnion
|
|
2
|
+
|
|
3
|
+
> **π§ Private Beta** - ConnectOnion is currently in private beta. [Join our waitlist](https://connectonion.com) to get early access!
|
|
4
|
+
|
|
5
|
+
A simple Python framework for creating AI agents that can use tools and track their behavior.
|
|
6
|
+
|
|
7
|
+
## β¨ What's New
|
|
8
|
+
|
|
9
|
+
- **π― Function-Based Tools**: Just write regular Python functions - no classes needed!
|
|
10
|
+
- **π System Prompts**: Define your agent's personality and role
|
|
11
|
+
- **π Automatic Conversion**: Functions become OpenAI-compatible tools automatically
|
|
12
|
+
- **π Smart Schema Generation**: Type hints become function schemas
|
|
13
|
+
|
|
14
|
+
## π Quick Start
|
|
15
|
+
|
|
16
|
+
### Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install -r requirements.txt
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Basic Usage
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import os
|
|
26
|
+
from connectonion import Agent
|
|
27
|
+
|
|
28
|
+
# Set your OpenAI API key
|
|
29
|
+
os.environ["OPENAI_API_KEY"] = "your-api-key-here"
|
|
30
|
+
|
|
31
|
+
# 1. Define tools as simple functions
|
|
32
|
+
def search(query: str) -> str:
|
|
33
|
+
"""Search for information."""
|
|
34
|
+
return f"Found information about {query}"
|
|
35
|
+
|
|
36
|
+
def calculate(expression: str) -> float:
|
|
37
|
+
"""Perform mathematical calculations."""
|
|
38
|
+
return eval(expression) # Use safely in production
|
|
39
|
+
|
|
40
|
+
# 2. Create an agent with tools and personality
|
|
41
|
+
agent = Agent(
|
|
42
|
+
name="my_assistant",
|
|
43
|
+
system_prompt="You are a helpful and friendly assistant.",
|
|
44
|
+
tools=[search, calculate]
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# 3. Use the agent
|
|
48
|
+
result = agent.run("What is 25 * 4?")
|
|
49
|
+
print(result) # Agent will use the calculate function
|
|
50
|
+
|
|
51
|
+
result = agent.run("Search for Python tutorials")
|
|
52
|
+
print(result) # Agent will use the search function
|
|
53
|
+
|
|
54
|
+
# 4. View behavior history (automatic!)
|
|
55
|
+
print(agent.history.summary())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## π§ Core Concepts
|
|
59
|
+
|
|
60
|
+
### Agent
|
|
61
|
+
The main class that orchestrates LLM calls and tool usage. Each agent:
|
|
62
|
+
- Has a unique name for tracking purposes
|
|
63
|
+
- Can be given a custom personality via `system_prompt`
|
|
64
|
+
- Automatically converts functions to tools
|
|
65
|
+
- Records all behavior to JSON files
|
|
66
|
+
|
|
67
|
+
### Function-Based Tools
|
|
68
|
+
**NEW**: Just write regular Python functions! ConnectOnion automatically converts them to tools:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
def my_tool(param: str, optional_param: int = 10) -> str:
|
|
72
|
+
"""This docstring becomes the tool description."""
|
|
73
|
+
return f"Processed {param} with value {optional_param}"
|
|
74
|
+
|
|
75
|
+
# Use it directly - no wrapping needed!
|
|
76
|
+
agent = Agent("assistant", tools=[my_tool])
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Key features:
|
|
80
|
+
- **Automatic Schema Generation**: Type hints become OpenAI function schemas
|
|
81
|
+
- **Docstring Integration**: First line becomes tool description
|
|
82
|
+
- **Parameter Handling**: Supports required and optional parameters
|
|
83
|
+
- **Type Conversion**: Handles different return types automatically
|
|
84
|
+
|
|
85
|
+
### System Prompts
|
|
86
|
+
Define your agent's personality and behavior with flexible input options:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
# 1. Direct string prompt
|
|
90
|
+
agent = Agent(
|
|
91
|
+
name="helpful_tutor",
|
|
92
|
+
system_prompt="You are an enthusiastic teacher who loves to educate.",
|
|
93
|
+
tools=[my_tools]
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# 2. Load from file (any text file, no extension restrictions)
|
|
97
|
+
agent = Agent(
|
|
98
|
+
name="support_agent",
|
|
99
|
+
system_prompt="prompts/customer_support.md" # Automatically loads file content
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# 3. Using Path object
|
|
103
|
+
from pathlib import Path
|
|
104
|
+
agent = Agent(
|
|
105
|
+
name="coder",
|
|
106
|
+
system_prompt=Path("prompts") / "senior_developer.txt"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# 4. None for default prompt
|
|
110
|
+
agent = Agent("basic_agent") # Uses default: "You are a helpful assistant..."
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Example prompt file (`prompts/customer_support.md`):
|
|
114
|
+
```markdown
|
|
115
|
+
# Customer Support Agent
|
|
116
|
+
|
|
117
|
+
You are a senior customer support specialist with expertise in:
|
|
118
|
+
- Empathetic communication
|
|
119
|
+
- Problem-solving
|
|
120
|
+
- Technical troubleshooting
|
|
121
|
+
|
|
122
|
+
## Guidelines
|
|
123
|
+
- Always acknowledge the customer's concern first
|
|
124
|
+
- Look for root causes, not just symptoms
|
|
125
|
+
- Provide clear, actionable solutions
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### History
|
|
129
|
+
Automatic tracking of all agent behaviors including:
|
|
130
|
+
- Tasks executed
|
|
131
|
+
- Tools called with parameters and results
|
|
132
|
+
- Agent responses and execution time
|
|
133
|
+
- Persistent storage in `~/.connectonion/agents/{name}/behavior.json`
|
|
134
|
+
|
|
135
|
+
## π― Example Tools
|
|
136
|
+
|
|
137
|
+
You can still use the traditional Tool class approach, but the new functional approach is much simpler:
|
|
138
|
+
|
|
139
|
+
### Traditional Tool Classes (Still Supported)
|
|
140
|
+
```python
|
|
141
|
+
from connectonion.tools import Calculator, CurrentTime, ReadFile
|
|
142
|
+
|
|
143
|
+
agent = Agent("assistant", tools=[Calculator(), CurrentTime(), ReadFile()])
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### New Function-Based Approach (Recommended)
|
|
147
|
+
```python
|
|
148
|
+
def calculate(expression: str) -> float:
|
|
149
|
+
"""Perform mathematical calculations."""
|
|
150
|
+
return eval(expression) # Use safely in production
|
|
151
|
+
|
|
152
|
+
def get_time(format: str = "%Y-%m-%d %H:%M:%S") -> str:
|
|
153
|
+
"""Get current date and time."""
|
|
154
|
+
from datetime import datetime
|
|
155
|
+
return datetime.now().strftime(format)
|
|
156
|
+
|
|
157
|
+
def read_file(filepath: str) -> str:
|
|
158
|
+
"""Read contents of a text file."""
|
|
159
|
+
with open(filepath, 'r') as f:
|
|
160
|
+
return f.read()
|
|
161
|
+
|
|
162
|
+
# Use them directly!
|
|
163
|
+
agent = Agent("assistant", tools=[calculate, get_time, read_file])
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The function-based approach is simpler, more Pythonic, and easier to test!
|
|
167
|
+
|
|
168
|
+
## π¨ Creating Custom Tools
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from connectonion.tools import Tool
|
|
172
|
+
|
|
173
|
+
class WeatherTool(Tool):
|
|
174
|
+
def __init__(self):
|
|
175
|
+
super().__init__(
|
|
176
|
+
name="weather",
|
|
177
|
+
description="Get current weather for a city"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
def run(self, city: str) -> str:
|
|
181
|
+
# Your weather API logic here
|
|
182
|
+
return f"Weather in {city}: Sunny, 22Β°C"
|
|
183
|
+
|
|
184
|
+
def get_parameters_schema(self):
|
|
185
|
+
return {
|
|
186
|
+
"type": "object",
|
|
187
|
+
"properties": {
|
|
188
|
+
"city": {
|
|
189
|
+
"type": "string",
|
|
190
|
+
"description": "Name of the city"
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"required": ["city"]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
# Use with agent
|
|
197
|
+
agent = Agent(name="weather_agent", tools=[WeatherTool()])
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## π Project Structure
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
connectonion/
|
|
204
|
+
βββ connectonion/
|
|
205
|
+
β βββ __init__.py # Main exports
|
|
206
|
+
β βββ agent.py # Agent class
|
|
207
|
+
β βββ tools.py # Tool interface and built-ins
|
|
208
|
+
β βββ llm.py # LLM interface and OpenAI implementation
|
|
209
|
+
β βββ history.py # Behavior tracking
|
|
210
|
+
βββ examples/
|
|
211
|
+
β βββ basic_example.py
|
|
212
|
+
βββ tests/
|
|
213
|
+
β βββ test_agent.py
|
|
214
|
+
βββ requirements.txt
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## π§ͺ Running Tests
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
python -m pytest tests/
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Or run individual test files:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
python -m unittest tests.test_agent
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## π Behavior Tracking
|
|
230
|
+
|
|
231
|
+
All agent behaviors are automatically tracked and saved to:
|
|
232
|
+
```
|
|
233
|
+
~/.connectonion/agents/{agent_name}/behavior.json
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Each record includes:
|
|
237
|
+
- Timestamp
|
|
238
|
+
- Task description
|
|
239
|
+
- Tool calls with parameters and results
|
|
240
|
+
- Final result
|
|
241
|
+
- Execution duration
|
|
242
|
+
|
|
243
|
+
View behavior summary:
|
|
244
|
+
```python
|
|
245
|
+
print(agent.history.summary())
|
|
246
|
+
# Agent: my_assistant
|
|
247
|
+
# Total tasks completed: 5
|
|
248
|
+
# Total tool calls: 8
|
|
249
|
+
# Total execution time: 12.34 seconds
|
|
250
|
+
# History file: ~/.connectonion/agents/my_assistant/behavior.json
|
|
251
|
+
#
|
|
252
|
+
# Tool usage:
|
|
253
|
+
# calculator: 5 calls
|
|
254
|
+
# current_time: 3 calls
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## π Configuration
|
|
258
|
+
|
|
259
|
+
### OpenAI API Key
|
|
260
|
+
Set your API key via environment variable:
|
|
261
|
+
```bash
|
|
262
|
+
export OPENAI_API_KEY="your-api-key-here"
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Or pass directly to agent:
|
|
266
|
+
```python
|
|
267
|
+
agent = Agent(name="test", api_key="your-api-key-here")
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Model Selection
|
|
271
|
+
```python
|
|
272
|
+
agent = Agent(name="test", model="gpt-5") # Default: gpt-5-mini
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## π οΈ Advanced Usage
|
|
276
|
+
|
|
277
|
+
### Multiple Tool Calls
|
|
278
|
+
Agents can chain multiple tool calls automatically:
|
|
279
|
+
```python
|
|
280
|
+
result = agent.run(
|
|
281
|
+
"Calculate 15 * 8, then tell me what time you did this calculation"
|
|
282
|
+
)
|
|
283
|
+
# Agent will use calculator first, then current_time tool
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Custom LLM Providers
|
|
287
|
+
```python
|
|
288
|
+
from connectonion.llm import LLM
|
|
289
|
+
|
|
290
|
+
class CustomLLM(LLM):
|
|
291
|
+
def complete(self, messages, tools=None):
|
|
292
|
+
# Your custom LLM implementation
|
|
293
|
+
pass
|
|
294
|
+
|
|
295
|
+
agent = Agent(name="test", llm=CustomLLM())
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## π§ Current Limitations (MVP)
|
|
299
|
+
|
|
300
|
+
This is an MVP version with intentional limitations:
|
|
301
|
+
- Single LLM provider (OpenAI)
|
|
302
|
+
- Synchronous execution only
|
|
303
|
+
- JSON file storage only
|
|
304
|
+
- Basic error handling
|
|
305
|
+
- No multi-agent collaboration
|
|
306
|
+
|
|
307
|
+
## πΊοΈ Future Roadmap
|
|
308
|
+
|
|
309
|
+
- Multiple LLM provider support (Anthropic, Local models)
|
|
310
|
+
- Async/await support
|
|
311
|
+
- Database storage options
|
|
312
|
+
- Advanced memory systems
|
|
313
|
+
- Multi-agent collaboration
|
|
314
|
+
- Web interface for behavior monitoring
|
|
315
|
+
- Plugin system for tools
|
|
316
|
+
|
|
317
|
+
## π License
|
|
318
|
+
|
|
319
|
+
MIT License - see LICENSE file for details.
|
|
320
|
+
|
|
321
|
+
## π€ Contributing
|
|
322
|
+
|
|
323
|
+
This is an MVP. For the full version roadmap:
|
|
324
|
+
1. Fork the repository
|
|
325
|
+
2. Create a feature branch
|
|
326
|
+
3. Add tests for new functionality
|
|
327
|
+
4. Submit a pull request
|
|
328
|
+
|
|
329
|
+
## π Support
|
|
330
|
+
|
|
331
|
+
For issues and questions:
|
|
332
|
+
- Create an issue on GitHub
|
|
333
|
+
- Check the examples/ directory for usage patterns
|
|
334
|
+
- Review the test files for implementation details
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""ConnectOnion - A simple agent framework with behavior tracking."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.0.1b2"
|
|
4
|
+
|
|
5
|
+
from .agent import Agent
|
|
6
|
+
from .tools import create_tool_from_function
|
|
7
|
+
from .llm import LLM
|
|
8
|
+
from .history import History
|
|
9
|
+
from .decorators import xray, replay, xray_replay
|
|
10
|
+
|
|
11
|
+
__all__ = ["Agent", "LLM", "History", "create_tool_from_function", "xray", "replay", "xray_replay"]
|