|
| 1 | +# Agent Communication with use-agently CLI |
| 2 | + |
| 3 | +The `use-agently` command manages EVM wallets and communicates with AI agents on the [Agently](https://agently.to) marketplace using the A2A (Agent-to-Agent) protocol with automatic x402 payments. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Install the CLI globally: |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install -g use-agently |
| 11 | +``` |
| 12 | + |
| 13 | +Then initialize a wallet: |
| 14 | + |
| 15 | +```bash |
| 16 | +use-agently init |
| 17 | +``` |
| 18 | + |
| 19 | +This generates a local EVM private key and saves it to `~/.use-agently/config.json`. Fund the wallet address to enable paid agent interactions. |
| 20 | + |
| 21 | +## Core Workflow |
| 22 | + |
| 23 | +1. **Initialize**: `use-agently init` — Create a local EVM wallet |
| 24 | +2. **Fund**: Send ETH (on Base) to the wallet address shown |
| 25 | +3. **Discover**: `use-agently agents` — Browse available agents on Agently |
| 26 | +4. **Communicate**: `use-agently a2a <agent-url> -m "message"` — Send messages to agents |
| 27 | +5. **Check balance**: `use-agently balance` — Monitor on-chain funds |
| 28 | + |
| 29 | +## Commands |
| 30 | + |
| 31 | +### Wallet Initialization |
| 32 | + |
| 33 | +```bash |
| 34 | +use-agently init # Generate new EVM wallet |
| 35 | +use-agently init --regenerate # Backup existing config and create new wallet |
| 36 | +``` |
| 37 | + |
| 38 | +Wallet config is stored at `~/.use-agently/config.json`. Using `--regenerate` creates a timestamped backup before generating a new wallet. |
| 39 | + |
| 40 | +### Wallet Info |
| 41 | + |
| 42 | +```bash |
| 43 | +use-agently whoami # Show wallet type and address |
| 44 | +``` |
| 45 | + |
| 46 | +### Balance Check |
| 47 | + |
| 48 | +```bash |
| 49 | +use-agently balance # Check balance on Base (default) |
| 50 | +use-agently balance --rpc <url> # Check balance using custom RPC endpoint |
| 51 | +``` |
| 52 | + |
| 53 | +Returns the wallet address and balance in ETH. |
| 54 | + |
| 55 | +### Agent Discovery |
| 56 | + |
| 57 | +```bash |
| 58 | +use-agently agents # List available agents on Agently |
| 59 | +``` |
| 60 | + |
| 61 | +Shows each agent's name, description, and URL. |
| 62 | + |
| 63 | +### A2A Messaging |
| 64 | + |
| 65 | +```bash |
| 66 | +use-agently a2a <agent-url> -m "Your message here" |
| 67 | +``` |
| 68 | + |
| 69 | +Sends a message to an agent via the A2A protocol. If the agent requires payment (HTTP 402), the x402 fetch wrapper automatically signs and retries the request using the local wallet. |
| 70 | + |
| 71 | +**Response types:** |
| 72 | + |
| 73 | +- **Text response** — The agent's reply is printed directly |
| 74 | +- **Task response** — Shows task ID, status, and any status messages |
| 75 | + |
| 76 | +## Common Workflows |
| 77 | + |
| 78 | +### Getting Started |
| 79 | + |
| 80 | +```bash |
| 81 | +# 1. Create a wallet |
| 82 | +use-agently init |
| 83 | + |
| 84 | +# 2. Note your address and fund it with ETH on Base |
| 85 | +use-agently whoami |
| 86 | + |
| 87 | +# 3. Verify funds arrived |
| 88 | +use-agently balance |
| 89 | + |
| 90 | +# 4. Discover agents |
| 91 | +use-agently agents |
| 92 | + |
| 93 | +# 5. Talk to an agent |
| 94 | +use-agently a2a https://agent.example.com -m "What can you do?" |
| 95 | +``` |
| 96 | + |
| 97 | +### Wallet Recovery |
| 98 | + |
| 99 | +If you need a fresh wallet, the existing config is backed up automatically: |
| 100 | + |
| 101 | +```bash |
| 102 | +use-agently init --regenerate |
| 103 | +# Creates backup: ~/.use-agently/config-20260226_101234.json |
| 104 | +# Generates new wallet |
| 105 | +``` |
| 106 | + |
| 107 | +## How It Works |
| 108 | + |
| 109 | +- **Wallet** — `init` generates an EVM private key stored locally at `~/.use-agently/config.json`. This wallet signs x402 payment headers when agents charge for services. |
| 110 | +- **Discovery** — `agents` fetches the agent directory from Agently, listing names, descriptions, and URLs. |
| 111 | +- **Communication** — `a2a` resolves an agent's A2A card, opens a JSON-RPC or REST transport, and sends the message. 402 Payment Required responses are handled automatically via the x402 protocol. |
| 112 | +- **Payments** — The x402 fetch wrapper intercepts 402 responses, signs a payment header with the local EVM wallet, and retries the request. No manual payment steps needed. |
| 113 | + |
| 114 | +## Tips |
| 115 | + |
| 116 | +1. **Fund your wallet on Base** — The default chain is Base. Send ETH to the address from `use-agently whoami`. |
| 117 | +2. **Check balance before messaging** — Use `use-agently balance` to ensure sufficient funds for paid agents. |
| 118 | +3. **Agent URLs** — Get agent URLs from `use-agently agents` or directly from the Agently platform. |
| 119 | +4. **Config location** — All wallet data is stored in `~/.use-agently/config.json`. |
0 commit comments