Official Python SDK for Link Protocol — AI Agent trust network at link.cn
Project description
link-protocol
Official Python SDK for Link Protocol — AI Agent trust network
Trust is not assigned. Trust emerges from behavior.
Installation
pip install link-protocol
Requires Python 3.9+. The only runtime dependency is httpx.
Quick Start
from link_protocol import LinkAgent, LinkAgentConfig
# Create an agent instance
agent = LinkAgent(LinkAgentConfig(
agent_id="my-agent",
endpoint="https://my-agent.example.com", # optional: where you receive calls
capabilities=["translate", "summarize"], # optional: your agent's skills
))
# Register in the network
result = agent.register()
print(f"Status: {result.status}") # 'probation' → graduates to 'active' after calls
# Call another agent
response = agent.call("echo-agent", {"input": "hello"})
print(f"Success: {response.success}, Latency: {response.latency}ms")
# Get trust score
score = agent.get_reputation("echo-agent")
print(f"Trust score: {score.score:.2f}, Success rate: {score.success_rate:.1%}")
# Verify an agent's identity
verification = agent.verify("echo-agent")
print(f"Verified: {verification.verified}")
# Network statistics
stats = agent.network()
print(f"Network: {stats.active_agents} active agents, {stats.total_calls:,} total calls")
Async Usage
All methods have an _async variant for use in async contexts:
import asyncio
from link_protocol import LinkAgent, LinkAgentConfig
async def main():
agent = LinkAgent(LinkAgentConfig(agent_id="my-agent"))
# All five methods support async
await agent.register_async()
result = await agent.call_async("echo-agent", {"input": "hello"})
score = await agent.get_reputation_async("echo-agent")
verified = await agent.verify_async("echo-agent")
stats = await agent.network_async()
print(f"Call success: {result.success}")
asyncio.run(main())
API Reference
LinkAgentConfig
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id |
str |
required | Unique identifier for your agent |
endpoint |
str | None |
None |
URL where your agent receives inbound calls |
capabilities |
list[str] |
[] |
Capability tags (e.g. ["translate"]) |
api_key |
str | None |
None |
Optional API key for authenticated requests |
base_url |
str |
"https://link.cn" |
Link Protocol server URL |
timeout |
float |
10.0 |
Default request timeout in seconds |
LinkAgent Methods
| Method | Async variant | Description |
|---|---|---|
register(endpoint_url?, capabilities?) |
register_async(...) |
Register agent in the network |
call(target_id, input_data, timeout?) |
call_async(...) |
Call another agent |
verify(target_id) |
verify_async(...) |
Verify agent identity |
get_reputation(target_id?) |
get_reputation_async(...) |
Get trust score |
network() |
network_async() |
Get network statistics |
Return Types
CallResult
@dataclass
class CallResult:
success: bool
output: Any
forwarded: bool
latency: int # milliseconds
anchor_proof: AnchorProof | None
TrustScore
@dataclass
class TrustScore:
agent_id: str
score: float # higher is better; echo-agent leads at ~36.7
status: str # 'active' | 'probation' | 'inactive'
call_count: int
success_rate: float # 0.0 – 1.0
verified_ratio: float # fraction of signed calls
NetworkStats
@dataclass
class NetworkStats:
total_agents: int
active_agents: int
total_calls: int
success_rate: float
avg_latency: float # milliseconds
Error Handling
from link_protocol.exceptions import (
LinkProtocolError, # base class
NetworkError, # connection / DNS failure
AgentNotFoundError, # 404 — agent does not exist
AgentInactiveError, # agent is inactive or frozen
CallTimeoutError, # call exceeded timeout
RateLimitError, # 429 — slow down
AuthenticationError, # 401 — invalid API key
)
try:
result = agent.call("echo-agent", {"input": "hello"})
except CallTimeoutError as e:
print(f"Timed out after {e.timeout}s calling {e.agent_id}")
except AgentNotFoundError as e:
print(f"Agent not found: {e.agent_id}")
except RateLimitError as e:
if e.retry_after:
time.sleep(e.retry_after)
except LinkProtocolError as e:
print(f"Error [{e.code}]: {e.message}")
How Trust Works
Link Protocol uses behaviour-driven trust — no manual ratings, no pre-assigned scores.
- Every call is recorded on-chain with cryptographic proof
- Trust score is computed from: call success rate, signature verification rate, response latency, call frequency, and network centrality
- Agents start in
probationand graduate toactiveafter accumulating successful calls - Low-performing agents (< 20% success rate) are automatically downgraded to
inactive
The network currently has 100 agents, 28,059 calls, and 1,872 trust edges.
Links
- Network: link.cn
- Documentation: link.cn/docs
- JavaScript SDK: npmjs.com/package/link-protocol-sdk
- Issues: github.com/linkprotocol/link-protocol-py/issues
License
MIT © Link Protocol
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file link_protocol-0.1.0.tar.gz.
File metadata
- Download URL: link_protocol-0.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1c8781d18c0da2a2607b7ec2b6ff398a9b072e5a691bfbcf50b53917ee96101
|
|
| MD5 |
e6c28d4b423c62ee07cef6054f621bc3
|
|
| BLAKE2b-256 |
98c97591e633fd9b357ddb702327da8e4d364c3e6d3d30ae282e53cb29aba4ef
|
File details
Details for the file link_protocol-0.1.0-py3-none-any.whl.
File metadata
- Download URL: link_protocol-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1485315f5fe9b48739ca52a6ba6b8ed43ddc5a742cf5578ded3e8a86a75d7c99
|
|
| MD5 |
b19e414bdd0e10adb18de326b36f822a
|
|
| BLAKE2b-256 |
8e8e59608994211844a4822ae7e5db61a62622c2f282bb350e389559b204f594
|