connectonion 0.5.8__py3-none-any.whl

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.
Files changed (113) hide show
  1. connectonion/__init__.py +78 -0
  2. connectonion/address.py +320 -0
  3. connectonion/agent.py +450 -0
  4. connectonion/announce.py +84 -0
  5. connectonion/asgi.py +287 -0
  6. connectonion/auto_debug_exception.py +181 -0
  7. connectonion/cli/__init__.py +3 -0
  8. connectonion/cli/browser_agent/__init__.py +5 -0
  9. connectonion/cli/browser_agent/browser.py +243 -0
  10. connectonion/cli/browser_agent/prompt.md +107 -0
  11. connectonion/cli/commands/__init__.py +1 -0
  12. connectonion/cli/commands/auth_commands.py +527 -0
  13. connectonion/cli/commands/browser_commands.py +27 -0
  14. connectonion/cli/commands/create.py +511 -0
  15. connectonion/cli/commands/deploy_commands.py +220 -0
  16. connectonion/cli/commands/doctor_commands.py +173 -0
  17. connectonion/cli/commands/init.py +469 -0
  18. connectonion/cli/commands/project_cmd_lib.py +828 -0
  19. connectonion/cli/commands/reset_commands.py +149 -0
  20. connectonion/cli/commands/status_commands.py +168 -0
  21. connectonion/cli/docs/co-vibecoding-principles-docs-contexts-all-in-one.md +2010 -0
  22. connectonion/cli/docs/connectonion.md +1256 -0
  23. connectonion/cli/docs.md +123 -0
  24. connectonion/cli/main.py +148 -0
  25. connectonion/cli/templates/meta-agent/README.md +287 -0
  26. connectonion/cli/templates/meta-agent/agent.py +196 -0
  27. connectonion/cli/templates/meta-agent/prompts/answer_prompt.md +9 -0
  28. connectonion/cli/templates/meta-agent/prompts/docs_retrieve_prompt.md +15 -0
  29. connectonion/cli/templates/meta-agent/prompts/metagent.md +71 -0
  30. connectonion/cli/templates/meta-agent/prompts/think_prompt.md +18 -0
  31. connectonion/cli/templates/minimal/README.md +56 -0
  32. connectonion/cli/templates/minimal/agent.py +40 -0
  33. connectonion/cli/templates/playwright/README.md +118 -0
  34. connectonion/cli/templates/playwright/agent.py +336 -0
  35. connectonion/cli/templates/playwright/prompt.md +102 -0
  36. connectonion/cli/templates/playwright/requirements.txt +3 -0
  37. connectonion/cli/templates/web-research/agent.py +122 -0
  38. connectonion/connect.py +128 -0
  39. connectonion/console.py +539 -0
  40. connectonion/debug_agent/__init__.py +13 -0
  41. connectonion/debug_agent/agent.py +45 -0
  42. connectonion/debug_agent/prompts/debug_assistant.md +72 -0
  43. connectonion/debug_agent/runtime_inspector.py +406 -0
  44. connectonion/debug_explainer/__init__.py +10 -0
  45. connectonion/debug_explainer/explain_agent.py +114 -0
  46. connectonion/debug_explainer/explain_context.py +263 -0
  47. connectonion/debug_explainer/explainer_prompt.md +29 -0
  48. connectonion/debug_explainer/root_cause_analysis_prompt.md +43 -0
  49. connectonion/debugger_ui.py +1039 -0
  50. connectonion/decorators.py +208 -0
  51. connectonion/events.py +248 -0
  52. connectonion/execution_analyzer/__init__.py +9 -0
  53. connectonion/execution_analyzer/execution_analysis.py +93 -0
  54. connectonion/execution_analyzer/execution_analysis_prompt.md +47 -0
  55. connectonion/host.py +579 -0
  56. connectonion/interactive_debugger.py +342 -0
  57. connectonion/llm.py +801 -0
  58. connectonion/llm_do.py +307 -0
  59. connectonion/logger.py +300 -0
  60. connectonion/prompt_files/__init__.py +1 -0
  61. connectonion/prompt_files/analyze_contact.md +62 -0
  62. connectonion/prompt_files/eval_expected.md +12 -0
  63. connectonion/prompt_files/react_evaluate.md +11 -0
  64. connectonion/prompt_files/react_plan.md +16 -0
  65. connectonion/prompt_files/reflect.md +22 -0
  66. connectonion/prompts.py +144 -0
  67. connectonion/relay.py +200 -0
  68. connectonion/static/docs.html +688 -0
  69. connectonion/tool_executor.py +279 -0
  70. connectonion/tool_factory.py +186 -0
  71. connectonion/tool_registry.py +105 -0
  72. connectonion/trust.py +166 -0
  73. connectonion/trust_agents.py +71 -0
  74. connectonion/trust_functions.py +88 -0
  75. connectonion/tui/__init__.py +57 -0
  76. connectonion/tui/divider.py +39 -0
  77. connectonion/tui/dropdown.py +251 -0
  78. connectonion/tui/footer.py +31 -0
  79. connectonion/tui/fuzzy.py +56 -0
  80. connectonion/tui/input.py +278 -0
  81. connectonion/tui/keys.py +35 -0
  82. connectonion/tui/pick.py +130 -0
  83. connectonion/tui/providers.py +155 -0
  84. connectonion/tui/status_bar.py +163 -0
  85. connectonion/usage.py +161 -0
  86. connectonion/useful_events_handlers/__init__.py +16 -0
  87. connectonion/useful_events_handlers/reflect.py +116 -0
  88. connectonion/useful_plugins/__init__.py +20 -0
  89. connectonion/useful_plugins/calendar_plugin.py +163 -0
  90. connectonion/useful_plugins/eval.py +139 -0
  91. connectonion/useful_plugins/gmail_plugin.py +162 -0
  92. connectonion/useful_plugins/image_result_formatter.py +127 -0
  93. connectonion/useful_plugins/re_act.py +78 -0
  94. connectonion/useful_plugins/shell_approval.py +159 -0
  95. connectonion/useful_tools/__init__.py +44 -0
  96. connectonion/useful_tools/diff_writer.py +192 -0
  97. connectonion/useful_tools/get_emails.py +183 -0
  98. connectonion/useful_tools/gmail.py +1596 -0
  99. connectonion/useful_tools/google_calendar.py +613 -0
  100. connectonion/useful_tools/memory.py +380 -0
  101. connectonion/useful_tools/microsoft_calendar.py +604 -0
  102. connectonion/useful_tools/outlook.py +488 -0
  103. connectonion/useful_tools/send_email.py +205 -0
  104. connectonion/useful_tools/shell.py +97 -0
  105. connectonion/useful_tools/slash_command.py +201 -0
  106. connectonion/useful_tools/terminal.py +285 -0
  107. connectonion/useful_tools/todo_list.py +241 -0
  108. connectonion/useful_tools/web_fetch.py +216 -0
  109. connectonion/xray.py +467 -0
  110. connectonion-0.5.8.dist-info/METADATA +741 -0
  111. connectonion-0.5.8.dist-info/RECORD +113 -0
  112. connectonion-0.5.8.dist-info/WHEEL +4 -0
  113. connectonion-0.5.8.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,741 @@
