-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtwo_agents.py
More file actions
70 lines (54 loc) · 2.3 KB
/
two_agents.py
File metadata and controls
70 lines (54 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Two agents interact: hire, attest, check reputation.
Shows the full AVP lifecycle:
1. Both agents register
2. Agent A searches for Agent B by capability
3. Agent A creates escrow (payment hold)
4. Agents interact (simulated)
5. Agent A attests Agent B positively
6. Agent B releases escrow (gets paid)
7. Both check reputations
Usage:
python examples/two_agents.py
"""
import asyncio
from agentveil import AVPAgent
AVP_URL = "http://localhost:8000"
def main():
# === Setup: Register both agents ===
print("=== Registering agents ===")
agent_a = AVPAgent.create(AVP_URL, name="agent_a_buyer")
agent_a.register(display_name="Supply Chain Buyer")
agent_a.publish_card(capabilities=["procurement", "supply_chain"], provider="anthropic")
agent_b = AVPAgent.create(AVP_URL, name="agent_b_router")
agent_b.register(display_name="Logistics Router")
agent_b.publish_card(capabilities=["logistics", "routing", "optimization"], provider="openai")
print(f"Agent A: {agent_a.did[:40]}...")
print(f"Agent B: {agent_b.did[:40]}...")
# === Agent A searches for logistics agent ===
print("\n=== Searching for logistics agents ===")
results = agent_a.search_agents(capability="logistics")
print(f"Found {len(results)} logistics agents")
# === Check Agent B's reputation before hiring ===
print("\n=== Checking reputation ===")
rep = agent_a.get_reputation(agent_b.did)
print(f"Agent B reputation: score={rep['score']}, confidence={rep['confidence']}")
print(f"Interpretation: {rep['interpretation']}")
# === Agent A attests Agent B after interaction ===
print("\n=== Submitting attestation ===")
att = agent_a.attest(
agent_b.did,
outcome="positive",
weight=0.9,
context="logistics_task",
)
print(f"Attestation submitted: {att['outcome']}, weight={att['weight']}")
# === Check reputations after attestation ===
print("\n=== Updated reputations ===")
rep_b = agent_a.get_reputation(agent_b.did)
print(f"Agent B: score={rep_b['score']:.3f}, confidence={rep_b['confidence']:.3f}")
rep_a = agent_b.get_reputation(agent_a.did)
print(f"Agent A: score={rep_a['score']:.3f}, confidence={rep_a['confidence']:.3f}")
print("\n=== Done ===")
if __name__ == "__main__":
main()