Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy, evaluate, and manage AI agents end-to-end on Microsoft Azure AI Foundry
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
foundry-agent/invoke/references/file-operations.md
1# File Operations23Manage files within a hosted agent session. All file operations require an active session with a running sandbox.45## Overview67Hosted agent sessions provide a persistent filesystem rooted at `$HOME` (`/home/session`). Files written to this path survive across requests within the same session. Use the session file tools to upload input data, download outputs, and manage the session filesystem externally.89> ⚠️ **Warning:** All file paths are relative to `$HOME`. For example, `filePath: '/data/input.csv'` maps to `/home/session/data/input.csv` inside the container.1011## MCP Tool Details1213### Upload File1415Use `session_file_upload` to write a file into the session:1617| Parameter | Required | Description |18|-----------|----------|-------------|19| `projectEndpoint` | ✅ | AI Foundry project endpoint |20| `agentName` | ✅ | Name of the hosted agent |21| `sessionId` | ✅ | Active session ID |22| `filePath` | ✅ | Destination path (e.g., `/data/input.csv`) |23| `contentBase64` | ✅ | File content as a base64-encoded string |2425> 💡 **Tip:** For text files, encode the content to base64 before passing it. For binary files (images, PDFs), read the raw bytes and base64-encode them.2627### Download File2829Use `session_file_download` to retrieve a file from the session:3031| Parameter | Required | Description |32|-----------|----------|-------------|33| `projectEndpoint` | ✅ | AI Foundry project endpoint |34| `agentName` | ✅ | Name of the hosted agent |35| `sessionId` | ✅ | Active session ID |36| `filePath` | ✅ | Path to the file to download (e.g., `/data/output.csv`) |3738Returns: File content as a base64-encoded string.3940### List Files4142Use `session_file_list` to browse the session filesystem:4344| Parameter | Required | Description |45|-----------|----------|-------------|46| `projectEndpoint` | ✅ | AI Foundry project endpoint |47| `agentName` | ✅ | Name of the hosted agent |48| `sessionId` | ✅ | Active session ID |49| `path` | ❌ | Directory path to list (defaults to root `/`) |5051Returns: List of files and directories with metadata.5253### Delete File5455Use `session_file_delete` to remove a file or directory:5657| Parameter | Required | Description |58|-----------|----------|-------------|59| `projectEndpoint` | ✅ | AI Foundry project endpoint |60| `agentName` | ✅ | Name of the hosted agent |61| `sessionId` | ✅ | Active session ID |62| `filePath` | ✅ | Path to delete |63| `recursive` | ❌ | Set `true` to recursively delete a directory and its contents (default `false`) |6465> ⚠️ **Warning:** Non-recursive delete on a non-empty directory will fail. Use `recursive: true` for directories with contents.6667### Get File Metadata6869Use `session_file_stat` to inspect a file or directory:7071| Parameter | Required | Description |72|-----------|----------|-------------|73| `projectEndpoint` | ✅ | AI Foundry project endpoint |74| `agentName` | ✅ | Name of the hosted agent |75| `sessionId` | ✅ | Active session ID |76| `filePath` | ✅ | Path to inspect |7778Returns: File name, size, whether it is a directory, and last modified time.7980### Create Directory8182Use `session_file_mkdir` to create directories:8384| Parameter | Required | Description |85|-----------|----------|-------------|86| `projectEndpoint` | ✅ | AI Foundry project endpoint |87| `agentName` | ✅ | Name of the hosted agent |88| `sessionId` | ✅ | Active session ID |89| `path` | ✅ | Directory path to create (e.g., `/data/results`) |90| `createParents` | ❌ | Create parent directories if needed (default `true`) |91| `mode` | ❌ | Unix permission mode (e.g., `755`). Uses system default if omitted |9293## Common Patterns9495### Upload Input → Invoke → Download Output9697```text981. session_create → get sessionId992. session_file_mkdir → create /data/input/1003. session_file_upload → upload input files to /data/input/1014. agent_invoke → tell agent to process /data/input/1025. session_file_list → check /data/output/ for results1036. session_file_download → retrieve output files1047. session_delete → clean up when done105```106107### Check Agent-Generated Files108109```text1101. session_file_list → browse $HOME to see what the agent created1112. session_file_stat → check size/type of specific files1123. session_file_download → retrieve files of interest113```114115## Storage Limits116117- Maximum `$HOME` size: **10 GiB** per session118- Files outside `$HOME` (e.g., `/tmp`) are ephemeral and may be cleared between requests119120## Error Handling121122| Error | Cause | Resolution |123|-------|-------|------------|124| Session not active | Session expired or not yet running | Use `session_get` to check status; create a new session if expired |125| File not found | Invalid path or file does not exist | Use `session_file_list` to verify the path |126| Directory not empty | Non-recursive delete on a directory with contents | Use `recursive: true` |127| Storage limit exceeded | `$HOME` exceeds 10 GiB | Delete unnecessary files with `session_file_delete` |128