Module 15: Agent Requests
Agents can request file operations and permissions from the client.
What You’ll Learn
- Reading files from the client with
context.readFile()
- Writing files with
context.writeFile()
- Requesting permissions with
context.requestPermission()
- The client-side handler pattern for responding to agent requests
The Agent
The prompt handler uses SyncPromptContext convenience methods:
The Client
The client registers handlers to respond to agent requests:
Throw exceptions from handlers for errors. The SDK converts exceptions to JSON-RPC error responses. Do not return error strings as content — agents will misinterpret them as file content.
Client Capabilities
The client must advertise file system support during initialization:
Agents can check capabilities before using them:
Source Code
View on GitHub
Running the Example
Next Module
Module 16: In-Memory Testing — test agents without subprocess launching.