1
+ Metadata-Version: 2.4
2
+ Name: connectonion
3
+ Version: 0.5.8
4
+ Summary: A simple Python framework for creating AI agents with behavior tracking
5
+ Project-URL: Homepage, https://github.com/openonion/connectonion
6
+ Project-URL: Documentation, https://docs.connectonion.com
7
+ Project-URL: Repository, https://github.com/openonion/connectonion
8
+ Project-URL: Bug Tracker, https://github.com/openonion/connectonion/issues
9
+ Author-email: ConnectOnion Team <pypi@connectonion.com>
10
+ License: MIT
11
+ Keywords: agent,ai,automation,breakpoints,debugging,interactive-debugging,llm,openai,tools,xray
12
+ Classifier: Development Status :: 5 - Production/Stable
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.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: anthropic>=0.18.0
25
+ Requires-Dist: beautifulsoup4>=4.12.0
26
+ Requires-Dist: click>=8.0.0
27
+ Requires-Dist: google-api-python-client>=2.0.0
28
+ Requires-Dist: google-auth>=2.0.0
29
+ Requires-Dist: httpx>=0.24.0
30
+ Requires-Dist: litellm>=1.0.0
31
+ Requires-Dist: mnemonic>=0.20
32
+ Requires-Dist: openai>=1.0.0
33
+ Requires-Dist: pydantic>=2.0.0
34
+ Requires-Dist: pyjwt>=2.0.0
35
+ Requires-Dist: pynacl>=1.5.0
36
+ Requires-Dist: python-dotenv>=1.0.0
37
+ Requires-Dist: pyyaml>=6.0.0
38
+ Requires-Dist: questionary>=2.0.0
39
+ Requires-Dist: requests>=2.25.0
40
+ Requires-Dist: rich>=13.0.0
41
+ Requires-Dist: toml>=0.10.2
42
+ Requires-Dist: typer>=0.20.0
43
+ Requires-Dist: uvicorn>=0.20.0
44
+ Requires-Dist: websockets>=11.0.0
45
+ Provides-Extra: browser
46
+ Requires-Dist: playwright>=1.40.0; extra == 'browser'
47
+ Provides-Extra: dev
48
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
49
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
50
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
51
+ Description-Content-Type: text/markdown
52
+
53
+ # πŸ§… ConnectOnion
54
+
55
+ <div align="center">
56
+
57
+ [![Production Ready](https://img.shields.io/badge/Status-Production_Ready-success?style=flat-square)](https://connectonion.com)
58
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
59
+ [![Python 3.10+](https://img.shields.io/badge/Python-3.10+-blue?style=flat-square&logo=python)](https://python.org)
60
+ [![PyPI Downloads](https://static.pepy.tech/personalized-badge/connectonion?period=total&units=international_system&left_color=black&right_color=green&left_text=downloads)](https://pepy.tech/projects/connectonion)
61
+ [![GitHub stars](https://img.shields.io/github/stars/openonion/connectonion?style=flat-square)](https://github.com/openonion/connectonion)
62
+ [![Contributors](https://img.shields.io/github/contributors/openonion/connectonion?style=flat-square)](https://github.com/openonion/connectonion/graphs/contributors)
63
+ [![Discord](https://img.shields.io/badge/Discord-Join-7289DA?style=flat-square&logo=discord)](https://discord.gg/4xfD9k8AUF)
64
+ [![Documentation](https://img.shields.io/badge/Docs-docs.connectonion.com-blue?style=flat-square)](http://docs.connectonion.com)
65
+
66
+ **A simple, elegant open-source framework for production-ready AI agents**
67
+
68
+ [πŸ“š Documentation](http://docs.connectonion.com) β€’ [πŸ’¬ Discord](https://discord.gg/4xfD9k8AUF) β€’ [⭐ Star Us](https://github.com/openonion/connectonion)
69
+
70
+ </div>
71
+
72
+ ---
73
+
74
+ > ## 🌟 Philosophy: "Keep simple things simple, make complicated things possible"
75
+ >
76
+ > This is the core principle that drives every design decision in ConnectOnion.
77
+
78
+ ## 🎯 Living Our Philosophy
79
+
80
+ ### Step 1: Simple - Create and Use
81
+ ```python
82
+ from connectonion import Agent
83
+
84
+ agent = Agent(name="assistant")
85
+ agent.input("Hello!") # That's it!
86
+ ```
87
+
88
+ ### Step 2: Add Your Tools
89
+ ```python
90
+ def search(query: str) -> str:
91
+ """Search for information."""
92
+ return f"Results for {query}"
93
+
94
+ agent = Agent(name="assistant", tools=[search])
95
+ agent.input("Search for Python tutorials")
96
+ ```
97
+
98
+ ### Step 3: Debug Your Agent
99
+ ```python
100
+ agent = Agent(name="assistant", tools=[search])
101
+ agent.auto_debug() # Interactive debugging session
102
+ ```
103
+
104
+ ### Step 4: Production Ready
105
+ ```python
106
+ agent = Agent(
107
+ name="production",
108
+ model="gpt-5", # Latest models
109
+ tools=[search, analyze, execute], # Your functions as tools
110
+ system_prompt=company_prompt, # Custom behavior
111
+ max_iterations=10, # Safety controls
112
+ trust="prompt" # Multi-agent ready
113
+ )
114
+ agent.input("Complex production task")
115
+ ```
116
+
117
+ ### Step 5: Multi-Agent - Make it Remotely Callable
118
+ ```python
119
+ from connectonion import host
120
+ host(agent) # HTTP server + P2P relay - other agents can now discover and call this agent
121
+ ```
122
+
123
+ ## ✨ Why ConnectOnion?
124
+
125
+ <table>
126
+ <tr>
127
+ <td width="33%">
128
+
129
+ ### 🎯 **Simple API**
130
+ Just one `Agent` class. Your functions become tools automatically. Start in 2 lines, not 200.
131
+
132
+ </td>
133
+ <td width="33%">
134
+
135
+ ### πŸš€ **Production Ready**
136
+ Battle-tested with GPT-5, Gemini 2.5, Claude Opus 4.1. Logging, debugging, trust system built-in.
137
+
138
+ </td>
139
+ <td width="33%">
140
+
141
+ ### 🌍 **Open Source**
142
+ MIT licensed. Community-driven. Join 1000+ developers building the future of AI agents.
143
+
144
+ </td>
145
+ </tr>
146
+ <tr>
147
+ <td width="33%">
148
+
149
+ ### πŸ”Œ **Plugin System**
150
+ Add reflection & reasoning to any agent in one line. Extensible and composable.
151
+
152
+ </td>
153
+ <td width="33%">
154
+
155
+ ### πŸ” **Interactive Debugging**
156
+ Pause at breakpoints with `@xray`, inspect state, modify variables on-the-fly.
157
+
158
+ </td>
159
+ <td width="33%">
160
+
161
+ ### ⚑ **No Boilerplate**
162
+ Scale from prototypes to production systems without rewriting code.
163
+
164
+ </td>
165
+ </tr>
166
+ </table>
167
+
168
+ ---
169
+
170
+ ## πŸ’¬ Join the Community
171
+
172
+ [![Discord](https://img.shields.io/discord/1234567890?color=7289da&label=Join%20Discord&logo=discord&logoColor=white&style=for-the-badge)](https://discord.gg/4xfD9k8AUF)
173
+
174
+ Get help, share agents, and discuss with 1000+ builders in our active community.
175
+
176
+ ---
177
+
178
+ ## πŸš€ Quick Start
179
+
180
+ ### Installation
181
+
182
+ ```bash
183
+ pip install connectonion
184
+ ```
185
+
186
+ ### Quickest Start - Use the CLI
187
+
188
+ ```bash
189
+ # Create a new agent project with one command
190
+ co create my-agent
191
+
192
+ # Navigate and run
193
+ cd my-agent
194
+ python agent.py
195
+ ```
196
+
197
+ *The CLI guides you through API key setup automatically. No manual `.env` editing needed!*
198
+
199
+ ### Manual Usage
200
+
201
+ ```python
202
+ import os
203
+ from connectonion import Agent
204
+
205
+ # Set your OpenAI API key
206
+ os.environ["OPENAI_API_KEY"] = "your-api-key-here"
207
+
208
+ # 1. Define tools as simple functions
209
+ def search(query: str) -> str:
210
+ """Search for information."""
211
+ return f"Found information about {query}"
212
+
213
+ def calculate(expression: str) -> float:
214
+ """Perform mathematical calculations."""
215
+ return eval(expression) # Use safely in production
216
+
217
+ # 2. Create an agent with tools and personality
218
+ agent = Agent(
219
+ name="my_assistant",
220
+ system_prompt="You are a helpful and friendly assistant.",
221
+ tools=[search, calculate]
222
+ # max_iterations=10 is the default - agent will try up to 10 tool calls per task
223
+ )
224
+
225
+ # 3. Use the agent
226
+ result = agent.input("What is 25 * 4?")
227
+ print(result) # Agent will use the calculate function
228
+
229
+ result = agent.input("Search for Python tutorials")
230
+ print(result) # Agent will use the search function
231
+
232
+ # 4. View behavior history (automatic!)
233
+ print(agent.history.summary())
234
+ ```
235
+
236
+ ### πŸ” Interactive Debugging with `@xray`
237
+
238
+ Debug your agents like you debug code - pause at breakpoints, inspect variables, and test edge cases:
239
+
240
+ ```python
241
+ from connectonion import Agent
242
+ from connectonion.decorators import xray
243
+
244
+ # Mark tools you want to debug with @xray
245
+ @xray
246
+ def search_database(query: str) -> str:
247
+ """Search for information."""
248
+ return f"Found 3 results for '{query}'"
249
+
250
+ @xray
251
+ def send_email(to: str, subject: str) -> str:
252
+ """Send an email."""
253
+ return f"Email sent to {to}"
254
+
255
+ # Create agent with @xray tools
256
+ agent = Agent(
257
+ name="debug_demo",
258
+ tools=[search_database, send_email]
259
+ )
260
+
261
+ # Launch interactive debugging session
262
+ agent.auto_debug()
263
+
264
+ # Or debug a specific task
265
+ agent.auto_debug("Search for Python tutorials and email the results")
266
+ ```
267
+
268
+ **What happens at each `@xray` breakpoint:**
269
+
270
+ ```
271
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
272
+ @xray BREAKPOINT: search_database
273
+
274
+ Local Variables:
275
+ query = "Python tutorials"
276
+ result = "Found 3 results for 'Python tutorials'"
277
+
278
+ What do you want to do?
279
+ β†’ Continue execution πŸš€ [c or Enter]
280
+ Edit values πŸ” [e]
281
+ Quit debugging 🚫 [q]
282
+
283
+ πŸ’‘ Use arrow keys to navigate or type shortcuts
284
+ >
285
+ ```
286
+
287
+ **Key features:**
288
+ - **Pause at breakpoints**: Tools decorated with `@xray` pause execution
289
+ - **Inspect state**: See all local variables and execution context
290
+ - **Edit variables**: Modify results to test "what if" scenarios
291
+ - **Full Python REPL**: Run any code to explore agent behavior
292
+ - **See next action**: Preview what the LLM plans to do next
293
+
294
+ Perfect for:
295
+ - Understanding why agents make certain decisions
296
+ - Testing edge cases without modifying code
297
+ - Exploring agent behavior interactively
298
+ - Debugging complex multi-tool workflows
299
+
300
+ [Learn more in the auto_debug guide](docs/auto_debug.md)
301
+
302
+ ### πŸ”Œ Plugin System
303
+
304
+ Package reusable capabilities as plugins and use them across multiple agents:
305
+
306
+ ```python
307
+ from connectonion import Agent, after_tools, llm_do
308
+
309
+ # Define a reflection plugin
310
+ def add_reflection(agent):
311
+ trace = agent.current_session['trace'][-1]
312
+ if trace['type'] == 'tool_execution' and trace['status'] == 'success':
313
+ result = trace['result']
314
+ reflection = llm_do(
315
+ f"Result: {result[:200]}\n\nWhat did we learn?",
316
+ system_prompt="Be concise.",
317
+ temperature=0.3
318
+ )
319
+ agent.current_session['messages'].append({
320
+ 'role': 'assistant',
321
+ 'content': f"πŸ€” {reflection}"
322
+ })
323
+
324
+ # Plugin is just a list of event handlers
325
+ reflection = [after_tools(add_reflection)] # after_tools fires once after all tools
326
+
327
+ # Use across multiple agents
328
+ researcher = Agent("researcher", tools=[search], plugins=[reflection])
329
+ analyst = Agent("analyst", tools=[analyze], plugins=[reflection])
330
+ ```
331
+
332
+ **What plugins provide:**
333
+ - **Reusable capabilities**: Package event handlers into bundles
334
+ - **Simple pattern**: A plugin is just a list of event handlers
335
+ - **Easy composition**: Combine multiple plugins together
336
+ - **Built-in examples**: Reflection, logging, todo tracking, and more
337
+
338
+ [Learn more about plugins](docs/plugin.md)
339
+
340
+ ## πŸ”§ Core Concepts
341
+
342
+ ### Agent
343
+ The main class that orchestrates LLM calls and tool usage. Each agent:
344
+ - Has a unique name for tracking purposes
345
+ - Can be given a custom personality via `system_prompt`
346
+ - Automatically converts functions to tools
347
+ - Records all behavior to JSON files
348
+
349
+ ### Function-Based Tools
350
+ **NEW**: Just write regular Python functions! ConnectOnion automatically converts them to tools:
351
+
352
+ ```python
353
+ def my_tool(param: str, optional_param: int = 10) -> str:
354
+ """This docstring becomes the tool description."""
355
+ return f"Processed {param} with value {optional_param}"
356
+
357
+ # Use it directly - no wrapping needed!
358
+ agent = Agent("assistant", tools=[my_tool])
359
+ ```
360
+
361
+ Key features:
362
+ - **Automatic Schema Generation**: Type hints become OpenAI function schemas
363
+ - **Docstring Integration**: First line becomes tool description
364
+ - **Parameter Handling**: Supports required and optional parameters
365
+ - **Type Conversion**: Handles different return types automatically
366
+
367
+ ### System Prompts
368
+ Define your agent's personality and behavior with flexible input options:
369
+
370
+ ```python
371
+ # 1. Direct string prompt
372
+ agent = Agent(
373
+ name="helpful_tutor",
374
+ system_prompt="You are an enthusiastic teacher who loves to educate.",
375
+ tools=[my_tools]
376
+ )
377
+
378
+ # 2. Load from file (any text file, no extension restrictions)
379
+ agent = Agent(
380
+ name="support_agent",
381
+ system_prompt="prompts/customer_support.md" # Automatically loads file content
382
+ )
383
+
384
+ # 3. Using Path object
385
+ from pathlib import Path
386
+ agent = Agent(
387
+ name="coder",
388
+ system_prompt=Path("prompts") / "senior_developer.txt"
389
+ )
390
+
391
+ # 4. None for default prompt
392
+ agent = Agent("basic_agent") # Uses default: "You are a helpful assistant..."
393
+ ```
394
+
395
+ Example prompt file (`prompts/customer_support.md`):
396
+ ```markdown
397
+ # Customer Support Agent
398
+
399
+ You are a senior customer support specialist with expertise in:
400
+ - Empathetic communication
401
+ - Problem-solving
402
+ - Technical troubleshooting
403
+
404
+ ## Guidelines
405
+ - Always acknowledge the customer's concern first
406
+ - Look for root causes, not just symptoms
407
+ - Provide clear, actionable solutions
408
+ ```
409
+
410
+ ### Logging
411
+ Automatic logging of all agent activities including:
412
+ - User inputs and agent responses
413
+ - LLM calls with timing
414
+ - Tool executions with parameters and results
415
+ - Default storage in `.co/logs/{name}.log` (human-readable format)
416
+
417
+ ## 🎯 Example Tools
418
+
419
+ You can still use the traditional Tool class approach, but the new functional approach is much simpler:
420
+
421
+ ### Traditional Tool Classes (Still Supported)
422
+ ```python
423
+ from connectonion.tools import Calculator, CurrentTime, ReadFile
424
+
425
+ agent = Agent("assistant", tools=[Calculator(), CurrentTime(), ReadFile()])
426
+ ```
427
+
428
+ ### New Function-Based Approach (Recommended)
429
+ ```python
430
+ def calculate(expression: str) -> float:
431
+ """Perform mathematical calculations."""
432
+ return eval(expression) # Use safely in production
433
+
434
+ def get_time(format: str = "%Y-%m-%d %H:%M:%S") -> str:
435
+ """Get current date and time."""
436
+ from datetime import datetime
437
+ return datetime.now().strftime(format)
438
+
439
+ def read_file(filepath: str) -> str:
440
+ """Read contents of a text file."""
441
+ with open(filepath, 'r') as f:
442
+ return f.read()
443
+
444
+ # Use them directly!
445
+ agent = Agent("assistant", tools=[calculate, get_time, read_file])
446
+ ```
447
+
448
+ The function-based approach is simpler, more Pythonic, and easier to test!
449
+
450
+ ## 🎨 CLI Templates
451
+
452
+ ConnectOnion CLI provides templates to get you started quickly:
453
+
454
+ ```bash
455
+ # Create a minimal agent (default)
456
+ co create my-agent
457
+
458
+ # Create with specific template
459
+ co create my-playwright-bot --template playwright
460
+
461
+ # Initialize in existing directory
462
+ co init # Adds .co folder only
463
+ co init --template playwright # Adds full template
464
+ ```
465
+
466
+ **Available Templates:**
467
+ - `minimal` (default) - Simple agent starter
468
+ - `playwright` - Web automation with browser tools
469
+ - `meta-agent` - Development assistant with docs search
470
+ - `web-research` - Web research and data extraction
471
+
472
+ Each template includes:
473
+ - Pre-configured agent ready to run
474
+ - Automatic API key setup
475
+ - Embedded ConnectOnion documentation
476
+ - Git-ready `.gitignore`
477
+
478
+ Learn more in the [CLI Documentation](docs/cli/) and [Templates Guide](docs/templates/).
479
+
480
+ ## πŸ”¨ Creating Custom Tools
481
+
482
+ The simplest way is to use functions (recommended):
483
+
484
+ ```python
485
+ def weather(city: str) -> str:
486
+ """Get current weather for a city."""
487
+ # Your weather API logic here
488
+ return f"Weather in {city}: Sunny, 22Β°C"
489
+
490
+ # That's it! Use it directly
491
+ agent = Agent(name="weather_agent", tools=[weather])
492
+ ```
493
+
494
+ Or use the Tool class for more control:
495
+
496
+ ```python
497
+ from connectonion.tools import Tool
498
+
499
+ class WeatherTool(Tool):
500
+ def __init__(self):
501
+ super().__init__(
502
+ name="weather",
503
+ description="Get current weather for a city"
504
+ )
505
+
506
+ def run(self, city: str) -> str:
507
+ return f"Weather in {city}: Sunny, 22Β°C"
508
+
509
+ def get_parameters_schema(self):
510
+ return {
511
+ "type": "object",
512
+ "properties": {
513
+ "city": {"type": "string", "description": "City name"}
514
+ },
515
+ "required": ["city"]
516
+ }
517
+
518
+ agent = Agent(name="weather_agent", tools=[WeatherTool()])
519
+ ```
520
+
521
+ ## πŸ“ Project Structure
522
+
523
+ ```
524
+ connectonion/
525
+ β”œβ”€β”€ connectonion/
526
+ β”‚ β”œβ”€β”€ __init__.py # Main exports
527
+ β”‚ β”œβ”€β”€ agent.py # Agent class
528
+ β”‚ β”œβ”€β”€ tools.py # Tool interface and built-ins
529
+ β”‚ β”œβ”€β”€ llm.py # LLM interface and OpenAI implementation
530
+ β”‚ β”œβ”€β”€ console.py # Terminal output and logging
531
+ β”‚ └── cli/ # CLI module
532
+ β”‚ β”œβ”€β”€ main.py # CLI commands
533
+ β”‚ β”œβ”€β”€ docs.md # Embedded documentation
534
+ β”‚ └── templates/ # Agent templates
535
+ β”‚ β”œβ”€β”€ basic_agent.py
536
+ β”‚ β”œβ”€β”€ chat_agent.py
537
+ β”‚ β”œβ”€β”€ data_agent.py
538
+ β”‚ └── *.md # Prompt templates
539
+ β”œβ”€β”€ docs/ # Documentation
540
+ β”‚ β”œβ”€β”€ quickstart.md
541
+ β”‚ β”œβ”€β”€ concepts/ # Core concepts
542
+ β”‚ β”œβ”€β”€ cli/ # CLI commands
543
+ β”‚ β”œβ”€β”€ templates/ # Project templates
544
+ β”‚ └── ...
545
+ β”œβ”€β”€ examples/
546
+ β”‚ └── basic_example.py
547
+ β”œβ”€β”€ tests/
548
+ β”‚ └── test_agent.py
549
+ └── pyproject.toml
550
+ ```
551
+
552
+ ## πŸ§ͺ Running Tests
553
+
554
+ ```bash
555
+ python -m pytest tests/
556
+ ```
557
+
558
+ Or run individual test files:
559
+
560
+ ```bash
561
+ python -m unittest tests.test_agent
562
+ ```
563
+
564
+ ## πŸ“Š Automatic Logging
565
+
566
+ All agent activities are automatically logged to:
567
+ ```
568
+ .co/logs/{agent_name}.log # Default location
569
+ ```
570
+
571
+ Each log entry includes:
572
+ - Timestamp
573
+ - User input
574
+ - LLM calls with timing
575
+ - Tool executions with parameters and results
576
+ - Final responses
577
+
578
+ Control logging behavior:
579
+ ```python
580
+ # Default: logs to .co/logs/assistant.log
581
+ agent = Agent("assistant")
582
+
583
+ # Log to current directory
584
+ agent = Agent("assistant", log=True) # β†’ assistant.log
585
+
586
+ # Disable logging
587
+ agent = Agent("assistant", log=False)
588
+
589
+ # Custom log file
590
+ agent = Agent("assistant", log="my_logs/custom.log")
591
+ ```
592
+
593
+ ## πŸ”‘ Configuration
594
+
595
+ ### OpenAI API Key
596
+ Set your API key via environment variable:
597
+ ```bash
598
+ export OPENAI_API_KEY="your-api-key-here"
599
+ ```
600
+
601
+ Or pass directly to agent:
602
+ ```python
603
+ agent = Agent(name="test", api_key="your-api-key-here")
604
+ ```
605
+
606
+ ### Model Selection
607
+ ```python
608
+ agent = Agent(name="test", model="gpt-5") # Default: gpt-5-mini
609
+ ```
610
+
611
+ ### Iteration Control
612
+ Control how many tool calling iterations an agent can perform:
613
+
614
+ ```python
615
+ # Default: 10 iterations (good for most tasks)
616
+ agent = Agent(name="assistant", tools=[...])
617
+
618
+ # Complex tasks may need more iterations
619
+ research_agent = Agent(
620
+ name="researcher",
621
+ tools=[search, analyze, summarize, write_file],
622
+ max_iterations=25 # Allow more steps for complex workflows
623
+ )
624
+
625
+ # Simple agents can use fewer iterations for safety
626
+ calculator = Agent(
627
+ name="calc",
628
+ tools=[calculate],
629
+ max_iterations=5 # Prevent runaway calculations
630
+ )
631
+
632
+ # Per-request override for specific complex tasks
633
+ result = agent.input(
634
+ "Analyze all project files and generate comprehensive report",
635
+ max_iterations=50 # Override for this specific task
636
+ )
637
+ ```
638
+
639
+ When an agent reaches its iteration limit, it returns:
640
+ ```
641
+ "Task incomplete: Maximum iterations (10) reached."
642
+ ```
643
+
644
+ **Choosing the Right Limit:**
645
+ - **Simple tasks (1-3 tools)**: 5-10 iterations
646
+ - **Standard workflows**: 10-15 iterations (default: 10)
647
+ - **Complex analysis**: 20-30 iterations
648
+ - **Research/multi-step**: 30+ iterations
649
+
650
+ ## πŸ› οΈ Advanced Usage
651
+
652
+ ### Multiple Tool Calls
653
+ Agents can chain multiple tool calls automatically:
654
+ ```python
655
+ result = agent.input(
656
+ "Calculate 15 * 8, then tell me what time you did this calculation"
657
+ )
658
+ # Agent will use calculator first, then current_time tool
659
+ ```
660
+
661
+ ### Custom LLM Providers
662
+ ```python
663
+ from connectonion.llm import LLM
664
+
665
+ class CustomLLM(LLM):
666
+ def complete(self, messages, tools=None):
667
+ # Your custom LLM implementation
668
+ pass
669
+
670
+ agent = Agent(name="test", llm=CustomLLM())
671
+ ```
672
+
673
+ ## πŸ—ΊοΈ Roadmap
674
+
675
+ **Current Focus:**
676
+ - Multi-agent networking (serve/connect)
677
+ - Trust system for agent collaboration
678
+ - `co deploy` for one-command deployment
679
+
680
+ **Recently Completed:**
681
+ - Multiple LLM providers (OpenAI, Anthropic, Gemini)
682
+ - Managed API keys (`co/` prefix)
683
+ - Plugin system
684
+ - Google OAuth integration
685
+ - Interactive debugging (`@xray`, `auto_debug`)
686
+
687
+ See [full roadmap](docs/roadmap.md) for details.
688
+
689
+ ## πŸ”— Connect With Us
690
+
691
+ <div align="center">
692
+
693
+ [![Discord](https://img.shields.io/badge/Discord-Join_Community-5865F2?style=for-the-badge&logo=discord)](https://discord.gg/4xfD9k8AUF)
694
+ [![GitHub](https://img.shields.io/badge/GitHub-Star_Us-black?style=for-the-badge&logo=github)](https://github.com/openonion/connectonion)
695
+ [![Documentation](https://img.shields.io/badge/Docs-Learn_More-blue?style=for-the-badge)](http://docs.connectonion.com)
696
+
697
+ </div>
698
+
699
+ - **πŸ’¬ Discord**: [Join our community](https://discord.gg/4xfD9k8AUF) - Get help, share ideas, meet other developers
700
+ - **πŸ“š Documentation**: [docs.connectonion.com](http://docs.connectonion.com) - Comprehensive guides and examples
701
+ - **⭐ GitHub**: [Star the repo](https://github.com/openonion/connectonion) - Show your support
702
+ - **πŸ› Issues**: [Report bugs](https://github.com/openonion/connectonion/issues) - We respond quickly
703
+
704
+ ---
705
+
706
+ ## ⭐ Show Your Support
707
+
708
+ If ConnectOnion helps you build better agents, **give it a star!** ⭐
709
+
710
+ It helps others discover the framework and motivates us to keep improving it.
711
+
712
+ [⭐ Star on GitHub](https://github.com/openonion/connectonion)
713
+
714
+ ---
715
+
716
+ ## 🀝 Contributing
717
+
718
+ We welcome contributions! ConnectOnion is open source and community-driven.
719
+
720
+ 1. Fork the repository
721
+ 2. Create a feature branch
722
+ 3. Add tests for new functionality
723
+ 4. Submit a pull request
724
+
725
+ See our [Contributing Guide](http://docs.connectonion.com/website-maintenance) for more details.
726
+
727
+ ---
728
+
729
+ ## πŸ“„ License
730
+
731
+ MIT License - Use it anywhere, even commercially. See [LICENSE](LICENSE) file for details.
732
+
733
+ ---
734
+
735
+ <div align="center">
736
+
737
+ **Built with ❀️ by the open-source community**
738
+
739
+ [⭐ Star this repo](https://github.com/openonion/connectonion) β€’ [πŸ’¬ Join Discord](https://discord.gg/4xfD9k8AUF) β€’ [πŸ“– Read Docs](https://docs.connectonion.com) β€’ [⬆ Back to top](#-connectonion)
740
+
741
+ </div>