Module 07: Agent Requests (Client Side)
Handle file read/write requests from agents on the client side.What Youâll Learn
- Registering
readTextFileHandlerandwriteTextFileHandler - Advertising file system capabilities, derived from the handlers themselves
- The inverted request flow: agents request, clients serve
Inverted Request Flow
In ACP, the request direction is inverted for file operations compared to traditional client-server: the agent requests files from the client. This allows agents to access the userâs local filesystem through a controlled interface â the client decides which files to expose and how to handle writes.The Code
To enable this, the client registers file handlers on its builder. As of 0.80.0, thatâs enough: the two handlers below are also what the client advertises, soinitialize() sends fs.readTextFile and
fs.writeTextFile because these handlers are registered, with no separate clientCapabilities(..)
call needed. When the agent calls context.readFile() or context.writeFile(), these handlers are
invoked:
As of 0.80.0,
initialize(InitializeRequest) is removed: capabilities are set only on the client builder, and initialize() sends them. See the 0.80.0 migration guide.Source Code
View on GitHubRunning the Example
Requires the Grok CLI on yourPATH, signed in once with grok login. The module launches it as grok agent --always-approve stdio; no API key is needed.