Skip to content

Commit 1275ca4

Browse files
feat: enhance Joy Trust integration for secure agent handoffs (fixes MervinPraison/PraisonAI#1324) (#16)
Enhanced Joy Trust tool with native integration features: - Added automatic handoff trust verification - Environment variable configuration (PRAISONAI_TRUST_PROVIDER=joy) - @trust_verified_handoff decorator for secure delegation - Handoff safety verification with recommendations - Configurable trust score thresholds and caching - Fallback handling for robust operation - Comprehensive examples and documentation - Updated tests for new functionality Addresses feature request for native Joy Trust integration to make trust verification automatic and free for PraisonAI users. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: MervinPraison <454862+MervinPraison@users.noreply.github.com> Co-authored-by: praisonai-triage-agent[bot] <praisonai-triage-agent[bot]@users.noreply.github.com>
1 parent 324d345 commit 1275ca4

File tree

5 files changed

+900
-32
lines changed

5 files changed

+900
-32
lines changed

docs/joy_trust_integration.md

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
# Joy Trust Integration for PraisonAI
2+
3+
Native Joy Trust Network integration for secure agent handoffs in PraisonAI.
4+
5+
## Overview
6+
7+
The Joy Trust integration provides automatic trust verification for agent handoffs, ensuring that tasks are only delegated to verified, trustworthy agents. This integration builds on the existing Joy Trust Network documentation and provides seamless, zero-configuration security for multi-agent workflows.
8+
9+
## Features
10+
11+
- **Automatic Trust Verification**: Environment variable configuration for seamless integration
12+
- **Handoff Safety Checks**: Verify agent trustworthiness before delegation
13+
- **Decorator-based Security**: `@trust_verified_handoff` decorator for secure functions
14+
- **Configurable Thresholds**: Set minimum trust scores for different use cases
15+
- **Caching**: Built-in result caching to reduce API calls
16+
- **Fallback Handling**: Graceful degradation when trust verification fails
17+
18+
## Quick Start
19+
20+
### 1. Environment Variable Configuration
21+
22+
```bash
23+
# Enable trust verification for all agents
24+
export PRAISONAI_TRUST_PROVIDER=joy
25+
26+
# Set minimum trust score threshold (default: 3.0)
27+
export PRAISONAI_TRUST_MIN_SCORE=3.5
28+
29+
# Enable automatic handoff verification (default: true)
30+
export PRAISONAI_TRUST_AUTO_VERIFY=true
31+
32+
# Optional: Set Joy Trust API key for enhanced features
33+
export JOY_TRUST_API_KEY=your_api_key_here
34+
```
35+
36+
### 2. Basic Usage
37+
38+
```python
39+
from praisonai_tools import check_trust_score, verify_handoff_safety
40+
41+
# Check an agent's trust score
42+
result = check_trust_score("researcher_agent", min_score=3.0)
43+
print(f"Trust Score: {result['trust_score']}")
44+
print(f"Safe to use: {result['meets_threshold']}")
45+
46+
# Verify handoff safety with recommendations
47+
verification = verify_handoff_safety("data_analyst", min_score=3.5)
48+
print(f"Handoff Safe: {verification['handoff_safe']}")
49+
print(f"Recommendation: {verification['recommendation']}")
50+
```
51+
52+
### 3. Decorator-based Security
53+
54+
```python
55+
from praisonai_tools import trust_verified_handoff
56+
57+
@trust_verified_handoff(min_score=4.0)
58+
def delegate_analysis_task(agent_name: str, data: dict):
59+
# This function only executes if the agent meets trust requirements
60+
return perform_delegation(agent_name, data)
61+
62+
# The decorator automatically checks trust before execution
63+
result = delegate_analysis_task("expert_analyst", {"data": "..."})
64+
```
65+
66+
## API Reference
67+
68+
### Functions
69+
70+
#### `check_trust_score(agent_name: str, min_score: float = 3.0) -> dict`
71+
72+
Check an agent's trust score on the Joy Trust Network.
73+
74+
**Parameters:**
75+
- `agent_name`: Name/identifier of the agent to check
76+
- `min_score`: Minimum acceptable trust score
77+
78+
**Returns:**
79+
```python
80+
{
81+
"agent_name": str,
82+
"trust_score": float,
83+
"verified": bool,
84+
"meets_threshold": bool,
85+
"threshold_used": float,
86+
"reputation": dict,
87+
"recommendations": int,
88+
"error": str | None
89+
}
90+
```
91+
92+
#### `verify_handoff_safety(agent_name: str, min_score: float = 3.0) -> dict`
93+
94+
Verify if it's safe to hand off to the specified agent.
95+
96+
**Parameters:**
97+
- `agent_name`: Target agent for handoff
98+
- `min_score`: Minimum acceptable trust score
99+
100+
**Returns:**
101+
```python
102+
{
103+
"agent_name": str,
104+
"trust_score": float,
105+
"verified": bool,
106+
"handoff_safe": bool,
107+
"recommendation": str,
108+
"threshold_used": float,
109+
"verification_time": float,
110+
"error": str | None
111+
}
112+
```
113+
114+
#### `trust_verified_handoff(min_score: float = 3.0)`
115+
116+
Decorator for automatic trust verification before function execution.
117+
118+
**Parameters:**
119+
- `min_score`: Minimum trust score required
120+
121+
**Usage:**
122+
```python
123+
@trust_verified_handoff(min_score=3.5)
124+
def my_delegation_function(agent_name, task):
125+
return delegate_task(agent_name, task)
126+
```
127+
128+
#### `is_trust_verification_enabled() -> bool`
129+
130+
Check if trust verification is enabled via environment variables.
131+
132+
#### `get_trust_config() -> TrustConfig`
133+
134+
Get current trust configuration from environment variables.
135+
136+
### Classes
137+
138+
#### `JoyTrustTool`
139+
140+
Enhanced tool class for Joy Trust Network verification.
141+
142+
```python
143+
from praisonai_tools import JoyTrustTool
144+
145+
tool = JoyTrustTool(api_key="optional_key")
146+
result = tool.check_trust("agent_name")
147+
```
148+
149+
#### `TrustConfig`
150+
151+
Configuration dataclass for Joy Trust integration.
152+
153+
```python
154+
from praisonai_tools.tools.joy_trust_tool import TrustConfig
155+
156+
config = TrustConfig.from_env()
157+
print(f"Enabled: {config.enabled}")
158+
print(f"Min Score: {config.min_score}")
159+
```
160+
161+
## Environment Variables
162+
163+
| Variable | Description | Default |
164+
|----------|-------------|---------|
165+
| `PRAISONAI_TRUST_PROVIDER` | Set to 'joy' to enable trust verification | None |
166+
| `PRAISONAI_TRUST_MIN_SCORE` | Minimum trust score threshold | 3.0 |
167+
| `PRAISONAI_TRUST_AUTO_VERIFY` | Enable automatic handoff verification | true |
168+
| `PRAISONAI_TRUST_TIMEOUT` | Request timeout in seconds | 10.0 |
169+
| `PRAISONAI_TRUST_CACHE_DURATION` | Cache duration in seconds | 300 |
170+
| `PRAISONAI_TRUST_FALLBACK` | Allow fallback on errors | true |
171+
| `JOY_TRUST_API_KEY` | Joy Trust API key (optional) | None |
172+
173+
## Trust Score Ranges
174+
175+
The Joy Trust Network uses a 0-5 scale for trust scores:
176+
177+
- **4.5-5.0**: Excellent - Highly trusted, verified agents
178+
- **3.5-4.4**: Good - Reliable agents with good reputation
179+
- **2.5-3.4**: Moderate - Acceptable with caution
180+
- **1.0-2.4**: Low - Not recommended for important tasks
181+
- **0.0-0.9**: Very Low - Strongly discouraged
182+
183+
## Integration Patterns
184+
185+
### 1. Workflow-level Integration
186+
187+
```python
188+
import os
189+
from praisonai_tools import verify_handoff_safety
190+
191+
# Enable trust verification
192+
os.environ['PRAISONAI_TRUST_PROVIDER'] = 'joy'
193+
194+
def secure_workflow(agents: list, min_score: float = 3.0):
195+
trusted_agents = []
196+
197+
for agent in agents:
198+
verification = verify_handoff_safety(agent['name'], min_score)
199+
if verification['handoff_safe']:
200+
trusted_agents.append(agent)
201+
else:
202+
print(f"⚠️ Agent {agent['name']} failed trust check")
203+
204+
return trusted_agents
205+
```
206+
207+
### 2. Conditional Trust Checking
208+
209+
```python
210+
from praisonai_tools import is_trust_verification_enabled, check_trust_score
211+
212+
def delegate_with_optional_trust(agent_name: str, task: str):
213+
if is_trust_verification_enabled():
214+
trust_result = check_trust_score(agent_name)
215+
if not trust_result['meets_threshold']:
216+
return {"error": f"Agent {agent_name} doesn't meet trust requirements"}
217+
218+
return perform_delegation(agent_name, task)
219+
```
220+
221+
### 3. Custom Trust Policies
222+
223+
```python
224+
from praisonai_tools import JoyTrustTool
225+
from praisonai_tools.tools.joy_trust_tool import TrustConfig
226+
227+
# Create custom configuration
228+
custom_config = TrustConfig(
229+
enabled=True,
230+
min_score=4.0, # High security requirement
231+
timeout_seconds=5.0, # Fast timeout
232+
fallback_on_error=False # Strict mode
233+
)
234+
235+
tool = JoyTrustTool(config=custom_config)
236+
result = tool.verify_handoff_safety("critical_agent")
237+
```
238+
239+
## Error Handling
240+
241+
The integration provides robust error handling:
242+
243+
```python
244+
from praisonai_tools import check_trust_score
245+
246+
result = check_trust_score("unknown_agent")
247+
248+
if result['error']:
249+
print(f"Trust check failed: {result['error']}")
250+
251+
if result.get('fallback_used'):
252+
print("Using fallback behavior")
253+
else:
254+
print("Strict mode - blocking delegation")
255+
else:
256+
print(f"Trust verification successful: {result['trust_score']}")
257+
```
258+
259+
## Best Practices
260+
261+
1. **Start with moderate thresholds** (3.0-3.5) and adjust based on your security needs
262+
2. **Use environment variables** for configuration to avoid hardcoding values
263+
3. **Enable caching** in production to reduce API calls and improve performance
264+
4. **Set appropriate timeouts** based on your application's requirements
265+
5. **Use fallback mode** for non-critical operations to maintain availability
266+
6. **Monitor trust scores** and update agent permissions accordingly
267+
268+
## Troubleshooting
269+
270+
### Common Issues
271+
272+
1. **"httpx is required" error**: Install httpx with `pip install httpx` or `pip install praisonai-tools[marketplace]`
273+
2. **Connection timeouts**: Increase `PRAISONAI_TRUST_TIMEOUT` value
274+
3. **False negatives**: Check if agent names match Joy Trust Network entries exactly
275+
4. **API rate limits**: Enable caching with `PRAISONAI_TRUST_CACHE_DURATION`
276+
277+
### Debug Mode
278+
279+
Enable debug logging to troubleshoot issues:
280+
281+
```python
282+
import logging
283+
logging.basicConfig(level=logging.DEBUG)
284+
285+
from praisonai_tools import check_trust_score
286+
result = check_trust_score("debug_agent")
287+
```
288+
289+
## Contributing
290+
291+
To contribute to the Joy Trust integration:
292+
293+
1. Fork the PraisonAI-Tools repository
294+
2. Create a feature branch
295+
3. Add tests for new functionality
296+
4. Submit a pull request
297+
298+
## Support
299+
300+
- **Documentation**: [Joy Trust Network Docs](https://docs.praison.ai/joy-trust-network)
301+
- **Issues**: [PraisonAI-Tools Issues](https://github.com/MervinPraison/PraisonAI-Tools/issues)
302+
- **Community**: [PraisonAI Discord](https://discord.gg/praisonai)

0 commit comments

Comments
 (0)