AgentConnect is an open-source SDK implementation of the Agent Network Protocol (ANP).
The goal of Agent Network Protocol (ANP) is to become the HTTP of the Intelligent Agent Internet Era, building an open, secure, and efficient collaborative network for billions of intelligent agents.
OpenANP is the simplest way to build ANP agents. Here's a complete server in just a few lines:
from fastapi import FastAPI
from anp.openanp import AgentConfig, anp_agent, interface
@anp_agent(AgentConfig(
name="My Agent",
did="did:wba:example.com:agent",
prefix="/agent",
))
class MyAgent:
@interface
async def hello(self, name: str) -> str:
return f"Hello, {name}!"
app = FastAPI()
app.include_router(MyAgent.router())Run: uvicorn app:app --port 8000
from anp.openanp import RemoteAgent
agent = await RemoteAgent.discover("http://localhost:8000/agent/ad.json", auth)
result = await agent.hello(name="World") # "Hello, World!"| Endpoint | Description |
|---|---|
GET /agent/ad.json |
Agent Description document |
GET /agent/interface.json |
OpenRPC interface document |
POST /agent/rpc |
JSON-RPC 2.0 endpoint |
π Full examples: OpenANP Examples
The most elegant and minimal SDK for building ANP agents:
from anp.openanp import anp_agent, interface, RemoteAgent
# Server: Build your agent
@anp_agent(AgentConfig(name="Hotel", did="did:wba:...", prefix="/hotel"))
class HotelAgent:
@interface
async def search(self, query: str) -> dict:
return {"results": [...]}
# Client: Call remote agents
agent = await RemoteAgent.discover("https://hotel.example.com/ad.json", auth)
result = await agent.search(query="Tokyo")Features:
- Decorator-based:
@anp_agent+@interface= complete agent - Auto-generated: ad.json, interface.json, JSON-RPC endpoint
- Context Injection: Automatic session and DID management
- LLM Integration: Built-in OpenAI Tools format export
π Full Documentation: OpenANP README
Crawler-style SDK for fetching and parsing ANP documents (like a web crawler for ANP):
from anp.anp_crawler import ANPCrawler
# Initialize crawler with DID authentication
crawler = ANPCrawler(
did_document_path="path/to/did.json",
private_key_path="path/to/key.pem"
)
# Crawl agent description and get OpenAI Tools format
content, tools = await crawler.fetch_text("https://example.com/ad.json")
# Execute discovered tools
result = await crawler.execute_tool_call("search_poi", {"query": "Beijing"})
# Or call JSON-RPC directly
result = await crawler.execute_json_rpc(
endpoint="https://example.com/rpc",
method="search",
params={"query": "hotel"}
)Features:
- Crawler Style: Fetch and parse ANP documents like a web crawler
- OpenAI Tools Format: Converts interfaces for LLM integration
- Direct JSON-RPC: Call methods without interface discovery
- No LLM Required: Deterministic data collection
π Full Documentation: ANP Crawler README
| Feature | RemoteAgent | ANPCrawler |
|---|---|---|
| Style | Proxy object (like local methods) | Crawler (fetch documents) |
| Usage | agent.search(query="Tokyo") |
crawler.execute_tool_call("search", {...}) |
| Type Safety | Full type hints, exceptions | Dict-based returns |
| Best For | Agent-to-agent calls in code | LLM tool integration, data collection |
# RemoteAgent: Methods feel like local calls
agent = await RemoteAgent.discover(url, auth)
result = await agent.search(query="Tokyo") # Like calling a local method
# ANPCrawler: Crawler-style document fetching
crawler = ANPCrawler(did_path, key_path)
content, tools = await crawler.fetch_text(url) # Fetch and parse documents
result = await crawler.execute_tool_call("search", {"query": "Tokyo"})pip install anp# Clone the repository
git clone https://github.com/agent-network-protocol/AgentConnect.git
cd AgentConnect
# Setup environment with UV
uv sync
# Install with optional dependencies
uv sync --extra api # FastAPI/OpenAI integration
uv sync --extra dev # Development tools
# Run examples
uv run python examples/python/did_wba_examples/create_did_document.py| Module | Description | Documentation |
|---|---|---|
| OpenANP | Decorator-driven agent development (recommended) | README |
| ANP Crawler | Lightweight discovery & interaction SDK | README |
| FastANP | FastAPI plugin framework | README |
| AP2 | Agent Payment Protocol v2 | README |
| Authentication | DID-WBA identity authentication | Examples |
Location: examples/python/openanp_examples/
| File | Description | Complexity |
|---|---|---|
minimal_server.py |
Minimal server (~30 lines) | β |
minimal_client.py |
Minimal client (~25 lines) | β |
advanced_server.py |
Full features (Context, Session, Information) | βββ |
advanced_client.py |
Full client (discovery, LLM integration) | βββ |
# Terminal 1: Start server
uvicorn examples.python.openanp_examples.minimal_server:app --port 8000
# Terminal 2: Run client
uv run python examples/python/openanp_examples/minimal_client.pyLocation: examples/python/anp_crawler_examples/
# Quick start
uv run python examples/python/anp_crawler_examples/simple_amap_example.py
# Complete demonstration
uv run python examples/python/anp_crawler_examples/amap_crawler_example.pyLocation: examples/python/did_wba_examples/
# Create DID document
uv run python examples/python/did_wba_examples/create_did_document.py
# Authentication demonstration
uv run python examples/python/did_wba_examples/authenticate_and_verify.pyLocation: examples/python/fastanp_examples/
# Simple agent
uv run python examples/python/fastanp_examples/simple_agent.py
# Hotel booking agent (full example)
uv run python examples/python/fastanp_examples/hotel_booking_agent.pyLocation: examples/python/ap2_examples/
# Complete AP2 flow (merchant + shopper)
uv run python examples/python/ap2_examples/ap2_complete_flow.pyExplore the agent network using natural language: ANP Network Explorer
uv run python tools/did_generater/generate_did_doc.py <did> [--agent-description-url URL]- Author: GaoWei Chang
- Email: chgaowei@gmail.com
- Website: https://agent-network-protocol.com/
- Discord: https://discord.gg/sFjBKTY7sB
- GitHub: https://github.com/agent-network-protocol/AgentNetworkProtocol
- WeChat: flow10240
This project is open-sourced under the MIT License. See LICENSE file for details.
Copyright (c) 2024 GaoWei Chang
