ConnectOnionConnectOnion
Core Feature

Trust in ConnectOnion

Flexible, bidirectional trust configuration for agent interactions

Read: Why we chose "trust" as our keyword

Quick Start

main.py
1from connectonion import Agent, need 2 3# Simple trust levels 4translator = need("translate", trust="strict") # Production: verified only 5analyzer = need("analyze", trust="tested") # Default: test first 6scraper = need("scrape", trust="open") # Development: trust all 7 8# For your own agent 9agent = Agent( 10 name="my_service", 11 tools=[process_data], 12 trust="strict" # Who can use my services 13)

Three Forms of Trust

1. Trust Levels (String)

Simple predefined levels for common scenarios:

main.py
1# Development - trust everyone 2agent = need("service", trust="open") 3 4# Default - test before trusting 5agent = need("service", trust="tested") 6 7# Production - only verified/whitelisted 8agent = need("service", trust="strict")

2. Trust Policy (Natural Language)

Express complex requirements in plain English:

main.py
1# Inline policy 2translator = need("translate", trust=""" 3 I trust agents that: 4 - Pass capability tests 5 - Respond within 500ms 6 - Are on my whitelist OR from local network 7""") 8 9# From file 10translator = need("translate", trust="./trust_policy.md")

Example trust policy file:

# My Trust Requirements

I trust agents that meet ALL of these criteria:
- Successfully translate "Hello" to "Hola"
- Respond in less than 1 second
- Have processed at least 10 requests successfully

I immediately reject agents that:
- Fail basic capability tests
- Take longer than 5 seconds
- Are on my blacklist

3. Trust Agent

For maximum control, use a custom trust agent:

main.py
1# Create a trust agent with verification tools 2trust_agent = Agent( 3 name="my_guardian", 4 tools=[ 5 check_whitelist, 6 verify_capability, 7 measure_response_time, 8 check_reputation 9 ], 10 system_prompt=""" 11 You verify other agents before allowing interaction. 12 Be strict with payment processors, relaxed with read-only services. 13 """ 14) 15 16# Use it for your agent 17my_agent = Agent( 18 name="my_service", 19 tools=[process_payment], 20 trust=trust_agent # My guardian protects me 21) 22 23# And for discovering services 24payment = need("payment processor", trust=trust_agent)

Bidirectional Trust

The same trust parameter works in both directions:

main.py
1# As a SERVICE provider (who can use me?) 2alice_agent = Agent( 3 name="alice_translator", 4 tools=[translate], 5 trust="tested" # Users must pass my tests 6) 7 8# As a SERVICE consumer (who do I trust?) 9translator = need("translate", trust="strict") # I only use verified services 10 11# Both trust requirements must be satisfied for interaction!

Trust Flow Example

main.py
1# Alice creates a translation service 2alice = Agent( 3 name="alice_translator", 4 tools=[translate], 5 trust="tested" # Test users before serving them 6) 7share(alice) 8 9# Bob looks for a translator 10translator = need( 11 "translate to Spanish", 12 trust="strict" # Bob only uses verified services 13) 14 15# What happens: 16# 1. Bob's trust agent evaluates Alice (strict check) 17# 2. Alice's trust agent evaluates Bob (test required) 18# 3. Both must approve for connection to succeed

Environment-Based Defaults

ConnectOnion automatically adjusts trust based on environment:

main.py
1# No trust parameter needed - auto-detected! 2translator = need("translate") 3 4# In development (localhost, Jupyter) 5# → Defaults to trust="open" 6 7# In test files (test_*.py) 8# → Defaults to trust="tested" 9 10# In production 11# → Defaults to trust="strict" 12 13# Override when needed 14translator = need("translate", trust="open") # Force open even in production

Common Patterns

Development Mode

main.py
1# Trust everyone for rapid development 2connectonion.set_default_trust("open")

Production Mode

main.py
1# Strict verification for production 2payment = need("payment processor", trust="strict") 3sensitive = need("data processor", trust="strict")

Mixed Trust

main.py
1# Different trust for different services 2scraper = need("web scraper", trust="open") # Low risk 3analyzer = need("analyze data", trust="tested") # Medium risk 4payment = need("process payment", trust="strict") # High risk

Security Best Practices

  • Production = Strict: Always use trust="strict" in production
  • Test Sensitive Operations: Payment, data modification, etc.
  • Whitelist Critical Services: Manually verify and whitelist
  • Monitor Trust Decisions: Log all trust evaluations
  • Regular Audits: Review whitelist and trust policies

FAQ

Q: What's the default trust level?

A: "tested" - agents are tested before first use

Q: Can I change trust after agent creation?

A: Yes: agent.trust = new_trust_agent

Q: How do trust agents communicate?

A: They're regular ConnectOnion agents - they talk naturally

Q: What if both agents have strict trust?

A: Both requirements must be met - most restrictive wins

Q: Can I disable trust completely?

A: Yes: trust="open" accepts everyone without checks

Choose Your Trust Level

Development?

trust="open"

Trust everyone, iterate fast

Testing/Staging?

trust="tested"

Test before trusting (default)

Production?

trust="strict"

Verified agents only

Security Note

Always use trust="strict" in production environments to prevent unauthorized access.