connectonion 0.6.3__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.
- connectonion/__init__.py +1 -1
- connectonion/cli/co_ai/agent.py +3 -3
- connectonion/cli/co_ai/main.py +2 -2
- connectonion/cli/co_ai/plugins/__init__.py +2 -3
- connectonion/cli/co_ai/plugins/system_reminder.py +154 -0
- connectonion/cli/co_ai/prompts/connectonion/concepts/trust.md +166 -208
- connectonion/cli/co_ai/prompts/system-reminders/agent.md +23 -0
- connectonion/cli/co_ai/prompts/system-reminders/plan_mode.md +13 -0
- connectonion/cli/co_ai/prompts/system-reminders/security.md +14 -0
- connectonion/cli/co_ai/prompts/system-reminders/simplicity.md +14 -0
- connectonion/cli/co_ai/tools/plan_mode.py +1 -4
- connectonion/cli/co_ai/tools/read.py +0 -6
- connectonion/cli/commands/copy_commands.py +21 -0
- connectonion/cli/commands/trust_commands.py +152 -0
- connectonion/cli/main.py +82 -0
- connectonion/core/llm.py +2 -2
- connectonion/docs/concepts/fast_rules.md +237 -0
- connectonion/docs/concepts/onboarding.md +465 -0
- connectonion/docs/concepts/plugins.md +2 -1
- connectonion/docs/concepts/trust.md +933 -192
- connectonion/docs/design-decisions/023-trust-policy-system-design.md +323 -0
- connectonion/docs/network/README.md +23 -1
- connectonion/docs/network/connect.md +135 -0
- connectonion/docs/network/host.md +73 -4
- connectonion/docs/useful_plugins/tool_approval.md +139 -0
- connectonion/network/__init__.py +7 -6
- connectonion/network/asgi/__init__.py +3 -0
- connectonion/network/asgi/http.py +125 -19
- connectonion/network/asgi/websocket.py +276 -15
- connectonion/network/connect.py +145 -29
- connectonion/network/host/auth.py +70 -67
- connectonion/network/host/routes.py +88 -3
- connectonion/network/host/server.py +100 -17
- connectonion/network/trust/__init__.py +27 -19
- connectonion/network/trust/factory.py +51 -24
- connectonion/network/trust/fast_rules.py +100 -0
- connectonion/network/trust/tools.py +316 -32
- connectonion/network/trust/trust_agent.py +403 -0
- connectonion/transcribe.py +1 -1
- connectonion/useful_plugins/__init__.py +2 -1
- connectonion/useful_plugins/tool_approval.py +233 -0
- {connectonion-0.6.3.dist-info → connectonion-0.6.5.dist-info}/METADATA +1 -1
- {connectonion-0.6.3.dist-info → connectonion-0.6.5.dist-info}/RECORD +45 -37
- connectonion/cli/co_ai/plugins/reminder.py +0 -76
- connectonion/cli/co_ai/plugins/shell_approval.py +0 -105
- connectonion/cli/co_ai/prompts/reminders/plan_mode.md +0 -34
- connectonion/cli/co_ai/reminders.py +0 -159
- connectonion/network/trust/prompts.py +0 -71
- {connectonion-0.6.3.dist-info → connectonion-0.6.5.dist-info}/WHEEL +0 -0
- {connectonion-0.6.3.dist-info → connectonion-0.6.5.dist-info}/entry_points.txt +0 -0
connectonion/__init__.py
CHANGED
connectonion/cli/co_ai/agent.py
CHANGED
|
@@ -12,9 +12,9 @@ from .tools import (
|
|
|
12
12
|
load_guide,
|
|
13
13
|
)
|
|
14
14
|
from .skills import skill
|
|
15
|
-
from .plugins import
|
|
15
|
+
from .plugins import system_reminder
|
|
16
16
|
from connectonion import Agent, bash, after_user_input, FileWriter, MODE_AUTO, MODE_NORMAL, TodoList
|
|
17
|
-
from connectonion.useful_plugins import
|
|
17
|
+
from connectonion.useful_plugins import eval, tool_approval
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
PROMPTS_DIR = Path(__file__).parent / "prompts"
|
|
@@ -71,7 +71,7 @@ def create_coding_agent(
|
|
|
71
71
|
if project_context:
|
|
72
72
|
system_prompt += f"\n\n---\n\n{project_context}"
|
|
73
73
|
|
|
74
|
-
plugins = [
|
|
74
|
+
plugins = [eval, system_reminder, tool_approval]
|
|
75
75
|
|
|
76
76
|
agent = Agent(
|
|
77
77
|
name="oo",
|
connectonion/cli/co_ai/main.py
CHANGED
|
@@ -47,6 +47,6 @@ def start_server(
|
|
|
47
47
|
web_mode=True,
|
|
48
48
|
)
|
|
49
49
|
|
|
50
|
-
# Start server with
|
|
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="
|
|
52
|
+
host(agent_factory, port=port, trust="careful", relay_url=None)
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""
|
|
2
|
+
System Reminder Plugin - Injects contextual guidance based on intent and tool usage.
|
|
3
|
+
|
|
4
|
+
Two triggers:
|
|
5
|
+
1. after_user_input: Detect intent (coding, agent creation) and inject relevant reminder
|
|
6
|
+
2. after_each_tool: Inject reminder based on tool usage
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
from connectonion.cli.co_ai.plugins.system_reminder import system_reminder
|
|
10
|
+
|
|
11
|
+
agent = Agent("coder", plugins=[system_reminder])
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
import fnmatch
|
|
16
|
+
from typing import TYPE_CHECKING
|
|
17
|
+
|
|
18
|
+
from connectonion.core.events import after_each_tool, after_user_input
|
|
19
|
+
from connectonion.llm_do import llm_do
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
from connectonion.core.agent import Agent
|
|
23
|
+
|
|
24
|
+
# Default reminders directory
|
|
25
|
+
REMINDERS_DIR = Path(__file__).parent.parent / "prompts" / "system-reminders"
|
|
26
|
+
|
|
27
|
+
# Intent detection prompt
|
|
28
|
+
INTENT_PROMPT = """Analyze the user's request.
|
|
29
|
+
|
|
30
|
+
User request: {user_prompt}
|
|
31
|
+
|
|
32
|
+
Is this about building software, creating agents, writing code, or automation?
|
|
33
|
+
Respond with ONE word only: "build" or "other"
|
|
34
|
+
|
|
35
|
+
One word only:"""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _parse_frontmatter(text):
|
|
39
|
+
"""Parse YAML frontmatter from markdown."""
|
|
40
|
+
if not text.startswith('---'):
|
|
41
|
+
return {}, text
|
|
42
|
+
parts = text.split('---', 2)
|
|
43
|
+
if len(parts) < 3:
|
|
44
|
+
return {}, text
|
|
45
|
+
import yaml
|
|
46
|
+
return yaml.safe_load(parts[1]) or {}, parts[2].strip()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _load_reminders(reminders_dir):
|
|
50
|
+
"""Load all .md reminder files from directory."""
|
|
51
|
+
reminders_dir = Path(reminders_dir)
|
|
52
|
+
if not reminders_dir.exists():
|
|
53
|
+
return {}
|
|
54
|
+
reminders = {}
|
|
55
|
+
for f in reminders_dir.glob("*.md"):
|
|
56
|
+
meta, body = _parse_frontmatter(f.read_text())
|
|
57
|
+
if meta.get('name'):
|
|
58
|
+
reminders[meta['name']] = {
|
|
59
|
+
'content': body,
|
|
60
|
+
'triggers': meta.get('triggers', []),
|
|
61
|
+
'intent': meta.get('intent'), # New: intent-based trigger
|
|
62
|
+
}
|
|
63
|
+
return reminders
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _matches_pattern(pattern, value):
|
|
67
|
+
"""Check if value matches glob pattern(s)."""
|
|
68
|
+
if not pattern or not value:
|
|
69
|
+
return False
|
|
70
|
+
patterns = [pattern] if isinstance(pattern, str) else pattern
|
|
71
|
+
return any(fnmatch.fnmatch(value, p) for p in patterns)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _find_tool_reminder(reminders, tool_name, args):
|
|
75
|
+
"""Find matching reminder for tool usage."""
|
|
76
|
+
for reminder in reminders.values():
|
|
77
|
+
for trigger in reminder['triggers']:
|
|
78
|
+
if trigger.get('tool') and trigger['tool'] != tool_name:
|
|
79
|
+
continue
|
|
80
|
+
if trigger.get('path_pattern'):
|
|
81
|
+
path = args.get('path') or args.get('file_path', '')
|
|
82
|
+
if not _matches_pattern(trigger['path_pattern'], path):
|
|
83
|
+
continue
|
|
84
|
+
if trigger.get('command_pattern'):
|
|
85
|
+
cmd = args.get('command') or args.get('cmd', '')
|
|
86
|
+
if not _matches_pattern(trigger['command_pattern'], cmd):
|
|
87
|
+
continue
|
|
88
|
+
# All conditions matched
|
|
89
|
+
content = reminder['content']
|
|
90
|
+
path = args.get('path') or args.get('file_path', '')
|
|
91
|
+
return content.replace('${file_path}', path).replace('${tool_name}', tool_name)
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _find_intent_reminder(reminders, intent):
|
|
96
|
+
"""Find matching reminder for detected intent."""
|
|
97
|
+
for reminder in reminders.values():
|
|
98
|
+
if reminder.get('intent') == intent:
|
|
99
|
+
return reminder['content']
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# Load reminders once at import
|
|
104
|
+
_REMINDERS = _load_reminders(REMINDERS_DIR)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@after_user_input
|
|
108
|
+
def detect_intent(agent: 'Agent') -> None:
|
|
109
|
+
"""Detect user intent and inject relevant system reminder."""
|
|
110
|
+
user_prompt = agent.current_session.get('user_prompt', '')
|
|
111
|
+
if not user_prompt:
|
|
112
|
+
return
|
|
113
|
+
|
|
114
|
+
# Use llm_do to detect intent
|
|
115
|
+
intent = llm_do(
|
|
116
|
+
INTENT_PROMPT.format(user_prompt=user_prompt),
|
|
117
|
+
model="co/gemini-2.5-flash",
|
|
118
|
+
temperature=0,
|
|
119
|
+
).strip().lower()
|
|
120
|
+
|
|
121
|
+
# Store intent in session
|
|
122
|
+
agent.current_session['intent'] = intent
|
|
123
|
+
|
|
124
|
+
# Find and inject intent-based reminder
|
|
125
|
+
content = _find_intent_reminder(_REMINDERS, intent)
|
|
126
|
+
if content:
|
|
127
|
+
agent.current_session['messages'].append({
|
|
128
|
+
'role': 'user',
|
|
129
|
+
'content': f"\n\n{content}"
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@after_each_tool
|
|
134
|
+
def inject_tool_reminder(agent: 'Agent') -> None:
|
|
135
|
+
"""Inject matching system reminder into tool result."""
|
|
136
|
+
trace = agent.current_session.get('trace', [])
|
|
137
|
+
messages = agent.current_session.get('messages', [])
|
|
138
|
+
if not trace or not messages:
|
|
139
|
+
return
|
|
140
|
+
|
|
141
|
+
last = trace[-1]
|
|
142
|
+
if last.get('type') != 'tool_result':
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
content = _find_tool_reminder(_REMINDERS, last.get('name', ''), last.get('args', {}))
|
|
146
|
+
if content:
|
|
147
|
+
for msg in reversed(messages):
|
|
148
|
+
if msg.get('role') == 'tool':
|
|
149
|
+
msg['content'] = msg.get('content', '') + '\n\n' + content
|
|
150
|
+
break
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# Export plugin
|
|
154
|
+
system_reminder = [detect_intent, inject_tool_reminder]
|
|
@@ -1,291 +1,249 @@
|
|
|
1
1
|
# Trust in ConnectOnion
|
|
2
2
|
|
|
3
|
-
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
#
|
|
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
|
-
##
|
|
18
|
+
## Core Concepts
|
|
24
19
|
|
|
25
|
-
###
|
|
20
|
+
### Separation of Concerns
|
|
26
21
|
|
|
27
|
-
|
|
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
|
-
#
|
|
31
|
-
agent =
|
|
28
|
+
# Agent is pure - only cares about its job
|
|
29
|
+
agent = Agent("translator", tools=[translate])
|
|
32
30
|
|
|
33
|
-
#
|
|
34
|
-
agent
|
|
35
|
-
|
|
36
|
-
#
|
|
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
|
-
###
|
|
37
|
+
### Two-Tier Verification
|
|
41
38
|
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
```markdown
|
|
59
|
-
# My Trust Requirements
|
|
46
|
+
## Trust Levels
|
|
60
47
|
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
+
```python
|
|
53
|
+
host(agent, trust="open")
|
|
54
|
+
```
|
|
73
55
|
|
|
74
|
-
|
|
56
|
+
Use for: Local development, Jupyter notebooks, testing.
|
|
75
57
|
|
|
76
|
-
|
|
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
|
-
|
|
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
|
-
|
|
100
|
-
|
|
62
|
+
```python
|
|
63
|
+
host(agent, trust="careful")
|
|
101
64
|
```
|
|
102
65
|
|
|
103
|
-
|
|
66
|
+
Use for: Staging, testing, pre-production.
|
|
67
|
+
|
|
68
|
+
### Strict (Production)
|
|
104
69
|
|
|
105
|
-
|
|
70
|
+
Whitelist only. No exceptions.
|
|
106
71
|
|
|
107
72
|
```python
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
133
|
-
translator = need(
|
|
134
|
-
"translate to Spanish",
|
|
135
|
-
trust="strict" # Bob only uses verified services
|
|
136
|
-
)
|
|
94
|
+
Admin (separate, manual only):
|
|
137
95
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
96
|
+
┌─────────────┐ set_admin() ┌─────────────┐
|
|
97
|
+
│ Any Level │ ─────────────► │ Admin │
|
|
98
|
+
└─────────────┘ └─────────────┘
|
|
99
|
+
│
|
|
100
|
+
remove_admin()
|
|
101
|
+
│
|
|
102
|
+
▼
|
|
103
|
+
┌─────────────┐
|
|
104
|
+
│ Previous │
|
|
105
|
+
└─────────────┘
|
|
142
106
|
```
|
|
143
107
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
ConnectOnion automatically adjusts trust based on environment:
|
|
108
|
+
### Client Levels
|
|
147
109
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
153
|
-
# → Defaults to trust="open"
|
|
118
|
+
## Trust Policy Files
|
|
154
119
|
|
|
155
|
-
|
|
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
|
-
|
|
159
|
-
#
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
```
|
|
130
|
+
- if: is_blocked
|
|
131
|
+
action: deny
|
|
164
132
|
|
|
165
|
-
|
|
133
|
+
- if: is_whitelist
|
|
134
|
+
action: allow
|
|
166
135
|
|
|
167
|
-
|
|
136
|
+
- if: is_stranger
|
|
137
|
+
action: deny
|
|
168
138
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
143
|
+
cache: 24h
|
|
144
|
+
---
|
|
196
145
|
|
|
197
|
-
|
|
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
|
-
|
|
150
|
+
## Available Tools
|
|
151
|
+
- promote_to_contact(client_id)
|
|
152
|
+
- block(client_id, reason)
|
|
207
153
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
##
|
|
160
|
+
## Atomic Functions
|
|
215
161
|
|
|
216
|
-
Trust
|
|
162
|
+
Trust manager provides simple atomic functions as tools:
|
|
217
163
|
|
|
218
164
|
```python
|
|
219
|
-
#
|
|
220
|
-
|
|
221
|
-
# →
|
|
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
|
-
#
|
|
224
|
-
|
|
173
|
+
# Blocking
|
|
174
|
+
block(client_id, reason)
|
|
175
|
+
unblock(client_id)
|
|
225
176
|
|
|
226
|
-
#
|
|
227
|
-
|
|
228
|
-
|
|
177
|
+
# Admin (manual only)
|
|
178
|
+
set_admin(client_id, by_admin)
|
|
179
|
+
remove_admin(client_id, by_admin)
|
|
229
180
|
```
|
|
230
181
|
|
|
231
|
-
##
|
|
182
|
+
## Custom Trust Policies
|
|
183
|
+
|
|
184
|
+
### Option 1: Use Preset
|
|
232
185
|
|
|
233
|
-
### Development Mode
|
|
234
186
|
```python
|
|
235
|
-
#
|
|
236
|
-
connectonion.set_default_trust("open")
|
|
187
|
+
host(agent, trust="careful") # Uses prompts/trust/careful.md
|
|
237
188
|
```
|
|
238
189
|
|
|
239
|
-
###
|
|
190
|
+
### Option 2: Custom Markdown File
|
|
191
|
+
|
|
240
192
|
```python
|
|
241
|
-
|
|
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
|
-
###
|
|
196
|
+
### Option 3: Custom TrustAgent
|
|
197
|
+
|
|
247
198
|
```python
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
208
|
+
## Environment-Based Defaults
|
|
209
|
+
|
|
255
210
|
```python
|
|
256
|
-
#
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
##
|
|
219
|
+
## List Management
|
|
269
220
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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: `"
|
|
234
|
+
A: `"careful"` - verify strangers, allow contacts.
|
|
280
235
|
|
|
281
|
-
**Q:
|
|
282
|
-
A:
|
|
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:
|
|
285
|
-
A:
|
|
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:
|
|
288
|
-
A:
|
|
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
|
-
|
|
291
|
-
|
|
245
|
+
```python
|
|
246
|
+
# Same agent, different trust
|
|
247
|
+
host(agent, trust="open") # Dev
|
|
248
|
+
host(agent, trust="strict") # Prod
|
|
249
|
+
```
|