Overview
The ACP SDK provides methods for agents to read and write files in the client’s file system. These operations are only available if the client advertises the corresponding capabilities during initialization.Reading Files
ThereadTextFile method reads content from a text file:
string
required
The session ID making the request
string
required
Absolute path to the file to read
string
required
The file contents as a string
Only available if the client advertises the
fs.readTextFile capability during initialization.Example
All paths in the protocol should be absolute paths.
Writing Files
ThewriteTextFile method writes content to a text file:
string
required
The session ID making the request
string
required
Absolute path to the file to write
string
required
The content to write to the file
Only available if the client advertises the
fs.writeTextFile capability during initialization.Example
Error Handling
Handle errors appropriately when working with file system operations:Error Codes
number
Resource not found - the file does not exist
number
Internal error - an error occurred while reading or writing the file
Security Considerations
Path Validation
Ensure paths are absolute and within expected boundaries:Permission Requests
Request user permission before writing sensitive files:Capability Checking
Always verify capabilities before attempting operations:Complete Example
Here’s a complete example that demonstrates safe file operations:Best Practices
Check Capabilities
Always verify the client supports file operations before attempting them
Use Absolute Paths
All paths in the protocol must be absolute, not relative
Handle Errors
Gracefully handle file not found and permission errors
Request Permission
Request user permission before writing sensitive files