connectonion 0.6.4__py3-none-any.whl → 0.6.5__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 (33) hide show
  1. connectonion/__init__.py +1 -1
  2. connectonion/cli/co_ai/main.py +2 -2
  3. connectonion/cli/co_ai/prompts/connectonion/concepts/trust.md +166 -208
  4. connectonion/cli/commands/copy_commands.py +21 -0
  5. connectonion/cli/commands/trust_commands.py +152 -0
  6. connectonion/cli/main.py +82 -0
  7. connectonion/core/llm.py +2 -2
  8. connectonion/docs/concepts/fast_rules.md +237 -0
  9. connectonion/docs/concepts/onboarding.md +465 -0
  10. connectonion/docs/concepts/trust.md +933 -192
  11. connectonion/docs/design-decisions/023-trust-policy-system-design.md +323 -0
  12. connectonion/docs/network/README.md +23 -1
  13. connectonion/docs/network/connect.md +135 -0
  14. connectonion/docs/network/host.md +73 -4
  15. connectonion/network/__init__.py +7 -6
  16. connectonion/network/asgi/__init__.py +3 -0
  17. connectonion/network/asgi/http.py +125 -19
  18. connectonion/network/asgi/websocket.py +276 -15
  19. connectonion/network/connect.py +145 -29
  20. connectonion/network/host/auth.py +70 -67
  21. connectonion/network/host/routes.py +88 -3
  22. connectonion/network/host/server.py +100 -17
  23. connectonion/network/trust/__init__.py +27 -19
  24. connectonion/network/trust/factory.py +51 -24
  25. connectonion/network/trust/fast_rules.py +100 -0
  26. connectonion/network/trust/tools.py +316 -32
  27. connectonion/network/trust/trust_agent.py +403 -0
  28. connectonion/transcribe.py +1 -1
  29. {connectonion-0.6.4.dist-info → connectonion-0.6.5.dist-info}/METADATA +1 -1
  30. {connectonion-0.6.4.dist-info → connectonion-0.6.5.dist-info}/RECORD +32 -27
  31. connectonion/network/trust/prompts.py +0 -71
  32. {connectonion-0.6.4.dist-info → connectonion-0.6.5.dist-info}/WHEEL +0 -0
  33. {connectonion-0.6.4.dist-info → connectonion-0.6.5.dist-info}/entry_points.txt +0 -0
connectonion/__init__.py CHANGED
@@ -10,7 +10,7 @@ LLM-Note:
10
10
  ConnectOnion - A simple agent framework with behavior tracking.
