A robust and secure implementation of the Agent Name Service, providing a universal directory for AI agents.
The Agent Name Service (ANS) is a directory service for AI agents that enables:
- Structured agent naming with protocol support
- Secure agent registration and discovery
- Public Key Infrastructure (PKI) integration
- Protocol adapters for different agent communication protocols
- Version negotiation for agent compatibility
ANS provides a way for agents to register their capabilities and for other agents to discover and securely communicate with them.
ANS is designed to support multiple agent communication protocols:
- A2A (Agent2Agent): Google's protocol for agent interoperability, enabling agents to discover and communicate with each other in a standardized way.
- MCP (Model Context Protocol): Anthropic's protocol for model-tool interaction, facilitating integration between foundation models and tools.
The protocol adapter layer allows ANS to be extended to support additional protocols in the future.
The ANS consists of several core components:
The structured naming system for agents follows the format:
Protocol://AgentID.agentCapability.Provider.vVersion,Extension
For example:
a2a://chatbot.conversation.openai.v1.0.0
The CA issues and manages certificates for agents and the ANS registry itself. It:
- Issues certificates based on Certificate Signing Requests (CSRs)
- Maintains a list of revoked certificates
- Verifies certificate chains
The RA manages agent registration by:
- Validating registration requests
- Forwarding CSRs to the CA
- Enforcing naming policies
The registry maintains a database of registered agents and handles:
- Storing agent information
- Resolving ANS names to endpoints
- Signing endpoint records
- Finding agents by criteria (protocol, capability, provider)
Protocol adapters provide a way to handle different agent communication protocols:
- A2A (Agent-to-Agent): For direct agent communication
- MCP (Model Capabilities Protocol): For ML model capabilities
- Structured agent naming with protocol support
- Secure agent registration and resolution
- Public Key Infrastructure (PKI) integration
- Protocol adapter layer for different agent protocols
- RESTful API interface
- Persistent storage with SQLite (extensible to other databases)
- Version negotiation for backward compatibility
- Certificate revocation for security
-
Clone the repository:
git clone https://github.com/yourusername/ans.git cd ans -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Initialize the database:
python -m ans.db.init_db
-
Start the API server:
python run_ans.py
-
Access the API documentation at
http://localhost:8000/docs
from examples.client import register_agent, create_csr, generate_key_pair
# Generate key pair and CSR
private_key, public_key = generate_key_pair()
csr = create_csr("my-agent", private_key)
# Register agent
response = register_agent(
agent_id="my-agent",
ans_name="a2a://my-agent.chat.example.v1.0.0",
capabilities=["chat", "question-answering"],
protocol_extensions={
"message_format": "json",
"supported_actions": [
{
"name": "send_message",
"version": "1.0.0"
}
],
"security_level": "basic"
},
endpoint="https://my-agent.example.com/api",
csr_pem=csr
)
# Save certificate
with open("my-agent.cert", "w") as f:
f.write(response["certificate"])from examples.client import resolve_agent, verify_endpoint_record
# Resolve agent
endpoint_record = resolve_agent("a2a://my-agent.chat.example.v1.0.0")
# Verify endpoint record signature
if verify_endpoint_record(endpoint_record):
# Use the agent's endpoint
endpoint = endpoint_record["data"]["endpoint"]
print(f"Agent endpoint: {endpoint}")
else:
print("Invalid endpoint record signature")import requests
# Get all agents using the A2A protocol
response = requests.get("http://localhost:8000/agents?protocol=a2a")
a2a_agents = response.json()["agents"]
# Get all agents using the MCP protocol
response = requests.get("http://localhost:8000/agents?protocol=mcp")
mcp_agents = response.json()["agents"]ans/
├── core/ # Core ANS components
│ ├── agent.py # Agent representation
│ ├── ans_name.py # ANS name handling
│ ├── agent_registry.py # Agent registry
│ └── registration_authority.py # Registration authority
├── crypto/ # Cryptographic operations
│ ├── certificate.py # Certificate operations
│ └── certificate_authority.py # Certificate authority
├── db/ # Database models and operations
│ ├── models.py # SQLAlchemy models
│ └── init_db.py # Database initialization
├── api/ # API endpoints
│ └── main.py # FastAPI application
├── schemas/ # JSON schemas
├── adapters/ # Protocol adapters
│ ├── base.py # Protocol adapter base class
│ └── a2a.py # Agent-to-Agent protocol adapter
│ └── mcp.py # Model Context Protocol adapter
└── tests/ # Test suite
├── test_ans.py # Basic ANS tests
├── test_crypto.py # Cryptography tests
├── test_protocol_adapters.py # Protocol adapter tests
└── test_resolution.py # ANS resolution tests
POST /register: Register a new agentPOST /renew: Renew an agent's registrationPOST /revoke: Revoke an agent's registrationPOST /resolve: Resolve an agent's ANS name to its endpointGET /agents: List agents matching criteriaGET /health: Health check endpoint
Run the test suite:
pytestRun specific tests:
pytest ans/tests/test_crypto.py # Run cryptography tests
pytest ans/tests/test_protocol_adapters.py # Run protocol adapter testsThe ANS implements several security measures while maintaining public access like DNS:
-
Certificate-based Authentication for Agents
- All agents must have valid certificates issued by the ANS CA
- Certificates are verified during registration and resolution
- This secures the agent identity without restricting public API access
-
Signed Endpoint Records
- Endpoint records are signed by the ANS registry
- Signatures are verified by clients to prevent tampering
- Ensures data integrity across the network
-
Certificate Revocation
- Compromised certificates can be revoked
- Revocation status is checked during certificate validation
- Provides ability to remove compromised agents
-
Input Validation
- All API inputs are validated against JSON schemas
- ANS names are strictly validated for format compliance
- Prevents injection attacks and malformed data
-
Rate Limiting
- Configurable rate limits per endpoint
- Prevents abuse while allowing legitimate usage
- Different limits for different operations based on resource impact
-
Comprehensive Audit Logging
- All API access is logged for auditing purposes
- Certificate operations (issuance, renewal, revocation) are tracked
- Security events and errors are documented for incident response
-
Secure Transport
- HTTPS should be used in production
- TLS configuration should follow best practices
- Prevents man-in-the-middle attacks
- Format code:
black ans/ - Type checking:
mypy ans/ - Run linting:
pylint ans/
MIT License