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,196 @@
1
+ """
2
+ Purpose: Development assistant agent with ConnectOnion documentation knowledge and shell execution
3
+ LLM-Note:
4
+ Dependencies: imports from [connectonion.Agent, connectonion.xray, connectonion.llm_do, json, pathlib, subprocess, platform, shutil] | template file copied by [cli/commands/init.py, cli/commands/create.py]
5
+ Data flow: user question → Agent.input() → answer_connectonion_question (reads .co/docs/connectonion.md → llm_do extracts relevant text → llm_do generates answer) | run_shell executes commands | todo tools manage todo.md
6
+ State/Effects: reads/writes todo.md | executes shell commands (cross-platform) | reads documentation files | uses co/gemini-2.5-pro model
7
+ Integration: template for 'co create --template meta-agent' | tools: answer_connectonion_question, think, add_todo, delete_todo, list_todos, run_shell | uses external prompt files in prompts/
8
+ Performance: llm_do calls for doc retrieval and answers | shell timeout 120s | max_iterations=15
9
+ Errors: graceful handling for missing docs | shell command timeout/errors caught | @xray decorator for debugging
10
+
11
+ Meta-Agent - Your ConnectOnion development assistant with documentation expertise
12
+ """
13
+
14
+ from connectonion import Agent, xray
15
+ from connectonion import llm_do
16
+ import json
17
+ from pathlib import Path
18
+ import subprocess
19
+ import platform
20
+ import shutil
21
+
22
+ @xray
23
+ def extract_relevant_connectonion_text(question: str, docs_path: str = ".co/docs/connectonion.md") -> str:
24
+ """Load docs and use llm_do to extract relevant text for the question."""
25
+ try:
26
+ with open(docs_path, 'r', encoding='utf-8') as f:
27
+ docs = f.read()
28
+ except FileNotFoundError:
29
+ return "ConnectOnion documentation not found. Try running 'co init' again."
30
+ # Use llm_do with a retrieval prompt file to select relevant content
31
+ return llm_do(
32
+ input=f"Question: {question}\n\nDocumentation:\n{docs}",
33
+ system_prompt="prompts/docs_retrieve_prompt.md",
34
+ model="co/gpt-4o",
35
+ temperature=0.1,
36
+ )
37
+
38
+
39
+ @xray
40
+ def answer_connectonion_question(question: str) -> str:
41
+ """Answer a question using relevant text extracted from documentation via llm_do."""
42
+ relevant = extract_relevant_connectonion_text(question)
43
+ return llm_do(
44
+ input=f"Question: {question}\n\nRelevant context:\n{relevant}",
45
+ system_prompt="prompts/answer_prompt.md",
46
+ model="co/gpt-4o",
47
+ temperature=0.1,
48
+ )
49
+
50
+
51
+
52
+ @xray
53
+ def think(context: str = "current situation") -> str:
54
+ """Reflect using llm_do on a simple JSON dump of xray.messages."""
55
+ transcript = json.dumps(xray.messages or [])
56
+ return llm_do(
57
+ input=f"Context: {context}\n\nMessages: {transcript}",
58
+ system_prompt="prompts/think_prompt.md",
59
+ model="co/gpt-4o",
60
+ temperature=0.1,
61
+ )
62
+
63
+
64
+
65
+ def add_todo(task: str) -> str:
66
+ """Add a to-do item to todo.md as an unchecked task."""
67
+ if not task or not task.strip():
68
+ return "Please provide a non-empty task."
69
+ path = Path(__file__).resolve().parent / "todo.md"
70
+ if not path.exists():
71
+ path.write_text("", encoding="utf-8")
72
+ with path.open("a", encoding="utf-8") as f:
73
+ f.write(f"- [ ] {task.strip()}\n")
74
+ return f"Added to-do: {task.strip()}"
75
+
76
+
77
+ def delete_todo(task: str) -> str:
78
+ """Delete the first matching to-do (checked or unchecked) from todo.md."""
79
+ path = Path(__file__).resolve().parent / "todo.md"
80
+ if not path.exists():
81
+ path.write_text("", encoding="utf-8")
82
+ lines = path.read_text(encoding="utf-8").splitlines()
83
+ new_lines = []
84
+ removed = False
85
+ for line in lines:
86
+ if (line.startswith("- [ ] ") or line.startswith("- [x] ")) and task in line and not removed:
87
+ removed = True
88
+ continue
89
+ new_lines.append(line)
90
+ if not removed:
91
+ return "To-do not found."
92
+ path.write_text("\n".join(new_lines) + "\n", encoding="utf-8")
93
+ return f"Deleted to-do: {task}"
94
+
95
+
96
+ def list_todos() -> str:
97
+ """Return the current contents of todo.md or a notice if empty."""
98
+ path = Path(__file__).resolve().parent / "todo.md"
99
+ if not path.exists():
100
+ path.write_text("", encoding="utf-8")
101
+ content = path.read_text(encoding="utf-8")
102
+ lines = [ln for ln in content.splitlines() if ln.strip()]
103
+ if len(lines) == 0:
104
+ return "No to-dos yet. Use add_todo(task) to add one."
105
+ return content
106
+
107
+
108
+ @xray
109
+ def run_shell(command: str, timeout: int = 120, cwd: str = "") -> str:
110
+ """Execute a shell command cross-platform and return output.
111
+
112
+ Works on macOS/Linux and Windows. Uses bash/sh when available on *nix,
113
+ and PowerShell (or cmd) on Windows.
114
+ """
115
+ cmd = command.strip()
116
+ if not cmd:
117
+ return "No command provided."
118
+ system = platform.system()
119
+ if system == "Windows":
120
+ if shutil.which("powershell"):
121
+ argv = ["powershell", "-NoProfile", "-NonInteractive", "-Command", cmd]
122
+ else:
123
+ argv = ["cmd", "/c", cmd]
124
+ else:
125
+ if shutil.which("bash"):
126
+ argv = ["bash", "-lc", cmd]
127
+ else:
128
+ argv = ["sh", "-lc", cmd]
129
+ try:
130
+ proc = subprocess.run(
131
+ argv,
132
+ capture_output=True,
133
+ text=True,
134
+ cwd=cwd or None,
135
+ timeout=timeout
136
+ )
137
+ stdout = proc.stdout or ""
138
+ stderr = proc.stderr or ""
139
+ return (
140
+ f"exit_code: {proc.returncode}\n"
141
+ f"stdout:\n{stdout}\n"
142
+ f"stderr:\n{stderr}".rstrip()
143
+ )
144
+ except subprocess.TimeoutExpired as e:
145
+ return f"Command timed out after {timeout}s. Partial output:\nstdout:\n{e.stdout or ''}\nstderr:\n{e.stderr or ''}"
146
+ except Exception as e:
147
+ return f"Error executing command: {e}"
148
+
149
+
150
+
151
+
152
+
153
+ # Create the meta-agent with comprehensive ConnectOnion knowledge
154
+ agent = Agent(
155
+ name="meta_agent",
156
+ system_prompt="prompts/metagent.md",
157
+ tools=[
158
+ answer_connectonion_question, # Primary documentation tool
159
+ think, # Self-reflection
160
+ add_todo,
161
+ delete_todo,
162
+ list_todos,
163
+ run_shell
164
+ ],
165
+ model="co/gemini-2.5-pro",
166
+ max_iterations=15 # More iterations for complex assistance
167
+ )
168
+
169
+
170
+ if __name__ == "__main__":
171
+ print("🤖 ConnectOnion Meta-Agent initialized!")
172
+ print("Your AI assistant for ConnectOnion development\n")
173
+ print("Available capabilities:")
174
+ print("📚 Documentation expert - Ask any question about ConnectOnion")
175
+ print("🔧 Code generation - Create agents, tools, and tests")
176
+ print("📝 Task planning - Break down complex projects")
177
+ print("🏗️ Project structure - Get architecture recommendations")
178
+ print("\nTry: 'How do tools work in ConnectOnion?'")
179
+ print(" 'Create a web scraper agent'")
180
+ print(" 'Generate a tool for sending emails'")
181
+
182
+ # Interactive loop
183
+ print("\nType 'exit' or 'quit' to end the conversation.")
184
+ while True:
185
+ try:
186
+ user_input = input("\nYou: ").strip()
187
+ except (EOFError, KeyboardInterrupt):
188
+ print("\nGoodbye!")
189
+ break
190
+ if user_input.lower() in {"exit", "quit"}:
191
+ print("Goodbye!")
192
+ break
193
+ if not user_input:
194
+ continue
195
+ assistant_reply = agent.input(user_input)
196
+ print(f"\nAssistant: {assistant_reply}")
@@ -0,0 +1,9 @@
1
+ # Answer Prompt
2
+
3
+ You are a precise assistant. Answer the user's question using ONLY the provided relevant context.
4
+
5
+ Rules:
6
+ - If the context contains the answer, respond concisely and accurately.
7
+ - If the answer is unclear or missing in the context, say: "I don't see that in the provided context."
8
+ - Do not invent details not supported by the context.
9
+ - When helpful, quote short snippets from the context.
@@ -0,0 +1,15 @@
1
+ # Documentation Retrieval Prompt
2
+
3
+ You are a helpful assistant that extracts only the most relevant parts of the provided documentation for answering the user's question.
4
+
5
+ Input:
6
+ - Question
7
+ - Full documentation text
8
+
9
+ Task:
10
+ - Return a concise excerpt (≤ 400 words) containing the most relevant paragraphs, bullet lists, or code blocks needed to answer the question.
11
+ - Preserve headings and formatting when useful.
12
+ - Do not invent content. If nothing is relevant, say: "No directly relevant content found."
13
+
14
+ Output:
15
+ - Only the extracted text (no explanations, no extra commentary).
@@ -0,0 +1,71 @@
1
+ # ConnectOnion Meta-Agent
2
+
3
+ You are the ConnectOnion Meta-Agent, an expert AI assistant specialized in helping developers build agents with the ConnectOnion framework. You have deep knowledge of the framework's documentation and can generate code, answer questions, and guide users through development.
4
+
5
+ ## Primary Role
6
+
7
+ Your main job is to help users understand and use ConnectOnion effectively by:
8
+ 1. **Answering documentation questions** using the embedded docs in `.co/docs/connectonion.md`
9
+ 2. **Generating agent code** from templates
10
+ 3. **Creating tool functions** with proper signatures
11
+ 4. **Writing tests** for agents
12
+ 5. **Planning complex projects** with structured to-do lists
13
+ 6. **Suggesting project structures** for different use cases
14
+
15
+ ## Core Capabilities
16
+
17
+ ### 📚 Documentation Expert (answer_connectonion_question)
18
+ - Primary source of truth about ConnectOnion
19
+ - Search through embedded documentation
20
+ - Provide accurate, context-aware answers
21
+ - Reference specific sections when relevant
22
+
23
+ ### 🔧 Code Generation
24
+ - **create_agent_from_template**: Generate complete agent implementations
25
+ - **generate_tool_code**: Create properly formatted tool functions
26
+ - **create_test_for_agent**: Generate pytest-compatible test suites
27
+
28
+ ### 🧠 Meta-Cognitive Tools
29
+ - **think**: Reflect on task completion and next steps
30
+ - **generate_todo_list**: Break down complex tasks (uses GPT-4o-mini)
31
+
32
+ ### 🏗️ Architecture Guidance
33
+ - **suggest_project_structure**: Recommend project organization
34
+ - Support for single-agent, multi-agent, tool libraries, and API projects
35
+
36
+ ## Behavioral Guidelines
37
+
38
+ 1. **Documentation First**: Always check the embedded docs before answering ConnectOnion questions
39
+ 2. **Code Quality**: Generate clean, well-documented, working code
40
+ 3. **Best Practices**: Follow ConnectOnion conventions (markdown prompts, type hints, docstrings)
41
+ 4. **Be Helpful**: Provide examples and explanations, not just answers
42
+ 5. **Think Step-by-Step**: For complex requests, use the think tool to plan approach
43
+
44
+ ## Response Strategy
45
+
46
+ When users ask about ConnectOnion:
47
+ 1. Use `answer_connectonion_question` to search documentation
48
+ 2. Provide relevant code examples when applicable
49
+ 3. Suggest next steps or related topics
50
+
51
+ When users need code:
52
+ 1. Use appropriate generation tools
53
+ 2. Explain the generated code
54
+ 3. Mention customization options
55
+
56
+ When users have complex projects:
57
+ 1. Use `think` to analyze requirements
58
+ 2. Generate a to-do list with `generate_todo_list`
59
+ 3. Suggest project structure
60
+ 4. Offer to generate starter code
61
+
62
+ ## Example Interactions
63
+
64
+ - "How do tools work?" → Search docs, explain with examples
65
+ - "Create a web scraper agent" → Generate agent template with appropriate tools
66
+ - "I need to process CSV files" → Generate tool code for CSV processing
67
+ - "Help me structure a multi-agent system" → Suggest architecture, create to-do list
68
+
69
+ ## Remember
70
+
71
+ You are not just answering questions - you're actively helping developers build better agents with ConnectOnion. Be proactive in offering relevant tools, suggesting improvements, and sharing best practices from the documentation.
@@ -0,0 +1,18 @@
1
+ # Think Prompt
2
+
3
+ You are a concise, high-signal thinking assistant.
4
+
5
+ Input:
6
+ - A short context string
7
+ - A JSON-serialized list of conversation messages (OpenAI chat format)
8
+
9
+ Task:
10
+ - Return 3-5 short bullet points covering:
11
+ - What has been accomplished so far
12
+ - Current issues or blockers
13
+ - The single next best step
14
+
15
+ Constraints:
16
+ - Be brief, direct, and actionable
17
+ - Do not restate the transcript
18
+ - No preambles or closing remarks
@@ -0,0 +1,56 @@
1
+ # Minimal ConnectOnion Agent
2
+
3
+ The simplest way to get started with ConnectOnion. A basic calculator agent that demonstrates:
4
+ - Creating an agent with a simple tool
5
+ - Interactive conversations
6
+ - Using both `agent.input()` and `llm_do()` functions
7
+
8
+ ## Quick Start
9
+
10
+ ```bash
11
+ # Initialize project (if not already done)
12
+ co init --template minimal
13
+
14
+ # Run the agent
15
+ python agent.py
16
+ ```
17
+
18
+ ## What's Inside
19
+
20
+ **`agent.py`** - A minimal agent with:
21
+ - Simple calculator tool (add, subtract, multiply, divide)
22
+ - Interactive conversation loop
23
+ - Examples of both agent and direct LLM usage
24
+
25
+ ## Example Interaction
26
+
27
+ ```python
28
+ # The agent can use its calculator tool
29
+ agent.input("What is 25 * 4?")
30
+ # → The calculator will compute: 100
31
+
32
+ # Direct LLM call without tools
33
+ llm_do("What is ConnectOnion?")
34
+ # → Quick response without agent overhead
35
+ ```
36
+
37
+ ## Environment Variables
38
+
39
+ The `.env` file is created automatically during `co init`. It includes:
40
+
41
+ - `OPENONION_API_KEY` - Managed keys with `co/` prefix (recommended)
42
+ - Or `OPENAI_API_KEY` - Your own OpenAI API key
43
+
44
+ ## Next Steps
45
+
46
+ **Ready for more?** Try these templates:
47
+
48
+ - `co init --template playwright` - Browser automation with Playwright
49
+ - `co init --template web-research` - Web search and research tools
50
+ - `co init --template meta-agent` - Multi-agent orchestration
51
+
52
+ ## Learn More
53
+
54
+ - [Documentation](https://docs.connectonion.com)
55
+ - [Examples](https://github.com/openonion/connectonion/tree/main/examples)
56
+ - [Discord Community](https://discord.gg/4xfD9k8AUF)
@@ -0,0 +1,40 @@
1
+ """
2
+ Purpose: Minimal agent template demonstrating basic ConnectOnion usage with a calculator tool
3
+ LLM-Note:
4
+ Dependencies: imports from [connectonion.Agent] | template file copied by [cli/commands/init.py, cli/commands/create.py] | default template for 'co create' and 'co init'
5
+ Data flow: user query → Agent.input() → calculator tool called if math expression → eval() computes result → returns answer
6
+ State/Effects: no persistent state | single Agent.input() call | uses co/gemini-2.5-pro model (OpenOnion hosted)
7
+ Integration: template for 'co create --template minimal' | demonstrates function-as-tool pattern | shows system_prompt and model configuration
8
+ Performance: single LLM call | eval() is fast
9
+ Errors: ⚠️ Security: uses eval() - for demo only, not production safe
10
+
11
+ Minimal ConnectOnion agent with a simple calculator tool.
12
+ """
13
+
14
+ from connectonion import Agent
15
+
16
+
17
+ def calculator(expression: str) -> float:
18
+ """Simple calculator that evaluates arithmetic expressions.
19
+
20
+ Args:
21
+ expression: A mathematical expression (e.g., "5*5", "10+20")
22
+
23
+ Returns:
24
+ The result of the calculation
25
+ """
26
+ # Note: eval() is used for simplicity. For production, use a safer parser.
27
+ return eval(expression)
28
+
29
+
30
+ # Create agent with calculator tool
31
+ agent = Agent(
32
+ name="calculator-agent",
33
+ system_prompt="pls use the calculator tool to answer math questions", # you can also pass a markdown file like system_prompt="path/to/your_markdown_file.md"
34
+ tools=[calculator], # tools can be python classes or functions
35
+ model="co/gemini-2.5-pro" # co/gemini-2.5-pro is hosted by OpenOnion, you can use your own API key by setting OPENAI_API_KEY in .env
36
+ )
37
+
38
+ # Run the agent
39
+ result = agent.input("what is the result of 5*5")
40
+ print(result)
@@ -0,0 +1,118 @@
1
+ # Playwright Web Automation Agent
2
+
3
+ A powerful browser automation agent using Playwright. Demonstrates stateful browser control, web scraping, form filling, and interactive automation.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # 1. Initialize project
9
+ co init --template playwright
10
+
11
+ # 2. Install dependencies
12
+ pip install -r requirements.txt
13
+ playwright install chromium
14
+
15
+ # 3. Run the agent
16
+ python agent.py
17
+ ```
18
+
19
+ ## What's Inside
20
+
21
+ **Stateful Browser Tools:**
22
+ - `start_browser()` - Launch browser instance
23
+ - `navigate()` - Go to URLs with smart waiting
24
+ - `scrape_content()` - Extract text from pages
25
+ - `take_screenshot()` - Capture page screenshots
26
+ - `fill_form()` - Fill and submit forms
27
+ - `click()` - Click elements
28
+ - `extract_links()` - Get all links from page
29
+ - `execute_javascript()` - Run custom JS
30
+ - `get_page_info()` / `get_session_info()` - Check browser state
31
+ - `close_browser()` - Clean up resources
32
+
33
+ ## Interactive Mode
34
+
35
+ The agent supports interactive conversation for browser automation:
36
+
37
+ ```bash
38
+ You: Start the browser and go to example.com
39
+ Agent: [Starts browser and navigates]
40
+
41
+ You: Take a screenshot
42
+ Agent: [Captures screenshot]
43
+
44
+ You: Extract all links from the page
45
+ Agent: [Lists all links found]
46
+ ```
47
+
48
+ ## Example Usage
49
+
50
+ ```python
51
+ from connectonion import Agent
52
+
53
+ # The browser instance maintains state across tool calls
54
+ agent.input("Start the browser and navigate to example.com")
55
+ agent.input("Take a screenshot of the homepage")
56
+ agent.input("Extract all links that contain 'doc'")
57
+ agent.input("Close the browser")
58
+ ```
59
+
60
+ ## Key Features
61
+
62
+ ### Stateful Session
63
+ - Browser state persists across tool calls
64
+ - Navigate multiple pages in one session
65
+ - Maintain cookies and session data
66
+
67
+ ### Smart Automation
68
+ - Automatic waiting for page loads
69
+ - Error handling with helpful messages
70
+ - Screenshot and download tracking
71
+
72
+ ### Flexible Input
73
+ - Natural language commands
74
+ - JSON form data for complex inputs
75
+ - CSS selectors for precise targeting
76
+
77
+ ## Common Use Cases
78
+
79
+ **Web Scraping:**
80
+ ```python
81
+ agent.input("Go to news.ycombinator.com and extract the top 5 article titles")
82
+ ```
83
+
84
+ **Form Automation:**
85
+ ```python
86
+ agent.input("Navigate to the contact form and fill it with name 'John' and email 'john@example.com'")
87
+ ```
88
+
89
+ **Screenshot Documentation:**
90
+ ```python
91
+ agent.input("Take full-page screenshots of example.com, github.com, and python.org")
92
+ ```
93
+
94
+ **Link Extraction:**
95
+ ```python
96
+ agent.input("Go to docs.python.org and extract all tutorial links")
97
+ ```
98
+
99
+ ## Tips
100
+
101
+ - Always `start_browser()` before other operations
102
+ - Use `get_session_info()` to check browser state
103
+ - Call `close_browser()` when done to free resources
104
+ - Screenshots are saved in the current directory
105
+ - Use headless=False to see browser in action
106
+
107
+ ## Next Steps
108
+
109
+ **More Templates:**
110
+ - `co init --template minimal` - Simple calculator agent
111
+ - `co init --template web-research` - Web search tools
112
+ - `co init --template meta-agent` - Multi-agent orchestration
113
+
114
+ ## Learn More
115
+
116
+ - [Playwright Documentation](https://playwright.dev/python/)
117
+ - [ConnectOnion Docs](https://docs.connectonion.com)
118
+ - [Discord Community](https://discord.gg/4xfD9k8AUF)