11
11
  """
12
12
 
13
- __version__ = "0.6.4"
13
+ __version__ = "0.6.5"
14
14
 
15
15
  # Auto-load .env files for the entire framework
16
16
  from dotenv import load_dotenv
@@ -47,6 +47,6 @@ def start_server(
47
47
  web_mode=True,
48
48
  )
49
49
 
50
- # Start server with open trust (no auth required)
50
+ # Start server with careful trust (requires invite code or payment for strangers)
51
51
  # relay_url=None disables P2P discovery
52
- host(agent_factory, port=port, trust="open", relay_url=None)
52
+ host(agent_factory, port=port, trust="careful", relay_url=None)
@@ -1,291 +1,249 @@
1
1
  # Trust in ConnectOnion
2
2
 
3
- The `trust` parameter provides flexible, bidirectional trust configuration for agent interactions.
3
+ Trust is a **host layer** concern that controls who can access your agent. It manages onboarding, access control, and client state transitions.
4
4
 
5
5
  ## Quick Start
6
6
 
7
7
  ```python
8
- from connectonion import Agent, need
9
-
10
- # Simple trust levels
11
- translator = need("translate", trust="strict") # Production: verified only
12
- analyzer = need("analyze", trust="tested") # Default: test first
13
- scraper = need("scrape", trust="open") # Development: trust all
14
-
15
- # For your own agent
16
- agent = Agent(
17
- name="my_service",
18
- tools=[process_data],
19
- trust="strict" # Who can use my services
20
- )
8
+ from connectonion import Agent
9
+ from connectonion.network import host
10
+
11
+ # Create your agent (no trust here - agent only cares about its job)
12
+ agent = Agent("my_service", tools=[process_data])
13
+
14
+ # Host it with trust (trust is a host concern)
15
+ host(agent, trust="careful") # Default: verify before allowing access
21
16
  ```
22
17
 
23
- ## Three Forms of Trust
18
+ ## Core Concepts
24
19
 
25
- ### 1. Trust Levels (String)
20
+ ### Separation of Concerns
26
21
 
27
- Simple predefined levels for common scenarios:
22
+ | Layer | Responsibility |
23
+ |-------|----------------|
24
+ | **Agent** | What it does (skills, tools, reasoning) |
25
+ | **Host** | How it's accessed (network, trust, security) |
28
26
 
29
27
  ```python
30
- # Development - trust everyone
31
- agent = need("service", trust="open")
28
+ # Agent is pure - only cares about its job
29
+ agent = Agent("translator", tools=[translate])
32
30
 
33
- # Default - test before trusting
34
- agent = need("service", trust="tested")
35
-
36
- # Production - only verified/whitelisted
37
- agent = need("service", trust="strict")
31
+ # Trust is configured at host level
32
+ host(agent, trust="open") # Dev: trust everyone
33
+ host(agent, trust="careful") # Staging: verify first
34
+ host(agent, trust="strict") # Prod: whitelist only
38
35
  ```
39
36
 
40
- ### 2. Trust Policy (Natural Language)
37
+ ### Two-Tier Verification
41
38
 
42
- Express complex requirements in plain English:
39
+ | Type | Tokens | When to Use |
40
+ |------|--------|-------------|
41
+ | **Fast Rules** | Zero | Simple checks (invite code, payment, whitelist) |
42
+ | **Trust Agent** | Burns tokens | Complex decisions (behavior analysis, edge cases) |
43
43
 
44
- ```python
45
- # Inline policy
46
- translator = need("translate", trust="""
47
- I trust agents that:
48
- - Pass capability tests
49
- - Respond within 500ms
50
- - Are on my whitelist OR from local network
51
- """)
52
-
53
- # From file
54
- translator = need("translate", trust="./trust_policy.md")
55
- ```
44
+ 90% of requests use fast rules (instant, free). 10% use trust agent (LLM reasoning, rare).
56
45
 
57
- Example trust policy file:
58
- ```markdown
59
- # My Trust Requirements
46
+ ## Trust Levels
60
47
 
61
- I trust agents that meet ALL of these criteria:
62
- - Successfully translate "Hello" to "Hola"
63
- - Respond in less than 1 second
64
- - Have processed at least 10 requests successfully
48
+ ### Open (Development)
65
49
 
66
- I immediately reject agents that:
67
- - Fail basic capability tests
68
- - Take longer than 5 seconds
69
- - Are on my blacklist
70
- ```
50
+ Trust everyone. No verification.
71
51
 
72
- ### 3. Trust Agent
52
+ ```python
53
+ host(agent, trust="open")
54
+ ```
73
55
 
74
- For maximum control, use a custom trust agent:
56
+ Use for: Local development, Jupyter notebooks, testing.
75
57
 
76
- ```python
77
- # Create a trust agent with verification tools
78
- trust_agent = Agent(
79
- name="my_guardian",
80
- tools=[
81
- check_whitelist,
82
- verify_capability,
83
- measure_response_time,
84
- check_reputation
85
- ],
86
- system_prompt="""
87
- You verify other agents before allowing interaction.
88
- Be strict with payment processors, relaxed with read-only services.
89
- """
90
- )
58
+ ### Careful (Default)
91
59
 
92
- # Use it for your agent
93
- my_agent = Agent(
94
- name="my_service",
95
- tools=[process_payment],
96
- trust=trust_agent # My guardian protects me
97
- )
60
+ Verify strangers before granting access. Fast rules first, then trust agent for complex cases.
98
61
 
99
- # And for discovering services
100
- payment = need("payment processor", trust=trust_agent)
62
+ ```python
63
+ host(agent, trust="careful")
101
64
  ```
102
65
 
103
- ## Bidirectional Trust
66
+ Use for: Staging, testing, pre-production.
67
+
68
+ ### Strict (Production)
104
69
 
105
- The same `trust` parameter works in both directions:
70
+ Whitelist only. No exceptions.
106
71
 
107
72
  ```python
108
- # As a SERVICE provider (who can use me?)
109
- alice_agent = Agent(
110
- name="alice_translator",
111
- tools=[translate],
112
- trust="tested" # Users must pass my tests
113
- )
73
+ host(agent, trust="strict")
74
+ ```
75
+
76
+ Use for: Production, sensitive data, payments.
114
77
 
115
- # As a SERVICE consumer (who do I trust?)
116
- translator = need("translate", trust="strict") # I only use verified services
78
+ ## Client States
117
79
 
118
- # Both trust requirements must be satisfied for interaction!
119
80
  ```
81
+ Promotion Chain (earned trust):
120
82
 
121
- ## Trust Flow Example
83
+ ┌─────────────┐ verify ┌─────────────┐ earn trust ┌─────────────┐
84
+ │ Stranger │ ──────────► │ Contact │ ───────────► │ Whitelist │
85
+ └─────────────┘ └─────────────┘ └─────────────┘
86
+ │ │ │
87
+ │ block │ demote │ demote
88
+ ▼ ▼ ▼
89
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
90
+ │ Blocklist │ │ Stranger │ │ Contact │
91
+ └─────────────┘ └─────────────┘ └─────────────┘
122
92
 
123
- ```python
124
- # Alice creates a translation service
125
- alice = Agent(
126
- name="alice_translator",
127
- tools=[translate],
128
- trust="tested" # Test users before serving them
129
- )
130
- share(alice)
131
93
 
132
- # Bob looks for a translator
133
- translator = need(
134
- "translate to Spanish",
135
- trust="strict" # Bob only uses verified services
136
- )
94
+ Admin (separate, manual only):
137
95
 
138
- # What happens:
139
- # 1. Bob's trust agent evaluates Alice (strict check)
140
- # 2. Alice's trust agent evaluates Bob (test required)
141
- # 3. Both must approve for connection to succeed
96
+ ┌─────────────┐ set_admin() ┌─────────────┐
97
+ │ Any Level │ ─────────────► │ Admin │
98
+ └─────────────┘ └─────────────┘
99
+
100
+ remove_admin()
101
+
102
+
103
+ ┌─────────────┐
104
+ │ Previous │
105
+ └─────────────┘
142
106
  ```
143
107
 
144
- ## Environment-Based Defaults
145
-
146
- ConnectOnion automatically adjusts trust based on environment:
108
+ ### Client Levels
147
109
 
148
- ```python
149
- # No trust parameter needed - auto-detected!
150
- translator = need("translate")
110
+ | Level | Description | Access |
111
+ |-------|-------------|--------|
112
+ | **Stranger** | Unknown client, not verified | Limited or none |
113
+ | **Contact** | Verified via invite/payment | Standard access |
114
+ | **Whitelist** | Trusted, pre-approved | Full access |
115
+ | **Admin** | Can manage other clients | Full access + management |
116
+ | **Blocklist** | Blocked, denied access | No access |
151
117
 
152
- # In development (localhost, Jupyter)
153
- # → Defaults to trust="open"
118
+ ## Trust Policy Files
154
119
 
155
- # In test files (test_*.py)
156
- # → Defaults to trust="tested"
120
+ Trust policies are markdown files with YAML frontmatter. YAML defines fast rules (no tokens), markdown body defines trust agent behavior (for complex decisions).
157
121
 
158
- # In production
159
- # → Defaults to trust="strict"
122
+ ```yaml
123
+ # prompts/trust/careful.md
124
+ ---
125
+ fast_rules:
126
+ - if: has_invite_code
127
+ action: verify_invite
128
+ on_success: promote_to_contact
160
129
 
161
- # Override when needed
162
- translator = need("translate", trust="open") # Force open even in production
163
- ```
130
+ - if: is_blocked
131
+ action: deny
164
132
 
165
- ## Trust Functions
133
+ - if: is_whitelist
134
+ action: allow
166
135
 
167
- Trust agents use composable functions:
136
+ - if: is_stranger
137
+ action: deny
168
138
 
169
- ```python
170
- # Basic trust functions (provided by ConnectOnion)
171
- def check_whitelist(agent_id: str) -> bool:
172
- """Check if agent is whitelisted"""
173
-
174
- def test_capability(agent, test_input, expected) -> bool:
175
- """Test if agent produces expected output"""
176
-
177
- def measure_response_time(agent, timeout_ms) -> float:
178
- """Measure agent response time"""
179
-
180
- def check_local_network(agent_ip: str) -> bool:
181
- """Check if agent is on local network"""
182
-
183
- # Combine in your trust agent
184
- my_trust = Agent(
185
- name="guardian",
186
- tools=[
187
- check_whitelist,
188
- test_capability,
189
- measure_response_time,
190
- check_local_network
191
- ]
192
- )
193
- ```
139
+ use_agent:
140
+ - when: requests > 10
141
+ reason: "Evaluate for promotion"
194
142
 
195
- ## Whitelist Management
143
+ cache: 24h
144
+ ---
196
145
 
197
- Simple text file at `~/.connectonion/trusted.txt`:
146
+ # Trust Agent Policy
198
147
 
199
- ```
200
- translator.api.com
201
- analyzer.local
202
- my-company.internal.net
203
- 192.168.1.*
204
- ```
148
+ You handle complex trust decisions.
205
149
 
206
- Edit with any text editor or programmatically:
150
+ ## Available Tools
151
+ - promote_to_contact(client_id)
152
+ - block(client_id, reason)
207
153
 
208
- ```python
209
- # Add to whitelist
210
- with open("~/.connectonion/trusted.txt", "a") as f:
211
- f.write("new-service.com\n")
154
+ ## When to Promote
155
+ Promote stranger to contact when:
156
+ - 10+ requests with good behavior
157
+ - No suspicious patterns
212
158
  ```
213
159
 
214
- ## Progressive Trust Building
160
+ ## Atomic Functions
215
161
 
216
- Trust grows through successful interactions:
162
+ Trust manager provides simple atomic functions as tools:
217
163
 
218
164
  ```python
219
- # First encounter - requires testing
220
- translator = need("translate", trust="tested")
221
- # → Agent is tested before use
165
+ # Promotion (earned)
166
+ promote_to_contact(client_id) # Stranger Contact
167
+ promote_to_whitelist(client_id) # Contact Whitelist
168
+
169
+ # Demotion
170
+ demote_to_contact(client_id) # Whitelist → Contact
171
+ demote_to_stranger(client_id) # Contact → Stranger
222
172
 
223
- # After successful interactions
224
- # → Agent automatically added to "verified" list
173
+ # Blocking
174
+ block(client_id, reason)
175
+ unblock(client_id)
225
176
 
226
- # Future encounters
227
- translator = need("translate", trust="tested")
228
- # → Skip testing, already verified
177
+ # Admin (manual only)
178
+ set_admin(client_id, by_admin)
179
+ remove_admin(client_id, by_admin)
229
180
  ```
230
181
 
231
- ## Common Patterns
182
+ ## Custom Trust Policies
183
+
184
+ ### Option 1: Use Preset
232
185
 
233
- ### Development Mode
234
186
  ```python
235
- # Trust everyone for rapid development
236
- connectonion.set_default_trust("open")
187
+ host(agent, trust="careful") # Uses prompts/trust/careful.md
237
188
  ```
238
189
 
239
- ### Production Mode
190
+ ### Option 2: Custom Markdown File
191
+
240
192
  ```python
241
- # Strict verification for production
242
- payment = need("payment processor", trust="strict")
243
- sensitive = need("data processor", trust="strict")
193
+ host(agent, trust="./my_policy.md")
244
194
  ```
245
195
 
246
- ### Mixed Trust
196
+ ### Option 3: Custom TrustAgent
197
+
247
198
  ```python
248
- # Different trust for different services
249
- scraper = need("web scraper", trust="open") # Low risk
250
- analyzer = need("analyze data", trust="tested") # Medium risk
251
- payment = need("process payment", trust="strict") # High risk
199
+ from connectonion.network.trust import TrustAgent
200
+
201
+ trust = TrustAgent(
202
+ system_prompt="./my_policy.md",
203
+ tools=[my_custom_verifier]
204
+ )
205
+ host(agent, trust=trust)
252
206
  ```
253
207
 
254
- ### Custom Trust Logic
208
+ ## Environment-Based Defaults
209
+
255
210
  ```python
256
- # Trust based on context
257
- def get_trust_level(service_type):
258
- if "payment" in service_type:
259
- return "strict"
260
- elif "read" in service_type:
261
- return "open"
262
- else:
263
- return "tested"
264
-
265
- service = need("read data", trust=get_trust_level("read data"))
211
+ # No trust specified - auto-detected from environment
212
+ host(agent)
213
+
214
+ # CONNECTONION_ENV=development → trust="open"
215
+ # CONNECTONION_ENV=staging → trust="careful"
216
+ # CONNECTONION_ENV=production → trust="strict"
266
217
  ```
267
218
 
268
- ## Security Best Practices
219
+ ## List Management
269
220
 
270
- 1. **Production = Strict**: Always use `trust="strict"` in production
271
- 2. **Test Sensitive Operations**: Payment, data modification, etc.
272
- 3. **Whitelist Critical Services**: Manually verify and whitelist
273
- 4. **Monitor Trust Decisions**: Log all trust evaluations
274
- 5. **Regular Audits**: Review whitelist and trust policies
221
+ Trust manager maintains lists at `~/.co/`:
222
+
223
+ ```
224
+ ~/.co/
225
+ ├── contacts.txt # Verified contacts
226
+ ├── whitelist.txt # Trusted, pre-approved
227
+ ├── admins.txt # Can manage other clients
228
+ └── blocklist.txt # Blocked clients
229
+ ```
275
230
 
276
231
  ## FAQ
277
232
 
278
233
  **Q: What's the default trust level?**
279
- A: `"tested"` - agents are tested before first use
234
+ A: `"careful"` - verify strangers, allow contacts.
280
235
 
281
- **Q: Can I change trust after agent creation?**
282
- A: Yes: `agent.trust = new_trust_agent`
236
+ **Q: Do fast rules burn tokens?**
237
+ A: No. Fast rules are simple if/then executed by host. Zero tokens.
283
238
 
284
- **Q: How do trust agents communicate?**
285
- A: They're regular ConnectOnion agents - they talk naturally
239
+ **Q: When does trust agent run?**
240
+ A: Only when `use_agent` triggers fire (e.g., after 10 requests). Rare.
286
241
 
287
- **Q: What if both agents have strict trust?**
288
- A: Both requirements must be met - most restrictive wins
242
+ **Q: Can I use the same agent with different trust levels?**
243
+ A: Yes. Trust is host config, not agent config.
289
244
 
290
- **Q: Can I disable trust completely?**
291
- A: Yes: `trust="open"` accepts everyone without checks
245
+ ```python
246
+ # Same agent, different trust
247
+ host(agent, trust="open") # Dev
248
+ host(agent, trust="strict") # Prod
249
+ ```
@@ -63,6 +63,13 @@ PROMPTS = {
63
63
  "coding_agent": "coding_agent",
64
64
  }
65
65
 
66
+ # Registry of copyable trust policies
67
+ TRUST = {
68
+ "open": "open.md",
69
+ "careful": "careful.md",
70
+ "strict": "strict.md",
71
+ }
72
+
66
73
 
67
74
  def handle_copy(
68
75
  names: List[str],
@@ -82,11 +89,14 @@ def handle_copy(
82
89
  import connectonion.useful_plugins as plugins_module
83
90
  import connectonion.tui as tui_module
84
91
  import connectonion.useful_prompts as prompts_module
92
+ import connectonion
85
93
 
86
94
  useful_tools_dir = Path(tools_module.__file__).parent
87
95
  useful_plugins_dir = Path(plugins_module.__file__).parent
88
96
  tui_dir = Path(tui_module.__file__).parent
89
97
  useful_prompts_dir = Path(prompts_module.__file__).parent
98
+ # Trust policies are in the main package's prompts/trust/ directory
99
+ trust_dir = Path(connectonion.__file__).parent.parent / "prompts" / "trust"
90
100
 
91
101
  current_dir = Path.cwd()
92
102
 
@@ -123,6 +133,13 @@ def handle_copy(
123
133
  dest_dir = Path(path) if path else current_dir / "prompts"
124
134
  copy_directory(source, dest_dir, force)
125
135
 
136
+ # Check if it's a trust policy (support both "careful" and "trust/careful")
137
+ elif name_lower in TRUST or (name_lower.startswith("trust/") and name_lower[6:] in TRUST):
138
+ policy_name = name_lower[6:] if name_lower.startswith("trust/") else name_lower
139
+ source = trust_dir / TRUST[policy_name]
140
+ dest_dir = Path(path) if path else current_dir / "prompts" / "trust"
141
+ copy_file(source, dest_dir, force)
142
+
126
143
  else:
127
144
  console.print(f"[red]Unknown: {name}[/red]")
128
145
  console.print("Use [cyan]co copy --list[/cyan] to see available items")
@@ -180,9 +197,13 @@ def show_available_items():
180
197
  for name, dir_name in sorted(PROMPTS.items()):
181
198
  table.add_row(name, "prompt", f"{dir_name}/")
182
199
 
200
+ for name, file in sorted(TRUST.items()):
201
+ table.add_row(f"trust/{name}", "trust", file)
202
+
183
203
  for name, file in sorted(TUI.items()):
184
204
  table.add_row(name, "tui", file)
185
205
 
186
206
  console.print(table)
187
207
  console.print("\n[dim]Usage: co copy <name> [--path ./custom/][/dim]")
188
208
  console.print("[dim]Prompts are copied as directories to ./prompts/<name>/[/dim]")
209
+ console.print("[dim]Trust policies are copied to ./prompts/trust/<name>.md[/dim]")