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,263 @@
1
+ """
2
+ Purpose: Provide experimental debugging tools to understand and fix unwanted tool calls via prompt testing
3
+ LLM-Note:
4
+ Dependencies: imports from [typing, pathlib, pydantic, ../llm_do.py] | imported by [explain_agent.py] | no dedicated tests found
5
+ Data flow: explain_tool_choice() creates RuntimeContext(breakpoint_context, agent) → stores bp_ctx and agent state → methods test_system_prompt_variation(new_prompt), suggest_prompt_improvements(), verify_stability() call llm_do() with modified prompts → returns RootCauseAnalysis (Pydantic model with primary_cause_source, influential_text, explanation, is_correct_choice, suggested_fix)
6
+ State/Effects: stores breakpoint_context and agent_instance | no file I/O | calls llm_do() for LLM analysis (multiple LLM requests per method) | no global state
7
+ Integration: exposes RuntimeContext class, RootCauseAnalysis (Pydantic model) | used by explain_agent.py to provide experimental debugging | methods help developers understand why agent chose specific tool and how to fix unwanted choices via prompt engineering
8
+ Performance: each method makes 1+ LLM calls via llm_do() | no caching | synchronous execution
9
+ Errors: LLM call failures propagate from llm_do() | Pydantic validation errors if LLM returns invalid structure
10
+ """
11
+
12
+ from typing import Dict, List, Any
13
+ from pathlib import Path
14
+ from pydantic import BaseModel
15
+ from ..llm_do import llm_do
16
+
17
+
18
+ class RootCauseAnalysis(BaseModel):
19
+ """Structured output for root cause analysis."""
20
+ primary_cause_source: str # "system_prompt" | "user_message" | "tool_results" | "available_tools"
21
+ influential_text: str # The exact sentence/phrase that caused this
22
+ explanation: str # Why this text led to choosing this tool
23
+ is_correct_choice: bool # Is this the right tool for the task?
24
+ suggested_fix: str # How to prevent if unwanted (be specific)
25
+
26
+
27
+ class RuntimeContext:
28
+ """Experimental debugger for fixing unwanted tool calls.
29
+
30
+ Primary use case: "Agent called tool X but I didn't want it to - how do I fix this?"
31
+
32
+ All static context is already in the prompt. This class provides experiments to:
33
+ 1. Test different system prompts - would they prevent this call?
34
+ 2. Suggest prompt improvements - what changes would help?
35
+ 3. Verify stability - is the decision consistent?
36
+ """
37
+
38
+ def __init__(self, breakpoint_context, agent_instance):
39
+ """Initialize with breakpoint and agent runtime state.
40
+
41
+ Args:
42
+ breakpoint_context: BreakpointContext with execution data
43
+ agent_instance: The Agent instance being debugged
44
+ """
45
+ self.bp_ctx = breakpoint_context
46
+ self.agent = agent_instance
47
+
48
+ def test_with_different_system_prompt(self, new_system_prompt: str) -> str:
49
+ """Test if different system prompt would prevent this tool call.
50
+
51
+ Use case: "Would modifying the system prompt prevent calling this unwanted tool?"
52
+
53
+ Args:
54
+ new_system_prompt: Alternative system prompt to test
55
+
56
+ Returns:
57
+ What the agent would do with the modified prompt
58
+ """
59
+ # Get messages up to the decision point
60
+ temp_messages = self.agent.current_session['messages'].copy()
61
+
62
+ # Remove the assistant message that made this tool call
63
+ if temp_messages and temp_messages[-1].get('role') == 'assistant':
64
+ temp_messages = temp_messages[:-1]
65
+
66
+ # Replace system prompt
67
+ for msg in temp_messages:
68
+ if msg.get('role') == 'system':
69
+ msg['content'] = new_system_prompt
70
+ break
71
+ else:
72
+ # No system message exists, add one
73
+ temp_messages.insert(0, {"role": "system", "content": new_system_prompt})
74
+
75
+ # See what agent would do with new prompt
76
+ tool_schemas = [tool.to_function_schema() for tool in self.agent.tools] if self.agent.tools else None
77
+ response = self.agent.llm.complete(temp_messages, tools=tool_schemas)
78
+
79
+ if response.tool_calls:
80
+ new_choices = [f"{tc.name}({tc.arguments})" for tc in response.tool_calls]
81
+ still_calls_this = any(tc.name == self.bp_ctx.tool_name for tc in response.tool_calls)
82
+ else:
83
+ new_choices = ["No tools - would answer directly"]
84
+ still_calls_this = False
85
+
86
+ result = f"**Current system prompt**: {self.agent.system_prompt[:200]}...\n"
87
+ result += f"**Current choice**: {self.bp_ctx.tool_name}({self.bp_ctx.tool_args})\n\n"
88
+ result += f"**New system prompt**: {new_system_prompt[:200]}...\n"
89
+ result += f"**Would choose**: {', '.join(new_choices)}\n\n"
90
+
91
+ if still_calls_this:
92
+ result += "❌ Still calls the same tool - prompt change didn't help"
93
+ else:
94
+ result += "✓ Different choice - prompt change would prevent this call"
95
+
96
+ return result
97
+
98
+ def test_stability_with_current_prompt(self, num_trials: int = 3) -> str:
99
+ """Test if current decision is stable or random.
100
+
101
+ Use case: "Is this tool choice consistent or does it vary randomly?"
102
+
103
+ Args:
104
+ num_trials: Number of times to test (default: 3)
105
+
106
+ Returns:
107
+ Analysis of decision stability
108
+ """
109
+ # Get messages up to decision point
110
+ temp_messages = self.agent.current_session['messages'].copy()
111
+ if temp_messages and temp_messages[-1].get('role') == 'assistant':
112
+ temp_messages = temp_messages[:-1]
113
+
114
+ # Run multiple trials
115
+ tool_schemas = [tool.to_function_schema() for tool in self.agent.tools] if self.agent.tools else None
116
+ decisions = []
117
+
118
+ for _ in range(num_trials):
119
+ response = self.agent.llm.complete(temp_messages, tools=tool_schemas)
120
+ if response.tool_calls:
121
+ decision = response.tool_calls[0].name
122
+ else:
123
+ decision = "No tool"
124
+ decisions.append(decision)
125
+
126
+ # Analyze
127
+ unique = set(decisions)
128
+ is_stable = len(unique) == 1
129
+
130
+ result = f"**Tested {num_trials} times**: {', '.join(decisions)}\n\n"
131
+
132
+ if is_stable:
133
+ result += "✓ STABLE - Always chooses same tool\n"
134
+ result += "Conclusion: Decision is consistent, not random"
135
+ else:
136
+ result += f"❌ UNSTABLE - {len(unique)} different choices\n"
137
+ result += "Conclusion: Decision varies - system prompt may need to be more directive"
138
+
139
+ return result
140
+
141
+ def test_with_different_result(self, hypothetical_result: Any) -> str:
142
+ """Test if different tool result changes next action.
143
+
144
+ Use case: "Would a different result change what the agent does next?"
145
+
146
+ System prompt and messages stay the same, only the tool result changes.
147
+
148
+ Args:
149
+ hypothetical_result: Alternative result to test
150
+
151
+ Returns:
152
+ Analysis of whether next action would change
153
+ """
154
+ current_next = self.bp_ctx.next_actions or []
155
+
156
+ # Build modified message history with different result
157
+ temp_messages = self.agent.current_session['messages'].copy()
158
+
159
+ # Find the assistant message with tool calls and add modified result
160
+ for msg in reversed(temp_messages):
161
+ if msg.get('role') == 'assistant' and msg.get('tool_calls'):
162
+ for tool_call in msg.get('tool_calls', []):
163
+ if tool_call.get('function', {}).get('name') == self.bp_ctx.tool_name:
164
+ # Add modified result message
165
+ temp_messages.append({
166
+ "role": "tool",
167
+ "tool_call_id": tool_call['id'],
168
+ "content": str(hypothetical_result)
169
+ })
170
+ break
171
+ break
172
+
173
+ # See what agent would do with modified result
174
+ tool_schemas = [tool.to_function_schema() for tool in self.agent.tools] if self.agent.tools else None
175
+ response = self.agent.llm.complete(temp_messages, tools=tool_schemas)
176
+
177
+ if response.tool_calls:
178
+ new_actions = [f"{tc.name}({tc.arguments})" for tc in response.tool_calls]
179
+ else:
180
+ new_actions = ["Finish - no more tools"]
181
+
182
+ current_actions = [f"{a['name']}({a['args']})" for a in current_next] if current_next else ["Finish"]
183
+
184
+ result = f"**Current result**: {self.bp_ctx.trace_entry.get('result')}\n"
185
+ result += f"**Current next action**: {', '.join(current_actions)}\n\n"
186
+ result += f"**If result was**: {hypothetical_result}\n"
187
+ result += f"**Would do**: {', '.join(new_actions)}\n\n"
188
+
189
+ if new_actions == current_actions:
190
+ result += "✓ Same action - result doesn't affect decision"
191
+ else:
192
+ result += "⚠️ Different action - result is critical to decision chain"
193
+
194
+ return result
195
+
196
+ def analyze_why_this_tool(self) -> str:
197
+ """Simple analysis: Ask why this specific tool was chosen.
198
+
199
+ Use case: "Why did you choose this tool?" - in the agent's own words
200
+
201
+ Uses the same system prompt and messages as the agent, just asks
202
+ the agent to explain its own reasoning.
203
+
204
+ Returns:
205
+ Agent's explanation of why it chose this tool
206
+ """
207
+ # Use the agent's current messages up to this point
208
+ temp_messages = self.agent.current_session['messages'].copy()
209
+
210
+ # Remove the assistant message that made the tool call
211
+ if temp_messages and temp_messages[-1].get('role') == 'assistant':
212
+ temp_messages = temp_messages[:-1]
213
+
214
+ # Add a question asking why it would choose this tool
215
+ temp_messages.append({
216
+ "role": "user",
217
+ "content": f"Why would you choose to call the tool '{self.bp_ctx.tool_name}' with arguments {self.bp_ctx.tool_args} for this task? Explain your reasoning."
218
+ })
219
+
220
+ # Get the agent's own explanation using its model
221
+ response = self.agent.llm.complete(temp_messages, tools=None)
222
+
223
+ return response.content
224
+
225
+ def analyze_root_cause(self) -> RootCauseAnalysis:
226
+ """Deep reasoning: WHY was this specific tool chosen?
227
+
228
+ Use case: "What caused the agent to choose this unwanted tool?"
229
+
230
+ Analyzes:
231
+ - Which parts of system prompt influenced this?
232
+ - What in user request triggered this?
233
+ - What reasoning chain led here?
234
+ - Root cause and how to fix
235
+
236
+ Returns:
237
+ Structured analysis with causal factors and suggested fixes
238
+ """
239
+ # Just provide the data - analysis framework is in the system prompt
240
+ data = f"""**Agent System Prompt:**
241
+ {self.agent.system_prompt}
242
+
243
+ **User Request:**
244
+ {self.bp_ctx.user_prompt}
245
+
246
+ **Tool Chosen:**
247
+ {self.bp_ctx.tool_name} with arguments {self.bp_ctx.tool_args}
248
+
249
+ **Available Tools:**
250
+ {', '.join([t.name for t in self.agent.tools]) if self.agent.tools else 'None'}
251
+
252
+ **Previous Tools Called:**
253
+ {', '.join(self.bp_ctx.previous_tools) if self.bp_ctx.previous_tools else 'None'}"""
254
+
255
+ prompt_file = Path(__file__).parent / "root_cause_analysis_prompt.md"
256
+
257
+ # Use the same model as the agent being debugged
258
+ return llm_do(
259
+ data,
260
+ output=RootCauseAnalysis,
261
+ system_prompt=prompt_file,
262
+ model=self.agent.llm.model
263
+ )
@@ -0,0 +1,29 @@
1
+ # Tool Choice Explainer
2
+
3
+ You are a debugging assistant that explains why an AI agent chose to call a specific tool.
4
+
5
+ ## Your Task
6
+
7
+ Provide a clear, concise explanation (2-4 sentences) focusing on:
8
+
9
+ 1. **Why THIS specific tool was chosen** - What need did it address?
10
+ 2. **Why THESE specific arguments were used** - How do they relate to the task?
11
+ 3. **Whether this choice makes sense** - Is there anything unusual or concerning?
12
+
13
+ ## Available Investigation Tools
14
+
15
+ For deeper analysis, you can use these experimental tools:
16
+
17
+ - **analyze_why_this_tool()** - Get the agent's own explanation of why it chose this tool
18
+ - **analyze_root_cause()** - Deep analysis of what caused this choice (returns structured data)
19
+ - **test_stability_with_current_prompt()** - Check if this decision is consistent or varies randomly
20
+ - **test_with_different_system_prompt(new_prompt)** - Test if a prompt change would prevent this call
21
+ - **test_with_different_result(hypothetical_result)** - Test if different result changes next action
22
+
23
+ ## Guidelines
24
+
25
+ - Start with the provided context - it has all basic information
26
+ - Use investigation tools ONLY if deeper analysis would help (e.g., for unwanted tool calls, unstable decisions)
27
+ - Be direct and helpful
28
+ - Focus on reasoning and causality
29
+ - Point out anything unexpected or potentially problematic
@@ -0,0 +1,43 @@
1
+ # Root Cause Analysis Expert
2
+
3
+ You are a debugging expert analyzing AI agent decisions.
4
+
5
+ ## Your Task
6
+
7
+ Identify **what caused** the agent to choose a specific tool.
8
+
9
+ You will be given:
10
+ - Agent's system prompt
11
+ - User's request
12
+ - Tool that was chosen
13
+ - Available tools
14
+ - Previous tools called
15
+
16
+ ## Analysis Framework
17
+
18
+ Identify the PRIMARY source of influence and provide:
19
+
20
+ 1. **primary_cause_source**: What influenced this choice?
21
+ - "system_prompt" - A directive in the system prompt
22
+ - "user_message" - Words/concepts in the user's request
23
+ - "tool_results" - Previous tool results led to this
24
+ - "available_tools" - Tool availability/names triggered this
25
+
26
+ 2. **influential_text**: Quote the EXACT sentence or phrase that caused this choice. Be precise.
27
+
28
+ 3. **explanation**: Why did this specific text lead to choosing this tool? What's the causal chain?
29
+
30
+ 4. **is_correct_choice**: Is this the right tool for the user's actual need? (true/false)
31
+
32
+ 5. **suggested_fix**: If unwanted, what specific change would prevent this?
33
+ - For system_prompt: Which sentence to modify/remove
34
+ - For user_message: How to rephrase
35
+ - For tool_results: What tool behavior needs fixing
36
+ - For available_tools: Which tools to add/remove
37
+
38
+ ## Guidelines
39
+
40
+ - Quote actual text - don't paraphrase
41
+ - Be specific about causality (not generic)
42
+ - Provide actionable fixes
43
+ - Focus on the PRIMARY cause (not all possible factors)