connectonion 0.6.1__py3-none-any.whl → 0.6.3__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 (413) hide show
  1. connectonion/__init__.py +46 -9
  2. connectonion/cli/__init__.py +11 -1
  3. connectonion/cli/browser_agent/__init__.py +11 -1
  4. connectonion/cli/browser_agent/browser.py +95 -142
  5. connectonion/cli/browser_agent/element_finder.py +147 -0
  6. connectonion/cli/browser_agent/highlight_screenshot.py +182 -0
  7. connectonion/cli/browser_agent/prompt.md +188 -105
  8. connectonion/cli/browser_agent/prompts/element_matcher.md +59 -0
  9. connectonion/cli/browser_agent/prompts/form_filler.md +19 -0
  10. connectonion/cli/browser_agent/prompts/scroll_strategy.md +36 -0
  11. connectonion/cli/browser_agent/scripts/extract_elements.js +126 -0
  12. connectonion/cli/browser_agent/scroll.py +145 -0
  13. connectonion/cli/co_ai/__init__.py +6 -0
  14. connectonion/cli/co_ai/agent.py +87 -0
  15. connectonion/cli/co_ai/agents/__init__.py +5 -0
  16. connectonion/cli/co_ai/agents/registry.py +57 -0
  17. connectonion/cli/co_ai/commands/__init__.py +45 -0
  18. connectonion/cli/co_ai/commands/compact.py +173 -0
  19. connectonion/cli/co_ai/commands/cost.py +77 -0
  20. connectonion/cli/co_ai/commands/export.py +60 -0
  21. connectonion/cli/co_ai/commands/help.py +80 -0
  22. connectonion/cli/co_ai/commands/init.py +101 -0
  23. connectonion/cli/co_ai/commands/sessions.py +55 -0
  24. connectonion/cli/co_ai/commands/tasks.py +63 -0
  25. connectonion/cli/co_ai/commands/undo.py +103 -0
  26. connectonion/cli/co_ai/context.py +127 -0
  27. connectonion/cli/co_ai/main.py +52 -0
  28. connectonion/cli/co_ai/plugins/__init__.py +6 -0
  29. connectonion/cli/co_ai/plugins/reminder.py +76 -0
  30. connectonion/cli/co_ai/plugins/shell_approval.py +105 -0
  31. connectonion/cli/co_ai/prompts/agents/explore.md +79 -0
  32. connectonion/cli/co_ai/prompts/agents/plan.md +60 -0
  33. connectonion/cli/co_ai/prompts/assembler.py +303 -0
  34. connectonion/cli/{docs/co-vibecoding-principles-docs-contexts-all-in-one.md → co_ai/prompts/connectonion/README.md} +26 -0
  35. connectonion/cli/co_ai/prompts/connectonion/api.md +457 -0
  36. connectonion/cli/co_ai/prompts/connectonion/cli/README.md +805 -0
  37. connectonion/cli/co_ai/prompts/connectonion/cli/auth.md +46 -0
  38. connectonion/cli/co_ai/prompts/connectonion/cli/browser.md +235 -0
  39. connectonion/cli/co_ai/prompts/connectonion/cli/copy.md +184 -0
  40. connectonion/cli/co_ai/prompts/connectonion/cli/create.md +335 -0
  41. connectonion/cli/co_ai/prompts/connectonion/cli/init.md +431 -0
  42. connectonion/cli/co_ai/prompts/connectonion/co-directory-structure.md +214 -0
  43. connectonion/cli/co_ai/prompts/connectonion/concepts/agent.md +1078 -0
  44. connectonion/cli/co_ai/prompts/connectonion/concepts/events.md +816 -0
  45. connectonion/cli/co_ai/prompts/connectonion/concepts/llm_do.md +256 -0
  46. connectonion/cli/co_ai/prompts/connectonion/concepts/max_iterations.md +362 -0
  47. connectonion/cli/co_ai/prompts/connectonion/concepts/models.md +641 -0
  48. connectonion/cli/co_ai/prompts/connectonion/concepts/plugins.md +100 -0
  49. connectonion/cli/co_ai/prompts/connectonion/concepts/prompts.md +122 -0
  50. connectonion/cli/co_ai/prompts/connectonion/concepts/tools.md +512 -0
  51. connectonion/cli/co_ai/prompts/connectonion/concepts/transcribe.md +156 -0
  52. connectonion/cli/co_ai/prompts/connectonion/concepts/trust.md +291 -0
  53. connectonion/cli/co_ai/prompts/connectonion/debug/README.md +18 -0
  54. connectonion/cli/co_ai/prompts/connectonion/debug/auto_debug.md +1026 -0
  55. connectonion/cli/co_ai/prompts/connectonion/debug/console.md +129 -0
  56. connectonion/cli/co_ai/prompts/connectonion/debug/eval-format.md +178 -0
  57. connectonion/cli/co_ai/prompts/connectonion/debug/eval.md +230 -0
  58. connectonion/cli/co_ai/prompts/connectonion/debug/exceptions.md +307 -0
  59. connectonion/cli/co_ai/prompts/connectonion/debug/log.md +117 -0
  60. connectonion/cli/co_ai/prompts/connectonion/debug/xray.md +215 -0
  61. connectonion/cli/co_ai/prompts/connectonion/design-decisions/001-choosing-input-method.md +202 -0
  62. connectonion/cli/co_ai/prompts/connectonion/design-decisions/002-choosing-llm-function-name.md +202 -0
  63. connectonion/cli/co_ai/prompts/connectonion/design-decisions/003-choosing-trust-keyword.md +141 -0
  64. connectonion/cli/co_ai/prompts/connectonion/design-decisions/004-cli-create-flow.md +117 -0
  65. connectonion/cli/co_ai/prompts/connectonion/design-decisions/005-designing-agent-network-protocol.md +503 -0
  66. connectonion/cli/co_ai/prompts/connectonion/design-decisions/006-agent-address-format.md +305 -0
  67. connectonion/cli/co_ai/prompts/connectonion/design-decisions/007-authentication-backend-design.md +240 -0
  68. connectonion/cli/co_ai/prompts/connectonion/design-decisions/008-naming-is-hard.md +228 -0
  69. connectonion/cli/co_ai/prompts/connectonion/design-decisions/009-why-connect-function.md +167 -0
  70. connectonion/cli/co_ai/prompts/connectonion/design-decisions/010-cli-ux-progressive-disclosure.md +176 -0
  71. connectonion/cli/co_ai/prompts/connectonion/design-decisions/011-global-config-identity-management.md +357 -0
  72. connectonion/cli/co_ai/prompts/connectonion/design-decisions/012-tool-execution-separation.md +259 -0
  73. connectonion/cli/co_ai/prompts/connectonion/design-decisions/013-debug-and-logging-design.md +253 -0
  74. connectonion/cli/co_ai/prompts/connectonion/design-decisions/014-hook-system-design.md +510 -0
  75. connectonion/cli/co_ai/prompts/connectonion/design-decisions/015-interactive-auto-debug-design.md +837 -0
  76. connectonion/cli/co_ai/prompts/connectonion/design-decisions/016-why-no-zero-knowledge-proofs.md +358 -0
  77. connectonion/cli/co_ai/prompts/connectonion/design-decisions/017-session-logging-and-eval-format.md +120 -0
  78. connectonion/cli/co_ai/prompts/connectonion/design-decisions/018-event-api-naming.md +274 -0
  79. connectonion/cli/co_ai/prompts/connectonion/design-decisions/019-agent-lifecycle-design.md +655 -0
  80. connectonion/cli/co_ai/prompts/connectonion/design-decisions/020-trust-system-and-network-architecture.md +503 -0
  81. connectonion/cli/co_ai/prompts/connectonion/design-decisions/021-task-storage-jsonl-design.md +496 -0
  82. connectonion/cli/co_ai/prompts/connectonion/design-decisions/022-raw-asgi-implementation.md +273 -0
  83. connectonion/cli/co_ai/prompts/connectonion/examples/agent_reasoning.md +62 -0
  84. connectonion/cli/co_ai/prompts/connectonion/examples/atomic_tools.md +24 -0
  85. connectonion/cli/co_ai/prompts/connectonion/examples/load_guide.md +18 -0
  86. connectonion/cli/co_ai/prompts/connectonion/examples.md +0 -0
  87. connectonion/cli/co_ai/prompts/connectonion/hook-system-options.md +364 -0
  88. connectonion/cli/co_ai/prompts/connectonion/index.md +162 -0
  89. connectonion/cli/co_ai/prompts/connectonion/integrations/README.md +12 -0
  90. connectonion/cli/co_ai/prompts/connectonion/integrations/auth.md +450 -0
  91. connectonion/cli/co_ai/prompts/connectonion/integrations/google.md +431 -0
  92. connectonion/cli/co_ai/prompts/connectonion/integrations/microsoft.md +370 -0
  93. connectonion/cli/co_ai/prompts/connectonion/network/README.md +14 -0
  94. connectonion/cli/co_ai/prompts/connectonion/network/connect.md +543 -0
  95. connectonion/cli/co_ai/prompts/connectonion/network/connection.md +538 -0
  96. connectonion/cli/co_ai/prompts/connectonion/network/deploy.md +123 -0
  97. connectonion/cli/co_ai/prompts/connectonion/network/host.md +1049 -0
  98. connectonion/cli/co_ai/prompts/connectonion/network/protocol/agent-relay-protocol.md +495 -0
  99. connectonion/cli/co_ai/prompts/connectonion/network/protocol/announce-message.md +115 -0
  100. connectonion/cli/co_ai/prompts/connectonion/principles.md +124 -0
  101. connectonion/cli/co_ai/prompts/connectonion/quickstart.md +261 -0
  102. connectonion/cli/co_ai/prompts/connectonion/roadmap.md +81 -0
  103. connectonion/cli/co_ai/prompts/connectonion/templates/README.md +77 -0
  104. connectonion/cli/co_ai/prompts/connectonion/templates/meta-agent.md +152 -0
  105. connectonion/cli/co_ai/prompts/connectonion/templates/minimal.md +105 -0
  106. connectonion/cli/co_ai/prompts/connectonion/templates/playwright.md +130 -0
  107. connectonion/cli/co_ai/prompts/connectonion/templates/web-research.md +144 -0
  108. connectonion/cli/co_ai/prompts/connectonion/tui/README.md +95 -0
  109. connectonion/cli/co_ai/prompts/connectonion/tui/chat.md +181 -0
  110. connectonion/cli/co_ai/prompts/connectonion/tui/divider.md +63 -0
  111. connectonion/cli/co_ai/prompts/connectonion/tui/dropdown.md +83 -0
  112. connectonion/cli/co_ai/prompts/connectonion/tui/footer.md +44 -0
  113. connectonion/cli/co_ai/prompts/connectonion/tui/fuzzy.md +68 -0
  114. connectonion/cli/co_ai/prompts/connectonion/tui/input.md +84 -0
  115. connectonion/cli/co_ai/prompts/connectonion/tui/keys.md +77 -0
  116. connectonion/cli/co_ai/prompts/connectonion/tui/pick.md +71 -0
  117. connectonion/cli/co_ai/prompts/connectonion/tui/providers.md +89 -0
  118. connectonion/cli/co_ai/prompts/connectonion/tui/status_bar.md +67 -0
  119. connectonion/cli/co_ai/prompts/connectonion/useful_plugins/README.md +156 -0
  120. connectonion/cli/co_ai/prompts/connectonion/useful_plugins/calendar_plugin.md +68 -0
  121. connectonion/cli/co_ai/prompts/connectonion/useful_plugins/eval.md +89 -0
  122. connectonion/cli/co_ai/prompts/connectonion/useful_plugins/gmail_plugin.md +68 -0
  123. connectonion/cli/co_ai/prompts/connectonion/useful_plugins/image_result_formatter.md +74 -0
  124. connectonion/cli/co_ai/prompts/connectonion/useful_plugins/re_act.md +86 -0
  125. connectonion/cli/co_ai/prompts/connectonion/useful_plugins/shell_approval.md +69 -0
  126. connectonion/cli/co_ai/prompts/connectonion/useful_tools/README.md +81 -0
  127. connectonion/cli/co_ai/prompts/connectonion/useful_tools/diff_writer.md +138 -0
  128. connectonion/cli/co_ai/prompts/connectonion/useful_tools/get_emails.md +499 -0
  129. connectonion/cli/co_ai/prompts/connectonion/useful_tools/gmail.md +135 -0
  130. connectonion/cli/co_ai/prompts/connectonion/useful_tools/google_calendar.md +106 -0
  131. connectonion/cli/co_ai/prompts/connectonion/useful_tools/memory.md +486 -0
  132. connectonion/cli/co_ai/prompts/connectonion/useful_tools/microsoft_calendar.md +106 -0
  133. connectonion/cli/co_ai/prompts/connectonion/useful_tools/outlook.md +120 -0
  134. connectonion/cli/co_ai/prompts/connectonion/useful_tools/send_email.md +403 -0
  135. connectonion/cli/co_ai/prompts/connectonion/useful_tools/shell.md +95 -0
  136. connectonion/cli/co_ai/prompts/connectonion/useful_tools/slash_command.md +96 -0
  137. connectonion/cli/co_ai/prompts/connectonion/useful_tools/terminal.md +97 -0
  138. connectonion/cli/co_ai/prompts/connectonion/useful_tools/todo_list.md +252 -0
  139. connectonion/cli/co_ai/prompts/connectonion/useful_tools/web_fetch.md +130 -0
  140. connectonion/cli/co_ai/prompts/connectonion/vibe-coding-guide.md +97 -0
  141. connectonion/cli/co_ai/prompts/connectonion/windows-support.md +258 -0
  142. connectonion/cli/co_ai/prompts/main.md +247 -0
  143. connectonion/cli/co_ai/prompts/reminders/plan_mode.md +34 -0
  144. connectonion/cli/co_ai/prompts/summarization.md +55 -0
  145. connectonion/cli/co_ai/prompts/tools/ask_user.md +61 -0
  146. connectonion/cli/co_ai/prompts/tools/background.md +57 -0
  147. connectonion/cli/co_ai/prompts/tools/edit.md +90 -0
  148. connectonion/cli/co_ai/prompts/tools/glob.md +52 -0
  149. connectonion/cli/co_ai/prompts/tools/grep.md +55 -0
  150. connectonion/cli/co_ai/prompts/tools/plan_mode.md +80 -0
  151. connectonion/cli/co_ai/prompts/tools/read.md +40 -0
  152. connectonion/cli/co_ai/prompts/tools/shell.md +67 -0
  153. connectonion/cli/co_ai/prompts/tools/task.md +51 -0
  154. connectonion/cli/co_ai/prompts/tools/todo.md +139 -0
  155. connectonion/cli/co_ai/prompts/tools/write.md +47 -0
  156. connectonion/cli/co_ai/prompts/workflow.md +89 -0
  157. connectonion/cli/co_ai/reminders.py +159 -0
  158. connectonion/cli/co_ai/sessions.py +110 -0
  159. connectonion/cli/co_ai/skills/__init__.py +37 -0
  160. connectonion/cli/co_ai/skills/builtin/commit/SKILL.md +63 -0
  161. connectonion/cli/co_ai/skills/builtin/review-pr/SKILL.md +76 -0
  162. connectonion/cli/co_ai/skills/loader.py +166 -0
  163. connectonion/cli/co_ai/skills/tool.py +46 -0
  164. connectonion/cli/co_ai/tools/__init__.py +92 -0
  165. connectonion/cli/co_ai/tools/ask_user.py +35 -0
  166. connectonion/cli/co_ai/tools/background.py +201 -0
  167. connectonion/cli/co_ai/tools/diff_writer.py +291 -0
  168. connectonion/cli/co_ai/tools/edit.py +89 -0
  169. connectonion/cli/co_ai/tools/glob.py +84 -0
  170. connectonion/cli/co_ai/tools/grep.py +158 -0
  171. connectonion/cli/co_ai/tools/load_guide.py +23 -0
  172. connectonion/cli/co_ai/tools/multi_edit.py +116 -0
  173. connectonion/cli/co_ai/tools/plan_mode.py +172 -0
  174. connectonion/cli/co_ai/tools/read.py +67 -0
  175. connectonion/cli/co_ai/tools/task.py +59 -0
  176. connectonion/cli/co_ai/tools/todo_list.py +159 -0
  177. connectonion/cli/co_ai/tools/write.py +126 -0
  178. connectonion/cli/commands/__init__.py +11 -1
  179. connectonion/cli/commands/ai_commands.py +34 -0
  180. connectonion/cli/commands/copy_commands.py +55 -6
  181. connectonion/cli/commands/create.py +20 -17
  182. connectonion/cli/commands/init.py +19 -22
  183. connectonion/cli/commands/project_cmd_lib.py +15 -0
  184. connectonion/cli/main.py +11 -0
  185. connectonion/console.py +15 -1
  186. connectonion/core/__init__.py +10 -1
  187. connectonion/core/agent.py +37 -16
  188. connectonion/core/exceptions.py +74 -0
  189. connectonion/core/llm.py +54 -6
  190. connectonion/core/tool_executor.py +32 -31
  191. connectonion/core/tool_factory.py +47 -10
  192. connectonion/debug/__init__.py +10 -1
  193. connectonion/debug/debug_explainer/__init__.py +10 -1
  194. connectonion/debug/execution_analyzer/__init__.py +10 -1
  195. connectonion/debug/execution_analyzer/execution_analysis.py +5 -2
  196. connectonion/debug/runtime_inspector/__init__.py +10 -1
  197. connectonion/docs/.package-ignore +6 -0
  198. connectonion/docs/README.md +2036 -0
  199. connectonion/docs/api.md +457 -0
  200. connectonion/docs/archive/001-ai-agent-is-just-prompt-plus-function.md +249 -0
  201. connectonion/docs/archive/README.md +53 -0
  202. connectonion/docs/archive/archive/consolidation-plan.md +72 -0
  203. connectonion/docs/archive/archive/core-principles-extracted.md +239 -0
  204. connectonion/docs/archive/archive/master-principles.md +222 -0
  205. connectonion/docs/archive/archive/principles.md +293 -0
  206. connectonion/docs/archive/archive/simplicity-principles.md +221 -0
  207. connectonion/docs/archive/attack-defense-insights.md +410 -0
  208. connectonion/docs/archive/business-model.md +305 -0
  209. connectonion/docs/archive/core-principles-unified.md +190 -0
  210. connectonion/docs/archive/discussion-journey.md +178 -0
  211. connectonion/docs/archive/economic-analysis.md +323 -0
  212. connectonion/docs/archive/features/01-share-and-find.md +256 -0
  213. connectonion/docs/archive/features/02-agent-authentication.md +93 -0
  214. connectonion/docs/archive/features/03-test-before-trust.md +71 -0
  215. connectonion/docs/archive/features/06-reliability-and-offline.md +197 -0
  216. connectonion/docs/archive/features/README.md +46 -0
  217. connectonion/docs/archive/features-roadmap.md +247 -0
  218. connectonion/docs/archive/mcp-comparison-insights.md +215 -0
  219. connectonion/docs/archive/migration-strategy.md +571 -0
  220. connectonion/docs/archive/mini-whitepaper.md +293 -0
  221. connectonion/docs/archive/network-protocol.md +394 -0
  222. connectonion/docs/archive/semantic-revolution.md +367 -0
  223. connectonion/docs/archive/technical-architecture.md +453 -0
  224. connectonion/docs/archive/the-semantic-insight.md +207 -0
  225. connectonion/docs/archive/threat-model.md +164 -0
  226. connectonion/docs/cli/README.md +805 -0
  227. connectonion/docs/cli/auth.md +46 -0
  228. connectonion/docs/cli/browser.md +235 -0
  229. connectonion/docs/cli/copy.md +232 -0
  230. connectonion/docs/cli/create.md +335 -0
  231. connectonion/docs/cli/init.md +431 -0
  232. connectonion/docs/co-directory-structure.md +214 -0
  233. connectonion/docs/concepts/agent.md +1078 -0
  234. connectonion/docs/concepts/events.md +699 -0
  235. connectonion/docs/concepts/llm_do.md +256 -0
  236. connectonion/docs/concepts/max_iterations.md +362 -0
  237. connectonion/docs/concepts/models.md +641 -0
  238. connectonion/docs/concepts/plugins.md +100 -0
  239. connectonion/docs/concepts/prompts.md +122 -0
  240. connectonion/docs/concepts/session.md +428 -0
  241. connectonion/docs/concepts/tools.md +512 -0
  242. connectonion/docs/concepts/transcribe.md +156 -0
  243. connectonion/docs/concepts/trust.md +291 -0
  244. connectonion/docs/connectonion.md +1256 -0
  245. connectonion/docs/debug/README.md +18 -0
  246. connectonion/docs/debug/auto_debug.md +1026 -0
  247. connectonion/docs/debug/console.md +129 -0
  248. connectonion/docs/debug/eval-format.md +178 -0
  249. connectonion/docs/debug/eval.md +230 -0
  250. connectonion/docs/debug/exceptions.md +307 -0
  251. connectonion/docs/debug/log.md +117 -0
  252. connectonion/docs/debug/xray.md +215 -0
  253. connectonion/docs/design-decisions/001-choosing-input-method.md +202 -0
  254. connectonion/docs/design-decisions/002-choosing-llm-function-name.md +202 -0
  255. connectonion/docs/design-decisions/003-choosing-trust-keyword.md +141 -0
  256. connectonion/docs/design-decisions/004-cli-create-flow.md +117 -0
  257. connectonion/docs/design-decisions/005-designing-agent-network-protocol.md +503 -0
  258. connectonion/docs/design-decisions/006-agent-address-format.md +305 -0
  259. connectonion/docs/design-decisions/007-authentication-backend-design.md +240 -0
  260. connectonion/docs/design-decisions/008-naming-is-hard.md +228 -0
  261. connectonion/docs/design-decisions/009-why-connect-function.md +167 -0
  262. connectonion/docs/design-decisions/010-cli-ux-progressive-disclosure.md +176 -0
  263. connectonion/docs/design-decisions/011-global-config-identity-management.md +357 -0
  264. connectonion/docs/design-decisions/012-tool-execution-separation.md +259 -0
  265. connectonion/docs/design-decisions/013-debug-and-logging-design.md +253 -0
  266. connectonion/docs/design-decisions/014-hook-system-design.md +510 -0
  267. connectonion/docs/design-decisions/015-interactive-auto-debug-design.md +837 -0
  268. connectonion/docs/design-decisions/016-why-no-zero-knowledge-proofs.md +358 -0
  269. connectonion/docs/design-decisions/017-session-logging-and-eval-format.md +120 -0
  270. connectonion/docs/design-decisions/018-event-api-naming.md +274 -0
  271. connectonion/docs/design-decisions/019-agent-lifecycle-design.md +655 -0
  272. connectonion/docs/design-decisions/020-trust-system-and-network-architecture.md +503 -0
  273. connectonion/docs/design-decisions/021-task-storage-jsonl-design.md +496 -0
  274. connectonion/docs/design-decisions/022-raw-asgi-implementation.md +273 -0
  275. connectonion/docs/examples.md +0 -0
  276. connectonion/docs/hook-system-options.md +364 -0
  277. connectonion/docs/integrations/README.md +12 -0
  278. connectonion/docs/integrations/auth.md +450 -0
  279. connectonion/docs/integrations/google.md +431 -0
  280. connectonion/docs/integrations/microsoft.md +370 -0
  281. connectonion/docs/network/README.md +14 -0
  282. connectonion/docs/network/connect.md +629 -0
  283. connectonion/docs/network/deploy.md +124 -0
  284. connectonion/docs/network/host.md +1087 -0
  285. connectonion/docs/network/io.md +538 -0
  286. connectonion/docs/network/protocol/agent-relay-protocol.md +495 -0
  287. connectonion/docs/network/protocol/announce-message.md +115 -0
  288. connectonion/docs/principles.md +124 -0
  289. connectonion/docs/quickstart.md +261 -0
  290. connectonion/docs/roadmap.md +81 -0
  291. connectonion/docs/templates/README.md +77 -0
  292. connectonion/docs/templates/meta-agent.md +152 -0
  293. connectonion/docs/templates/minimal.md +105 -0
  294. connectonion/docs/templates/playwright.md +130 -0
  295. connectonion/docs/templates/web-research.md +144 -0
  296. connectonion/docs/tui/README.md +95 -0
  297. connectonion/docs/tui/chat.md +181 -0
  298. connectonion/docs/tui/divider.md +63 -0
  299. connectonion/docs/tui/dropdown.md +83 -0
  300. connectonion/docs/tui/footer.md +44 -0
  301. connectonion/docs/tui/fuzzy.md +68 -0
  302. connectonion/docs/tui/input.md +84 -0
  303. connectonion/docs/tui/keys.md +77 -0
  304. connectonion/docs/tui/pick.md +71 -0
  305. connectonion/docs/tui/providers.md +89 -0
  306. connectonion/docs/tui/status_bar.md +67 -0
  307. connectonion/docs/useful_plugins/README.md +160 -0
  308. connectonion/docs/useful_plugins/calendar_plugin.md +68 -0
  309. connectonion/docs/useful_plugins/eval.md +89 -0
  310. connectonion/docs/useful_plugins/gmail_plugin.md +68 -0
  311. connectonion/docs/useful_plugins/image_result_formatter.md +74 -0
  312. connectonion/docs/useful_plugins/re_act.md +86 -0
  313. connectonion/docs/useful_plugins/shell_approval.md +69 -0
  314. connectonion/docs/useful_plugins/system_reminder.md +210 -0
  315. connectonion/docs/useful_prompts/README.md +127 -0
  316. connectonion/docs/useful_prompts/coding_agent.md +214 -0
  317. connectonion/docs/useful_tools/README.md +81 -0
  318. connectonion/docs/useful_tools/ask_user.md +103 -0
  319. connectonion/docs/useful_tools/diff_writer.md +158 -0
  320. connectonion/docs/useful_tools/get_emails.md +519 -0
  321. connectonion/docs/useful_tools/gmail.md +155 -0
  322. connectonion/docs/useful_tools/google_calendar.md +126 -0
  323. connectonion/docs/useful_tools/memory.md +506 -0
  324. connectonion/docs/useful_tools/microsoft_calendar.md +126 -0
  325. connectonion/docs/useful_tools/outlook.md +140 -0
  326. connectonion/docs/useful_tools/send_email.md +423 -0
  327. connectonion/docs/useful_tools/shell.md +115 -0
  328. connectonion/docs/useful_tools/slash_command.md +116 -0
  329. connectonion/docs/useful_tools/terminal.md +115 -0
  330. connectonion/docs/useful_tools/todo_list.md +272 -0
  331. connectonion/docs/useful_tools/web_fetch.md +150 -0
  332. connectonion/docs/vibe-coding-guide.md +97 -0
  333. connectonion/docs/windows-support.md +258 -0
  334. connectonion/logger.py +3 -3
  335. connectonion/network/__init__.py +19 -6
  336. connectonion/network/asgi/__init__.py +81 -0
  337. connectonion/network/asgi/http.py +205 -0
  338. connectonion/network/asgi/websocket.py +217 -0
  339. connectonion/network/connect.py +232 -185
  340. connectonion/network/host/__init__.py +59 -0
  341. connectonion/network/host/auth.py +191 -0
  342. connectonion/network/host/routes.py +135 -0
  343. connectonion/network/host/server.py +289 -0
  344. connectonion/network/host/session.py +78 -0
  345. connectonion/network/io/__init__.py +21 -0
  346. connectonion/network/{connection.py → io/base.py} +17 -42
  347. connectonion/network/io/websocket.py +55 -0
  348. connectonion/network/relay.py +37 -16
  349. connectonion/network/trust/__init__.py +30 -0
  350. connectonion/network/trust/factory.py +138 -0
  351. connectonion/network/{trust_agents.py → trust/prompts.py} +3 -3
  352. connectonion/network/{trust_functions.py → trust/tools.py} +2 -2
  353. connectonion/prompt_files/__init__.py +11 -1
  354. connectonion/prompt_files/react_acknowledge.md +26 -0
  355. connectonion/prompts.py +10 -1
  356. connectonion/tui/chat.py +10 -1
  357. connectonion/tui/divider.py +10 -1
  358. connectonion/tui/dropdown.py +10 -1
  359. connectonion/tui/footer.py +8 -0
  360. connectonion/tui/fuzzy.py +11 -1
  361. connectonion/tui/input.py +118 -70
  362. connectonion/tui/keys.py +133 -6
  363. connectonion/tui/providers.py +11 -1
  364. connectonion/tui/status_bar.py +10 -1
  365. connectonion/useful_events_handlers/__init__.py +8 -0
  366. connectonion/useful_events_handlers/reflect.py +19 -4
  367. connectonion/useful_plugins/__init__.py +2 -1
  368. connectonion/useful_plugins/eval.py +2 -2
  369. connectonion/useful_plugins/gmail_plugin.py +3 -3
  370. connectonion/useful_plugins/image_result_formatter.py +3 -3
  371. connectonion/useful_plugins/re_act.py +114 -28
  372. connectonion/useful_plugins/shell_approval.py +2 -2
  373. connectonion/useful_plugins/system_reminder.py +103 -0
  374. connectonion/useful_plugins/ui_stream.py +18 -133
  375. connectonion/useful_prompts/README.md +61 -0
  376. connectonion/useful_prompts/__init__.py +45 -0
  377. connectonion/useful_prompts/coding_agent/README.md +106 -0
  378. connectonion/useful_prompts/coding_agent/assembler.py +123 -0
  379. connectonion/useful_prompts/coding_agent/prompts/main.md +227 -0
  380. connectonion/useful_prompts/coding_agent/prompts/tools/ask_user.md +61 -0
  381. connectonion/useful_prompts/coding_agent/prompts/tools/background.md +57 -0
  382. connectonion/useful_prompts/coding_agent/prompts/tools/edit.md +90 -0
  383. connectonion/useful_prompts/coding_agent/prompts/tools/glob.md +52 -0
  384. connectonion/useful_prompts/coding_agent/prompts/tools/grep.md +55 -0
  385. connectonion/useful_prompts/coding_agent/prompts/tools/plan_mode.md +80 -0
  386. connectonion/useful_prompts/coding_agent/prompts/tools/read.md +40 -0
  387. connectonion/useful_prompts/coding_agent/prompts/tools/shell.md +67 -0
  388. connectonion/useful_prompts/coding_agent/prompts/tools/task.md +51 -0
  389. connectonion/useful_prompts/coding_agent/prompts/tools/todo.md +139 -0
  390. connectonion/useful_prompts/coding_agent/prompts/tools/write.md +48 -0
  391. connectonion/useful_prompts/system-reminders/security-warning.md +14 -0
  392. connectonion/useful_prompts/system-reminders/test-reminder.md +11 -0
  393. connectonion/useful_tools/__init__.py +31 -4
  394. connectonion/useful_tools/ask_user.py +35 -0
  395. connectonion/useful_tools/bash.py +69 -0
  396. connectonion/useful_tools/diff_writer.py +186 -94
  397. connectonion/useful_tools/edit.py +102 -0
  398. connectonion/useful_tools/glob_files.py +97 -0
  399. connectonion/useful_tools/grep_files.py +171 -0
  400. connectonion/useful_tools/multi_edit.py +116 -0
  401. connectonion/useful_tools/read_file.py +73 -0
  402. connectonion/useful_tools/shell.py +50 -45
  403. connectonion/useful_tools/write_file.py +129 -0
  404. {connectonion-0.6.1.dist-info → connectonion-0.6.3.dist-info}/METADATA +10 -3
  405. connectonion-0.6.3.dist-info/RECORD +469 -0
  406. connectonion/cli/browser_agent/scroll_strategies.py +0 -276
  407. connectonion/network/asgi.py +0 -407
  408. connectonion/network/host.py +0 -616
  409. connectonion/network/trust.py +0 -166
  410. connectonion-0.6.1.dist-info/RECORD +0 -123
  411. /connectonion/cli/{docs → co_ai/prompts/connectonion}/connectonion.md +0 -0
  412. {connectonion-0.6.1.dist-info → connectonion-0.6.3.dist-info}/WHEEL +0 -0
  413. {connectonion-0.6.1.dist-info → connectonion-0.6.3.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,1078 @@
1
+ # Agent
2
+
3
+ > The heart of ConnectOnion. Give it tools, and it figures out the rest.
4
+
5
+ ---
6
+
7
+ ## Quick Start (60 Seconds)
8
+
9
+ ```python
10
+ from connectonion import Agent
11
+
12
+ # Define what your agent can do
13
+ def calculate(expression: str) -> str:
14
+ """Do math calculations."""
15
+ return str(eval(expression))
16
+
17
+ # Create agent
18
+ agent = Agent("math_bot", tools=[calculate])
19
+
20
+ # Use it
21
+ result = agent.input("What is 42 * 17?")
22
+ ```
23
+
24
+ **Output:**
25
+ ```
26
+ To calculate 42 * 17, I'll use the calculator tool.
27
+ The result is 714.
28
+ ```
29
+
30
+ **That's it.** Your first AI agent in 5 lines.
31
+
32
+ ---
33
+
34
+ ## What Agent Can Do - Full API Overview
35
+
36
+ After that simple example, here's **everything** an Agent can do:
37
+
38
+ ### Creating an Agent
39
+
40
+ ```python
41
+ Agent(
42
+ name="my_bot", # Required: agent identifier
43
+ tools=[func1, func2], # Optional: functions agent can call
44
+ system_prompt="You are helpful", # Optional: personality/behavior
45
+ model="co/gemini-2.5-pro", # Optional: LLM model (default: co/gemini-2.5-pro)
46
+ max_iterations=10, # Optional: how many tool calls allowed
47
+ api_key="sk-...", # Optional: override environment variable
48
+ llm=custom_llm, # Optional: bring your own LLM instance
49
+ trust="tested", # Optional: security verification
50
+ quiet=False, # Optional: suppress console output
51
+ log=True # Optional: logging configuration
52
+ )
53
+ ```
54
+
55
+ ### Using Your Agent
56
+
57
+ ```python
58
+ # Give it a task
59
+ result = agent.input("Do something")
60
+
61
+ # Override iterations for complex tasks
62
+ result = agent.input("Complex task", max_iterations=20)
63
+
64
+ # Execute a tool directly (for testing)
65
+ result = agent.execute_tool("tool_name", {"arg": "value"})
66
+ ```
67
+
68
+ ### Managing Tools
69
+
70
+ ```python
71
+ # Add tools after creation
72
+ agent.add_tool(new_function)
73
+
74
+ # Remove tools
75
+ agent.remove_tool("function_name")
76
+
77
+ # See what tools are available
78
+ tools = agent.list_tools()
79
+ ```
80
+
81
+ ### Conversations & State
82
+
83
+ ```python
84
+ # Multi-turn conversations work automatically
85
+ agent.input("What is 10 + 5?") # Turn 1: "15"
86
+ agent.input("Multiply that by 2") # Turn 2: "30" (remembers context)
87
+
88
+ # Start fresh
89
+ agent.reset_conversation()
90
+
91
+ # Access internal state (advanced)
92
+ session = agent.current_session # Messages, trace, turn count
93
+ ```
94
+
95
+ ### Attributes You Can Access
96
+
97
+ ```python
98
+ agent.name # str: Agent identifier
99
+ agent.tools # ToolRegistry: All available tools
100
+ agent.tools.names() # list[str]: Tool names
101
+ agent.tools.get("name") # Tool: Get tool by name
102
+ agent.tools.tool_name # Tool: Attribute access to tools
103
+ agent.system_prompt # str: Agent's personality
104
+ agent.max_iterations # int: Default iteration limit
105
+ agent.current_session # dict | None: Runtime state
106
+
107
+ # Token usage tracking
108
+ agent.last_usage # TokenUsage | None: From last LLM call
109
+ agent.total_cost # float: Cumulative cost in USD
110
+ agent.context_percent # float: Context window usage (0-100%)
111
+ ```
112
+
113
+ **That's the complete API.** Now let's dive into each feature.
114
+
115
+ ---
116
+
117
+ ## Table of Contents
118
+
119
+ 1. [Creating Agents](#creating-agents)
120
+ 2. [Using Your Agent](#using-your-agent)
121
+ 3. [Managing Tools](#managing-tools)
122
+ 4. [Conversations & Multi-Turn](#conversations--multi-turn)
123
+ 5. [Iteration Control](#iteration-control)
124
+ 6. [Models & LLMs](#models--llms)
125
+ 7. [Token Usage & Cost Tracking](#token-usage--cost-tracking)
126
+ 8. [Logging & Debugging](#logging--debugging)
127
+ 9. [Trust & Security](#trust--security)
128
+ 10. [Common Patterns](#common-patterns)
129
+ 11. [Testing Your Agents](#testing-your-agents)
130
+ 12. [Architecture & Internals](#architecture--internals)
131
+
132
+ ---
133
+
134
+ ## Creating Agents
135
+
136
+ ### Minimal Agent
137
+
138
+ ```python
139
+ agent = Agent("my_bot") # Just conversation, no tools
140
+ ```
141
+
142
+ ### Agent with Tools
143
+
144
+ ```python
145
+ def search(query: str) -> str:
146
+ """Search for information."""
147
+ return f"Found results for '{query}'"
148
+
149
+ def get_time() -> str:
150
+ """Get current time."""
151
+ from datetime import datetime
152
+ return datetime.now().strftime("%H:%M:%S")
153
+
154
+ agent = Agent(
155
+ "assistant",
156
+ tools=[search, get_time]
157
+ )
158
+ ```
159
+
160
+ ### Agent with Personality
161
+
162
+ ```python
163
+ agent = Agent(
164
+ "expert",
165
+ tools=[search],
166
+ system_prompt="You are a thorough researcher. Always cite sources."
167
+ )
168
+ ```
169
+
170
+ ### Load Prompt from File
171
+
172
+ ```python
173
+ # Automatically detects if it's a file path
174
+ agent = Agent(
175
+ "bot",
176
+ system_prompt="prompts/assistant.md" # Loads from file
177
+ )
178
+
179
+ # Or use Path object
180
+ from pathlib import Path
181
+ agent = Agent(
182
+ "bot",
183
+ system_prompt=Path("prompts/expert.txt")
184
+ )
185
+ ```
186
+
187
+ **System prompt rules:**
188
+ - Can be a direct string
189
+ - Can be a file path (auto-detected if file exists)
190
+ - Can be a Path object
191
+ - Defaults to "You are a helpful assistant that can use tools to complete tasks."
192
+
193
+ ---
194
+
195
+ ## Using Your Agent
196
+
197
+ ### Basic Usage
198
+
199
+ ```python
200
+ agent = Agent("helper", tools=[search, calculate])
201
+
202
+ # Give it a task
203
+ result = agent.input("Search for Python docs and calculate 2+2")
204
+ ```
205
+
206
+ ### Console Output
207
+
208
+ When you run `agent.input()`, you'll see:
209
+
210
+ ```
211
+ INPUT: Search for Python docs and calculate 2+2
212
+
213
+ Iteration 1/10
214
+ → LLM Request (gpt-4o-mini)
215
+ ← LLM Response (234ms): 2 tool calls
216
+ → Tool: search({"query": "Python docs"})
217
+ ← Result (1ms): Found results for 'Python docs'
218
+ → Tool: calculate({"expression": "2+2"})
219
+ ← Result (0ms): 4
220
+
221
+ Iteration 2/10
222
+ → LLM Request (gpt-4o-mini)
223
+ ← LLM Response (189ms)
224
+
225
+ ✓ Complete (0.4s)
226
+ ```
227
+
228
+ ### How It Works
229
+
230
+ ```
231
+ User Input
232
+
233
+ LLM Decision (should I use a tool?)
234
+
235
+ Tool Execution (if needed)
236
+
237
+ LLM sees results → Repeat
238
+
239
+ Final Response (when LLM is done)
240
+ ```
241
+
242
+ The agent loops until:
243
+ - LLM provides a final answer (no more tool calls), OR
244
+ - Max iterations reached (default: 10)
245
+
246
+ ---
247
+
248
+ ## Managing Tools
249
+
250
+ ### Add Tools Dynamically
251
+
252
+ ```python
253
+ agent = Agent("bot") # No tools initially
254
+
255
+ def new_feature(x: str) -> str:
256
+ """Process something."""
257
+ return f"Processed {x}"
258
+
259
+ agent.add_tool(new_feature) # Now agent can use it
260
+ ```
261
+
262
+ ### Remove Tools
263
+
264
+ ```python
265
+ removed = agent.remove_tool("calculator")
266
+ # Returns True if found and removed, False otherwise
267
+ ```
268
+
269
+ ### List Available Tools
270
+
271
+ ```python
272
+ tools = agent.list_tools()
273
+ # ['search', 'calculate', 'get_time']
274
+ ```
275
+
276
+ ### Execute Tool Directly
277
+
278
+ Useful for testing and debugging:
279
+
280
+ ```python
281
+ result = agent.execute_tool("calculator", {"expression": "2+2"})
282
+
283
+ # Returns:
284
+ {
285
+ "name": "calculator",
286
+ "arguments": {"expression": "2+2"},
287
+ "result": "4",
288
+ "status": "success", # or "error", "not_found"
289
+ "timing": 1.23 # milliseconds
290
+ }
291
+ ```
292
+
293
+ ### Stateful Tools (Class Instances)
294
+
295
+ You can pass a class instance as tools, and the agent will extract all public methods:
296
+
297
+ ```python
298
+ class Browser:
299
+ def __init__(self):
300
+ self.page = None
301
+
302
+ def start(self) -> str:
303
+ """Start browser."""
304
+ from playwright.sync_api import sync_playwright
305
+ self.playwright = sync_playwright().start()
306
+ self.page = self.playwright.chromium.launch().new_page()
307
+ return "Browser started"
308
+
309
+ def navigate(self, url: str) -> str:
310
+ """Navigate to URL."""
311
+ self.page.goto(url)
312
+ return f"Navigated to {url}"
313
+
314
+ def screenshot(self, filename: str) -> str:
315
+ """Take screenshot."""
316
+ self.page.screenshot(path=filename)
317
+ return f"Saved {filename}"
318
+
319
+ # Browser state persists across tool calls!
320
+ browser = Browser()
321
+ agent = Agent("web_bot", tools=browser, max_iterations=20)
322
+
323
+ agent.input("Go to wikipedia.org and take a screenshot")
324
+ # Agent calls: start() → navigate() → screenshot()
325
+ # All share the same browser instance
326
+ ```
327
+
328
+ See [tools.md](tools.md) for complete tool guide.
329
+
330
+ ---
331
+
332
+ ## Conversations & Multi-Turn
333
+
334
+ ### Automatic Context
335
+
336
+ Agents remember conversation history by default:
337
+
338
+ ```python
339
+ agent = Agent("bot", tools=[calculator])
340
+
341
+ # Turn 1
342
+ response1 = agent.input("What is 10 + 5?")
343
+ # "The result is 15"
344
+
345
+ # Turn 2 - agent remembers "15" from previous turn
346
+ response2 = agent.input("Multiply that by 2")
347
+ # "The result is 30"
348
+ ```
349
+
350
+ ### Reset Conversation
351
+
352
+ ```python
353
+ agent.reset_conversation()
354
+ # Next input starts fresh, no memory of previous turns
355
+ ```
356
+
357
+ ### Session State (Advanced)
358
+
359
+ Each conversation creates a session:
360
+
361
+ ```python
362
+ agent.input("Hello")
363
+
364
+ # Inspect the session
365
+ session = agent.current_session
366
+ {
367
+ 'messages': [
368
+ {'role': 'system', 'content': 'You are...'},
369
+ {'role': 'user', 'content': 'Hello'},
370
+ {'role': 'assistant', 'content': 'Hi!'},
371
+ ],
372
+ 'trace': [
373
+ {'type': 'user_input', 'prompt': 'Hello', 'timestamp': ...},
374
+ {'type': 'llm_call', 'model': 'gpt-4o-mini', 'duration_ms': 234},
375
+ {'type': 'tool_execution', 'tool_name': 'search', 'result': '...'},
376
+ ],
377
+ 'turn': 1, # Number of user inputs
378
+ 'iteration': 1, # Current iteration within this turn
379
+ 'user_prompt': 'Hello' # Latest user input
380
+ }
381
+ ```
382
+
383
+ **Trace types:**
384
+ - `user_input` - User provided input
385
+ - `llm_call` - LLM API request/response
386
+ - `tool_execution` - Tool call and result
387
+
388
+ ---
389
+
390
+ ## Iteration Control
391
+
392
+ Each tool call is one iteration. Control how many times an agent can call tools:
393
+
394
+ ### Set Default for Agent
395
+
396
+ ```python
397
+ # Simple tasks need fewer iterations
398
+ agent = Agent("calc", tools=[calculate], max_iterations=5)
399
+
400
+ # Complex workflows need more
401
+ agent = Agent("researcher", tools=[search, analyze], max_iterations=20)
402
+ ```
403
+
404
+ ### Override Per Task
405
+
406
+ ```python
407
+ agent = Agent("bot", tools=[...], max_iterations=10)
408
+
409
+ # Simple task uses default (10)
410
+ agent.input("What is 2+2?")
411
+
412
+ # Complex task needs more
413
+ agent.input(
414
+ "Research AI trends, analyze data, write report",
415
+ max_iterations=25 # Override just for this task
416
+ )
417
+ ```
418
+
419
+ ### Choosing the Right Limit
420
+
421
+ | Task Type | Recommended | Example |
422
+ |-----------|-------------|---------|
423
+ | Simple (1-2 tools) | **3-5** | "Calculate 2+2" |
424
+ | Standard | **8-10** | "Search and summarize" |
425
+ | Data analysis | **10-15** | "Load, process, visualize data" |
426
+ | Web automation | **15-25** | Browser workflows, scraping |
427
+ | Research | **20-30** | Multi-step analysis |
428
+ | Complex workflows | **30-50** | Full automation pipelines |
429
+
430
+ ### What Happens at Max Iterations
431
+
432
+ ```python
433
+ agent = Agent("bot", tools=[tool], max_iterations=3)
434
+
435
+ # If agent can't complete in 3 iterations:
436
+ result = agent.input("Impossible task")
437
+ # "Task incomplete: Maximum iterations (3) reached."
438
+ ```
439
+
440
+ **Rule of thumb:** Start low, increase if you see "Maximum iterations reached" messages.
441
+
442
+ See [max_iterations.md](max_iterations.md) for detailed guide.
443
+
444
+ ---
445
+
446
+ ## Models & LLMs
447
+
448
+ ### Supported Providers
449
+
450
+ Default model is `co/gemini-2.5-pro`. You can use:
451
+
452
+ ```python
453
+ # OpenAI models
454
+ agent = Agent("bot", model="gpt-4o-mini")
455
+ agent = Agent("bot", model="gpt-4o")
456
+ agent = Agent("bot", model="o1-mini")
457
+ agent = Agent("bot", model="o1")
458
+
459
+ # Anthropic Claude
460
+ agent = Agent("bot", model="claude-3-5-sonnet-20241022")
461
+ agent = Agent("bot", model="claude-3-5-haiku-20241022")
462
+ agent = Agent("bot", model="claude-opus-4")
463
+
464
+ # Google Gemini
465
+ agent = Agent("bot", model="gemini-1.5-pro")
466
+ agent = Agent("bot", model="gemini-1.5-flash")
467
+ agent = Agent("bot", model="gemini-2.0-flash-exp")
468
+ ```
469
+
470
+ ### Managed Keys (After `co auth`)
471
+
472
+ ```python
473
+ # Use managed keys instead of your own
474
+ agent = Agent("bot", model="co/gpt-4o-mini")
475
+ agent = Agent("bot", model="co/claude-3-5-sonnet")
476
+ ```
477
+
478
+ ### API Keys
479
+
480
+ ```python
481
+ # From environment (recommended)
482
+ export OPENAI_API_KEY=sk-...
483
+ export ANTHROPIC_API_KEY=sk-ant-...
484
+ export GOOGLE_API_KEY=...
485
+
486
+ # Or pass directly
487
+ agent = Agent("bot", api_key="sk-...", model="gpt-4o-mini")
488
+ ```
489
+
490
+ ### Custom LLM Instance (Advanced)
491
+
492
+ ```python
493
+ from connectonion.llm import AnthropicLLM
494
+
495
+ custom_llm = AnthropicLLM(
496
+ model="claude-3-5-sonnet-20241022",
497
+ api_key="sk-ant-..."
498
+ )
499
+
500
+ agent = Agent("bot", llm=custom_llm)
501
+ ```
502
+
503
+ See [models.md](models.md) for complete model list and details.
504
+
505
+ ---
506
+
507
+ ## Token Usage & Cost Tracking
508
+
509
+ Track token consumption and API costs across LLM calls.
510
+
511
+ ### Basic Usage
512
+
513
+ ```python
514
+ agent = Agent("assistant", tools=[search])
515
+ result = agent.input("Search for Python tutorials")
516
+
517
+ # Check usage after any LLM call
518
+ print(f"Last call used {agent.last_usage.input_tokens} input tokens")
519
+ print(f"Total cost so far: ${agent.total_cost:.4f}")
520
+ print(f"Context window used: {agent.context_percent:.1f}%")
521
+ ```
522
+
523
+ ### TokenUsage Object
524
+
525
+ After each LLM call, `agent.last_usage` contains:
526
+
527
+ ```python
528
+ from connectonion.usage import TokenUsage
529
+
530
+ # TokenUsage fields:
531
+ agent.last_usage.input_tokens # Total input tokens
532
+ agent.last_usage.output_tokens # Output/completion tokens
533
+ agent.last_usage.cached_tokens # Tokens from cache (cheaper)
534
+ agent.last_usage.cache_write_tokens # Tokens written to cache (Anthropic)
535
+ agent.last_usage.cost # Cost for this call in USD
536
+ ```
537
+
538
+ ### Multi-Turn Cost Tracking
539
+
540
+ ```python
541
+ agent = Agent("chat", tools=[calculator])
542
+
543
+ agent.input("What is 10 + 5?")
544
+ print(f"After turn 1: ${agent.total_cost:.4f}")
545
+
546
+ agent.input("Multiply that by 2")
547
+ print(f"After turn 2: ${agent.total_cost:.4f}")
548
+
549
+ agent.input("Now divide by 3")
550
+ print(f"Total spent: ${agent.total_cost:.4f}")
551
+ ```
552
+
553
+ ### Context Window Monitoring
554
+
555
+ Monitor how much context you're using to avoid hitting limits:
556
+
557
+ ```python
558
+ agent = Agent("researcher", tools=[search, analyze])
559
+
560
+ for topic in topics:
561
+ result = agent.input(f"Research {topic}")
562
+
563
+ # Warn if context is getting full
564
+ if agent.context_percent > 80:
565
+ print(f"Warning: {agent.context_percent:.0f}% context used")
566
+ agent.reset_conversation() # Start fresh
567
+ ```
568
+
569
+ ### Cache Pricing
570
+
571
+ Different providers handle caching differently:
572
+
573
+ | Provider | Cache Read | Cache Write |
574
+ |----------|-----------|-------------|
575
+ | OpenAI | 50% of input price | N/A |
576
+ | Anthropic | 10% of input price | 125% of input price |
577
+ | Google Gemini | 25% of input price | N/A |
578
+
579
+ Cached tokens save money on repeated context (e.g., system prompts, previous messages).
580
+
581
+ ### Console Output
582
+
583
+ Token usage is automatically shown in console logs after each LLM call:
584
+
585
+ ```
586
+ → LLM Request (gpt-4o-mini) • 5 msgs • 2 tools
587
+ ← LLM Response (0.8s) • 1,234 in • 156 out • $0.0003
588
+ ```
589
+
590
+ ### Supported Models
591
+
592
+ Cost tracking works with all supported providers:
593
+ - OpenAI (gpt-4o, gpt-4o-mini, o1, o3-mini, o4-mini)
594
+ - Anthropic Claude (claude-3-5-sonnet, claude-3-5-haiku, claude-opus-4)
595
+ - Google Gemini (gemini-2.5-pro, gemini-2.5-flash, gemini-1.5-pro)
596
+
597
+ Unknown models use default pricing estimates.
598
+
599
+ ---
600
+
601
+ ## Logging & Debugging
602
+
603
+ ### Automatic Logging
604
+
605
+ All agent activity is automatically logged to three places:
606
+
607
+ **1. Console (default on, use `quiet=True` to suppress):**
608
+ ```
609
+ INPUT: What is 2+2?
610
+ Iteration 1/10
611
+ → LLM Request (gpt-4o-mini)
612
+ ← LLM Response (234ms): 1 tool calls
613
+ → Tool: calculator({"expression": "2+2"})
614
+ ← Result (1ms): 4
615
+ ✓ Complete (0.4s)
616
+ ```
617
+
618
+ **2. Plain text logs (`.co/logs/{name}.log`):**
619
+ ```
620
+ ============================================================
621
+ Session started: 2024-12-02 10:32:14
622
+ ============================================================
623
+
624
+ [10:32:14] INPUT: What is 2+2?
625
+ [10:32:14] -> LLM Request (gpt-4o-mini) • 2 msgs • 1 tools
626
+ [10:32:15] <- LLM Response (234ms) • 1 tools • 156 tokens • $0.0001
627
+ [10:32:15] -> Tool: calculator({"expression": "2+2"})
628
+ [10:32:15] <- Result (1ms): 4
629
+ [10:32:15] [OK] Complete (0.4s)
630
+ ```
631
+
632
+ **3. Session YAML (`.co/evals/{name}_{timestamp}.yaml`):**
633
+ ```yaml
634
+ name: bot
635
+ timestamp: 2024-12-02 10:32:14
636
+
637
+ turns:
638
+ - input: "What is 2+2?"
639
+ model: "gpt-4o-mini"
640
+ duration_ms: 400
641
+ tokens: 156
642
+ cost: 0.0001
643
+ tools_called: [calculator]
644
+ result: "The answer is 4"
645
+ messages: '[{"role":"system",...}]'
646
+ ```
647
+
648
+ ### Logging Parameters
649
+
650
+ ```python
651
+ # Default: everything on (console + logs + sessions)
652
+ agent = Agent("bot")
653
+
654
+ # Quiet mode: suppress console, keep sessions for eval
655
+ agent = Agent("bot", quiet=True)
656
+
657
+ # Disable all file logging (console only)
658
+ agent = Agent("bot", log=False)
659
+
660
+ # Custom log path
661
+ agent = Agent("bot", log="logs/my-agent.log")
662
+ ```
663
+
664
+ ### Logging Modes Summary
665
+
666
+ | quiet | log | Console | Plain Text | Sessions | Use Case |
667
+ |-------|-----|---------|------------|----------|----------|
668
+ | False | True/None | ✓ | ✓ | ✓ | Development (default) |
669
+ | True | True/None | ✗ | ✗ | ✓ | Eval/testing |
670
+ | False | False | ✓ | ✗ | ✗ | Benchmarking |
671
+ | False | "path" | ✓ | custom | ✓ | Custom log path |
672
+
673
+ ### Environment Override
674
+
675
+ ```bash
676
+ # Override log file via environment (highest priority)
677
+ CONNECTONION_LOG=debug.log python agent.py
678
+ ```
679
+
680
+ ### Session Use Cases
681
+
682
+ - **Session replay**: Restore context from saved sessions
683
+ - **Regression testing**: Compare expected vs actual results
684
+ - **Development comparison**: See what changed after prompt edits
685
+
686
+ ### Debug with @xray
687
+
688
+ See what your agent is thinking inside tool execution:
689
+
690
+ ```python
691
+ from connectonion.decorators import xray
692
+
693
+ @xray
694
+ def search(query: str) -> str:
695
+ """Search for information."""
696
+
697
+ # Access agent context!
698
+ print(f"User asked: {xray.task}")
699
+ print(f"Iteration: {xray.iteration}")
700
+ print(f"Previous tools: {xray.previous_tools}")
701
+
702
+ return f"Results for {query}"
703
+
704
+ agent = Agent("bot", tools=[search])
705
+ agent.input("Find Python docs")
706
+
707
+ # Automatically prints Rich table with full context
708
+ ```
709
+
710
+ The `@xray` decorator provides:
711
+ - `xray.agent` - The Agent instance
712
+ - `xray.task` - Original user request
713
+ - `xray.messages` - Full conversation history
714
+ - `xray.iteration` - Current iteration number
715
+ - `xray.previous_tools` - Tools called before this one
716
+
717
+ See [xray.md](../debug/xray.md) for complete debugging guide and [console.md](../debug/console.md) for more options.
718
+
719
+ ---
720
+
721
+ ## Trust & Security
722
+
723
+ Add verification before risky tools execute:
724
+
725
+ ### Trust Levels
726
+
727
+ ```python
728
+ agent = Agent(
729
+ "bot",
730
+ tools=[delete_database],
731
+ trust="tested" # Requires manual approval before execution
732
+ )
733
+ ```
734
+
735
+ **Trust levels:**
736
+ - `"open"` - No verification (default)
737
+ - `"tested"` - Manual approval required
738
+ - `"strict"` - Both manual approval + verification logic
739
+
740
+ ### Trust Policies (Natural Language)
741
+
742
+ ```python
743
+ agent = Agent(
744
+ "bot",
745
+ tools=[deploy_code],
746
+ trust="policies/production.md" # Checks against policy file
747
+ )
748
+ ```
749
+
750
+ ### Custom Trust Agent
751
+
752
+ ```python
753
+ # Create a verifier agent
754
+ verifier = Agent("security", tools=[scan_code, check_safety])
755
+
756
+ # Use it to verify tools
757
+ agent = Agent(
758
+ "bot",
759
+ tools=[risky_tool],
760
+ trust=verifier # Custom verification logic
761
+ )
762
+ ```
763
+
764
+ See [trust.md](trust.md) for complete security guide.
765
+
766
+ ---
767
+
768
+ ## Common Patterns
769
+
770
+ ### Quick One-Off Task
771
+
772
+ ```python
773
+ def quick_task(prompt: str, tools: list) -> str:
774
+ """Execute a one-off task without conversation state."""
775
+ agent = Agent("temp", tools=tools, log=False)
776
+ return agent.input(prompt)
777
+
778
+ result = quick_task("Search for Python", [search])
779
+ ```
780
+
781
+ ### Stateful Chatbot
782
+
783
+ ```python
784
+ class ChatBot:
785
+ def __init__(self):
786
+ self.agent = Agent(
787
+ "chatbot",
788
+ tools=[search, calculate],
789
+ system_prompt="You are friendly and helpful"
790
+ )
791
+
792
+ def chat(self, message: str) -> str:
793
+ return self.agent.input(message)
794
+
795
+ def reset(self):
796
+ self.agent.reset_conversation()
797
+
798
+ bot = ChatBot()
799
+ bot.chat("Hello!")
800
+ bot.chat("What's 2+2?") # Remembers context
801
+ bot.reset() # Fresh start
802
+ ```
803
+
804
+ ### Agent Factory
805
+
806
+ ```python
807
+ def create_analyst(name: str, tools: list) -> Agent:
808
+ """Create analysts with shared configuration."""
809
+ return Agent(
810
+ name=name,
811
+ tools=tools,
812
+ system_prompt=Path("prompts/analyst.md"),
813
+ model="claude-3-5-sonnet-20241022",
814
+ max_iterations=15,
815
+ log=f"logs/{name}.log"
816
+ )
817
+
818
+ sales_agent = create_analyst("sales", [sql_query, chart])
819
+ finance_agent = create_analyst("finance", [sql_query, forecast])
820
+ ```
821
+
822
+ ### Multi-Agent Workflow
823
+
824
+ ```python
825
+ # Create specialized agents
826
+ researcher = Agent("researcher", tools=[search, scrape])
827
+ writer = Agent("writer", tools=[format_text, save_file])
828
+ reviewer = Agent("reviewer", tools=[check_grammar, fact_check])
829
+
830
+ # Orchestrate workflow
831
+ def content_pipeline(topic: str):
832
+ research = researcher.input(f"Research {topic}")
833
+ draft = writer.input(f"Write article: {research}")
834
+ final = reviewer.input(f"Review and improve: {draft}")
835
+ return final
836
+
837
+ result = content_pipeline("AI trends 2025")
838
+ ```
839
+
840
+ ### Browser Automation
841
+
842
+ ```python
843
+ class Browser:
844
+ """Stateful browser automation."""
845
+ def __init__(self):
846
+ self.page = None
847
+
848
+ def start(self) -> str:
849
+ """Start browser."""
850
+ # Browser initialization
851
+ return "Browser started"
852
+
853
+ def navigate(self, url: str) -> str:
854
+ """Navigate to URL."""
855
+ self.page.goto(url)
856
+ return f"Navigated to {url}"
857
+
858
+ def screenshot(self, filename: str) -> str:
859
+ """Take screenshot."""
860
+ self.page.screenshot(path=filename)
861
+ return f"Saved {filename}"
862
+
863
+ browser = Browser()
864
+ agent = Agent(
865
+ "web_bot",
866
+ tools=browser,
867
+ max_iterations=20 # Browser automation needs more iterations
868
+ )
869
+
870
+ agent.input("Go to wikipedia.org, search for 'Python', take screenshot")
871
+ ```
872
+
873
+ ---
874
+
875
+ ## Testing Your Agents
876
+
877
+ ### Mock the LLM
878
+
879
+ ```python
880
+ from unittest.mock import Mock
881
+ from connectonion import Agent
882
+ from connectonion.llm import LLMResponse
883
+
884
+ def test_agent():
885
+ agent = Agent("test", tools=[calculate])
886
+
887
+ # Mock LLM response
888
+ agent.llm.complete = Mock(return_value=LLMResponse(
889
+ content="The answer is 4",
890
+ tool_calls=[],
891
+ raw_response=None
892
+ ))
893
+
894
+ result = agent.input("What is 2+2?")
895
+ assert result == "The answer is 4"
896
+ ```
897
+
898
+ ### Test Tool Execution
899
+
900
+ ```python
901
+ def test_tool_execution():
902
+ agent = Agent("test", tools=[calculator])
903
+
904
+ result = agent.execute_tool("calculator", {"expression": "2+2"})
905
+
906
+ assert result["status"] == "success"
907
+ assert result["result"] == "4"
908
+ ```
909
+
910
+ ### Integration Tests
911
+
912
+ ```python
913
+ import pytest
914
+
915
+ @pytest.mark.real_api
916
+ def test_real_agent():
917
+ """Requires OPENAI_API_KEY in environment."""
918
+ agent = Agent("test", tools=[search], model="gpt-4o-mini")
919
+ result = agent.input("Search for Python")
920
+ assert "Python" in result
921
+
922
+ # Run tests:
923
+ # pytest -m "not real_api" # Skip real API tests
924
+ # pytest -m real_api # Only integration tests
925
+ ```
926
+
927
+ ---
928
+
929
+ ## Architecture & Internals
930
+
931
+ ### How Agent Works Internally
932
+
933
+ ```
934
+ agent.input("prompt")
935
+
936
+ 1. Initialize/Continue Session
937
+ - First call: Create new session
938
+ - Subsequent: Continue existing session
939
+
940
+ 2. Add User Message to History
941
+
942
+ 3. Iteration Loop (up to max_iterations):
943
+ ├─ Call LLM with tools and messages
944
+ ├─ If no tool calls → Return final response
945
+ ├─ Execute all tool calls in sequence
946
+ ├─ Add tool results to messages
947
+ └─ Repeat
948
+
949
+ 4. Return Final Response or "Maximum iterations reached"
950
+ ```
951
+
952
+ ### File References
953
+
954
+ If you want to explore the source code:
955
+
956
+ - **Agent core**: `connectonion/agent.py:32` (Agent class definition)
957
+ - **Tool execution**: `connectonion/tool_executor.py:24` (Tool execution logic)
958
+ - **LLM interface**: `connectonion/llm.py:41` (LLM abstraction)
959
+ - **Tool factory**: `connectonion/tool_factory.py:26` (Function → Tool conversion)
960
+ - **Console**: `connectonion/console.py:15` (Logging)
961
+
962
+ ### Error Handling Philosophy
963
+
964
+ Tool errors are **returned to the LLM** as messages, allowing it to retry or adapt:
965
+
966
+ ```python
967
+ def risky_tool(data: str) -> str:
968
+ if not data:
969
+ raise ValueError("data required")
970
+ return f"Processed {data}"
971
+
972
+ agent = Agent("bot", tools=[risky_tool])
973
+
974
+ # If tool fails:
975
+ # 1. Error captured
976
+ # 2. Error message sent to LLM
977
+ # 3. LLM can retry with different arguments or choose different approach
978
+ agent.input("Use risky_tool")
979
+ ```
980
+
981
+ This makes agents resilient to errors.
982
+
983
+ ### Session State Structure
984
+
985
+ ```python
986
+ {
987
+ 'messages': [
988
+ {'role': 'system', 'content': '...'},
989
+ {'role': 'user', 'content': '...'},
990
+ {'role': 'assistant', 'content': '...', 'tool_calls': [...]},
991
+ {'role': 'tool', 'content': '...', 'tool_call_id': '...'},
992
+ ],
993
+ 'trace': [
994
+ {
995
+ 'type': 'user_input',
996
+ 'prompt': '...',
997
+ 'timestamp': 1234567890.123,
998
+ 'turn': 1
999
+ },
1000
+ {
1001
+ 'type': 'llm_call',
1002
+ 'model': 'gpt-4o-mini',
1003
+ 'duration_ms': 234,
1004
+ 'tool_calls_count': 2,
1005
+ 'iteration': 1
1006
+ },
1007
+ {
1008
+ 'type': 'tool_execution',
1009
+ 'tool_name': 'search',
1010
+ 'arguments': {'query': '...'},
1011
+ 'result': '...',
1012
+ 'status': 'success',
1013
+ 'timing': 1.23,
1014
+ 'iteration': 1
1015
+ }
1016
+ ],
1017
+ 'turn': 1,
1018
+ 'iteration': 1,
1019
+ 'user_prompt': '...'
1020
+ }
1021
+ ```
1022
+
1023
+ ---
1024
+
1025
+ ## Learn More
1026
+
1027
+ ### Essential Documentation
1028
+ - **[quickstart.md](../quickstart.md)** - Installation and first steps
1029
+ - **[tools.md](tools.md)** - How to create powerful tools
1030
+ - **[models.md](models.md)** - All supported LLM providers
1031
+
1032
+ ### Advanced Features
1033
+ - **[xray.md](../debug/xray.md)** - Debug and inspect agent behavior
1034
+ - **[trust.md](trust.md)** - Security and tool verification
1035
+ - **[max_iterations.md](max_iterations.md)** - Detailed iteration control
1036
+ - **[log.md](../debug/log.md)** - Logging configuration
1037
+ - **[console.md](../debug/console.md)** - Console output and debugging
1038
+
1039
+ ### Examples
1040
+ - **[examples.md](../examples.md)** - Real-world code examples
1041
+ - **[api.md](../api.md)** - Complete API reference
1042
+
1043
+ ---
1044
+
1045
+ ## Philosophy
1046
+
1047
+ **"Keep simple things simple, make complicated things possible"**
1048
+
1049
+ ### Simple Case
1050
+ ```python
1051
+ agent = Agent("bot", tools=[search])
1052
+ agent.input("Find Python docs")
1053
+ ```
1054
+
1055
+ ### Complex Case
1056
+ ```python
1057
+ trust_agent = Agent("verifier", tools=[scan_code])
1058
+
1059
+ agent = Agent(
1060
+ name="production",
1061
+ llm=custom_llm,
1062
+ tools=[deploy, rollback, monitor],
1063
+ system_prompt=Path("prompts/ops.md"),
1064
+ max_iterations=30,
1065
+ trust=trust_agent,
1066
+ log="/var/log/agents/production.log"
1067
+ )
1068
+
1069
+ result = agent.input("Deploy v2.0 to production", max_iterations=40)
1070
+ ```
1071
+
1072
+ **Both are valid.** Start simple, add complexity only when needed.
1073
+
1074
+ ---
1075
+
1076
+ **ConnectOnion: AI Agent = Prompt + Function**
1077
+
1078
+ That's it. That's the framework. Now go build something useful.