Agents
Agent-to-agent delegation using the A2A protocol.
The Agents package enables agent-to-agent (A2A) delegation — allowing one AI agent to securely delegate tasks to another while maintaining the user’s identity and authorization context.
When to Use
Section titled “When to Use”- Building agents that delegate work to other specialized agents
- Exposing an agent as a service that other agents can call
- Integrating with CrewAI or other agent frameworks
- Implementing the A2A protocol with Keycard authentication
Installation
Section titled “Installation”pip install keycardai-agentsKey Exports
Section titled “Key Exports”keycardai.agents
Section titled “keycardai.agents”| Export | Description |
|---|---|
AgentServiceConfig | Configuration for an agent service (name, URL, capabilities) |
AgentServer | Host an agent as an A2A-compatible service |
AgentClient | Call remote agents via A2A protocol |
DelegationClient | Handle delegated OAuth token exchange between agents |
ServiceDiscovery | Discover available agent services |
serve_agent | Convenience function to start an agent server |
crewai | Optional CrewAI framework integration |
Quick Start
Section titled “Quick Start”Serve an Agent
Section titled “Serve an Agent”from keycardai.agents import AgentServiceConfig, AgentServer, serve_agent
config = AgentServiceConfig( name="Research Agent", description="Searches the web and summarizes findings", url="http://localhost:9000",)
async def handle_task(task): # Process the delegated task return {"result": "Research complete"}
server = AgentServer(config=config, handler=handle_task)serve_agent(server)Call a Remote Agent
Section titled “Call a Remote Agent”from keycardai.agents import AgentClient, ServiceDiscovery
# Discover available agentsdiscovery = ServiceDiscovery(zone_url="https://your-zone.keycard.ai")agents = await discovery.list_agents()
# Call a remote agentclient = AgentClient(agent_url="http://localhost:9000")result = await client.send_task( task="Summarize the latest news on AI agents",)