|
| 1 | +--- |
| 2 | +title: "Commands" |
| 3 | +description: "Advertise available slash commands to clients" |
| 4 | +--- |
| 5 | + |
| 6 | +Agents can advertise a set of slash commands that users can invoke. These commands provide quick access to specific agent capabilities and workflows. |
| 7 | + |
| 8 | +## Advertising commands |
| 9 | + |
| 10 | +After creating a session, the Agent **MAY** send a list of available commands via the `available_commands_update` session notification: |
| 11 | + |
| 12 | +```json |
| 13 | +{ |
| 14 | + "jsonrpc": "2.0", |
| 15 | + "method": "session/update", |
| 16 | + "params": { |
| 17 | + "sessionId": "sess_abc123def456", |
| 18 | + "update": { |
| 19 | + "sessionUpdate": "available_commands_update", |
| 20 | + "availableCommands": [ |
| 21 | + { |
| 22 | + "name": "web", |
| 23 | + "description": "Search the web for information", |
| 24 | + "input": { |
| 25 | + "hint": "query to search for" |
| 26 | + } |
| 27 | + }, |
| 28 | + { |
| 29 | + "name": "test", |
| 30 | + "description": "Run tests for the current project" |
| 31 | + }, |
| 32 | + { |
| 33 | + "name": "plan", |
| 34 | + "description": "Create a detailed implementation plan", |
| 35 | + "input": { |
| 36 | + "hint": "description of what to plan" |
| 37 | + } |
| 38 | + } |
| 39 | + ] |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +<ResponseField name="availableCommands" type="AvailableCommand[]"> |
| 46 | + The list of commands available in this session |
| 47 | +</ResponseField> |
| 48 | + |
| 49 | +### AvailableCommand |
| 50 | + |
| 51 | +<ResponseField name="name" type="string" required> |
| 52 | + The command name (e.g., "web", "test", "plan") |
| 53 | +</ResponseField> |
| 54 | + |
| 55 | +<ResponseField name="description" type="string" required> |
| 56 | + Human-readable description of what the command does |
| 57 | +</ResponseField> |
| 58 | + |
| 59 | +<ResponseField name="input" type="AvailableCommandInput"> |
| 60 | + Optional input specification for the command |
| 61 | +</ResponseField> |
| 62 | + |
| 63 | +### AvailableCommandInput |
| 64 | + |
| 65 | +Currently supports unstructured text input: |
| 66 | + |
| 67 | +<ResponseField name="hint" type="string" required> |
| 68 | + A brief description of the expected input |
| 69 | +</ResponseField> |
| 70 | + |
| 71 | +## Command lifecycle |
| 72 | + |
| 73 | +1. **Discovery**: The Agent sends available commands after session creation |
| 74 | +2. **Display**: The Client displays these commands in its UI (e.g., in a slash command menu) |
| 75 | +3. **Invocation**: When the user selects a command, the Client includes it in the prompt |
| 76 | +4. **Execution**: The Agent processes the command as part of the prompt |
| 77 | + |
| 78 | +Commands are not a separate protocol mechanism - they are simply a way for the Agent to advertise what slash commands it understands. The actual command invocation happens through the regular prompt mechanism. |
| 79 | + |
| 80 | +## Dynamic updates |
| 81 | + |
| 82 | +The Agent can update the list of available commands at any time during a session by sending another `available_commands_update` notification. This allows commands to be: |
| 83 | + |
| 84 | +- Added based on context (e.g., project type detection) |
| 85 | +- Removed when no longer relevant |
| 86 | +- Modified with updated descriptions or input hints |
| 87 | + |
| 88 | +Clients may also add their own local commands (e.g., authentication commands) to the list before displaying them to users. |
| 89 | + |
| 90 | +## Example usage |
| 91 | + |
| 92 | +When a user types `/web climate change` in the Client, it would send: |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "jsonrpc": "2.0", |
| 97 | + "id": 3, |
| 98 | + "method": "session/prompt", |
| 99 | + "params": { |
| 100 | + "sessionId": "sess_abc123def456", |
| 101 | + "prompt": { |
| 102 | + "type": "text", |
| 103 | + "text": "/web climate change" |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +The Agent recognizes the command prefix and processes it accordingly, potentially using web search tools to gather information about climate change. |
0 commit comments