Now inviting automation leaders: publish your playbook as a skill, under your own name. Publish yours →
Automation Skills
All skills/n8n binary and data official/AGENT_TOOL_BINARY
Reference · n8n binary and data official

AGENT_TOOL_BINARY

Part of n8n binary and data official. Install the skill and your agent reads this page when it needs the depth.

Agent tools and binary

Binary doesn't survive the agent tool boundary in either direction. Agent and tools communicate via JSON. This catches people twice:

  1. Inbound: user uploads a file. Agent can see it via vision, but tool calls don't carry the file.
  2. Outbound: tool generates a file. Result back to the agent is JSON, so binary can't be returned directly.

Same workaround shape: stage binary in storage, pass a key/URL through the JSON boundary, fetch on the other side.

The same boundary holds for first-class n8n Agents (n8n-agents-official): workflow tool inputs and results are JSON. What differs is the inbound side (from n8n source, not tested live): files sent to the Agent in chat reach the model directly, and on Telegram get_current_message_context returns the photo's chat_id and file_id, so a workflow tool can take those ids and fetch the file itself.

Inbound: passing user-uploaded binary into a tool

User pastes an image into chat. The chat trigger gives you a files[] array on the input. The agent itself can be configured with passthroughBinaryImages: true to let the LLM see the image (vision), but the tools cannot. Tool parameters are filled by fromAi() and fromAi() only handles strings/numbers/booleans/objects, not binary.

So if the agent needs to call a tool that operates on the file (image edit, OCR, document parse), the tool can't receive the file directly. You have to pre-stage it.

The pattern

[Chat Trigger]
    │
    │ files[]
    ▼
[IF: files empty?]
    ├── empty ──────────────────────────────────────► [AI Agent]
    └── not empty:
        [Split Out files]
          ↓
        [Generate hash for filename]
          ↓
        [Upload binary to private storage with hashed key]
          ↓
        [Merge back into main path]   ← synchronization barrier (see below)
          ↓
        [AI Agent]  ← system prompt is told the keys; set executeOnce: true
            │
            │ tool call with imageKey="abc123.png"
            ▼
        [Tool sub-workflow]
            ↓
          [Download from storage by key]
            ↓
          [Operate on binary (edit, OCR, etc.)]
            ↓
          [Upload result, return new key + URL]

Two pieces of plumbing that look optional and aren't

What goes in the system prompt

The agent needs to know which keys exist for this turn. Inject them:

## File Handling
Files passed in:
{{ JSON.stringify($('Chat Trigger').first().json.files.map((item, index) =>
    ({
        "originalFileName": item.fileName,
        "fileName": $('Generate Hash').all()[index].json.hash + "." + item.fileExtension
    })), null, 2) }}

CRITICAL: Use EXACTLY the `fileName` field as shown above when calling tools.

Two things to notice:

  1. Both names are listed. The original gives the model human context ("photo.png" tells it what kind of file), and the hashed name is what the tool actually needs.
  2. The "use EXACTLY". Without it, the model paraphrases ("photo.png" or "the user's image") and the tool can't find the file.

What the tool's fromAi parameter looks like

fromAi('imageName', 'storage reference for an existing image to operate on, or empty for a new generation. Format depends on backend: an object-storage key like "abc123.png", a Dropbox file ID, a Google Drive file ID. Use the exact key/ID shown in the system prompt; do not reconstruct.', 'string')

The description matters: it tells the agent what shape the value should take. Match the description to the backend the user actually wired up. The example above lists multiple shapes for illustration, but a real tool description names only the one the workflow uses.

Branching: new vs editing

If the tool can be invoked with OR without an existing file (e.g., "generate" vs "edit"), branch inside the tool's sub-workflow:

[Trigger: { imagePrompt, imageName, sessionId }]
   ↓
[IF: imageName empty?]
   ├── empty (generation request) ──► [Generate]
   └── not empty (edit request) ──► [Download from storage] → [Edit]
                                          ↓ (storage error)
                                          → [Fallback path]

The agent picks which mode by filling or not filling imageName in the tool call. Default to one tool with branching, since near-identical tools can confuse selection.

The viable two-tool variant. Two toolWorkflow nodes can point at the same sub-workflow with different parameter wiring: a Generate Image tool that hardcodes imageName: "" and an Edit Image tool that lets the agent fill imageName via fromAi(). The descriptions then differ ("generate from scratch" vs "edit existing"), giving the model a clearer pick than one tool with a "leave imageName empty for generate" rule. One sub-workflow, two front doors. Use this when the model keeps misfiring on the unified tool's discriminator parameter. Otherwise the unified tool is simpler.

passthroughBinaryImages: true on the agent

Set this when the agent should be able to see uploaded images (multimodal vision). It enables the LLM to receive the image as part of its prompt context.

Image-only. The flag handles images for vision-capable models. PDFs, audio, and video do not get vision through this setting. For those, the model only sees what you put in the system prompt (filename, type, the storage key) and must rely on a tool to extract content. For PDFs specifically, an OCR/parse tool is the standard route.

It does not help the tools. Tools still get only the parameters from fromAi, regardless of this setting. So you still need the upload-and-pass-key pattern if a tool needs to operate on the file.

The two settings work together:

Storage choice for inbound

Same options as outbound (next section), but a few inbound-specific notes:

Hash strategy: inbound vs outbound

Use different hash patterns at each end:

The two Crypto nodes you'll often see in this kind of workflow aren't a copy-paste mistake. One is for the inbound stable hash, the other for the outbound unique suffix.

Long-running tools (video generation, large batches)

Agent tool calls don't time out at the agent layer. A sub-workflow tool that takes 20 minutes returns whenever it returns, the agent waits. So for slow generation, the answer is the same as for any other tool: a sub-workflow tool with the slow node inside, options.binaryPropertyOutput: 'data' on the generator, upload to storage, return { url, key }.

The one place duration actually matters: the HTTP Request node has its own HTTP-level timeout (default 5 minutes). If your tool is an HTTP Request Tool calling a slow external API, bump options.timeout past the expected duration. Otherwise the HTTP call aborts mid-job, the upstream work keeps running, and the agent gets nothing.

Surface-specific seams: look up the platform's API docs

The examples in this ref use n8n Chat Trigger conventions: $('Chat Trigger').first().json.files[] on the way in, markdown image rendering (![]()) on the way out. These shapes aren't universal. Production chat surfaces (Slack, Discord, Microsoft Teams, Telegram, WhatsApp Business, custom webhooks, etc.) each have their own:

Don't guess from the canvas examples. Before wiring an inbound or outbound binary path on a production surface, look up the platform's official API docs and the n8n node's docs for that platform. Use WebSearch or WebFetch if you need to. Two specific things to check:

  1. The exact path to the file metadata in the trigger event payload, and whether downloading the URL needs auth headers.
  2. The exact shape the platform expects for an image / file in a reply (markdown? a JSON block? a separate upload call?).

Get those two right and the rest of the patterns in this ref carry over cleanly. Skip them and the workflow ships looking correct, then quietly fails on real messages.

Outbound: tool produces binary, agent needs to return it

When an agent tool produces a file (generated PDF, image, document), the tool's result back to the agent is JSON. Binary bytes don't fit naturally into JSON. They'd have to be base64-encoded into a JSON field, and they'd be huge, slowing every tool call and bloating the agent's context.

So agent tools effectively can't return raw binary. The binary lives in storage, and the tool returns a reference to it.

The pattern

[Agent calls tool]
    │
    ▼
[Tool sub-workflow]
    ↓
  [Generate or transform binary]
    ↓
  [Upload to storage with key]
    ↓
  [Return JSON: { ok: true, key, url, mime_type, size_bytes }]
    │
    ▼
[Agent receives JSON, can display URL or pass key to another tool]

What the tool returns

A useful response shape:

{
  "ok": true,
  "file_id": "abc123",
  "url": "https://storage.example.com/files/abc123",
  "mime_type": "application/pdf",
  "size_bytes": 12345,
  "expires_at": "2026-04-26T12:00:00Z"
}

The agent decides what to do: display the URL inline (markdown image/link in the response), pass the key to another tool, attach to a callback. The system prompt typically tells it which:

## Display Protocol
ALWAYS display generated images using inline markdown:
![descriptive alt text](https://imageurl.com)

For VIDEOS, share as a plain markdown link, NOT a video embed:
[Descriptive video title](https://videourl.com)

Image vs video display matters, and rendering is surface-specific. The ![]() markdown above is the canvas Chat Trigger's syntax. Production surfaces use Block Kit image blocks, adaptive cards, embeds, or native file uploads (see the "Surface-specific seams" section above). Whatever the surface, video is the harder case: video embeds often don't render reliably, and a plain link is the path that works everywhere. Tell the agent explicitly in the system prompt for its surface. Otherwise it copies the image pattern for video and the user sees a broken thumbnail.

When you don't need this

The upload-and-return-key pattern is specifically for the agent-calls-tool-and-tool-produces-binary case.

Storage choices

Ask which service before building

n8n supports many storage backends, and defaulting to S3 is presumptuous. Before designing the workflow, ask the user what they use. Common options, all with native nodes:

The choice affects credential setup, URL shape, public vs signed access, TTL/cleanup mechanics, and how the tool's fromAi parameter description should explain the URL/key format. Don't pick on the user's behalf.

What changes per backend

A common production split for object storage: private bucket for inbound user files, public bucket for outbound results so the agent can return public URLs. For drive-style, use a private folder for inbound and a shared-link-enabled folder for outbound.

Lifecycle and cleanup

Without cleanup, bills grow. Options:

Pick based on retention and cost.

Common mistakes

Documenting the tool

In the sub-workflow's description:

Per n8n-extending-mcp-official, also document in the user's CLAUDE.md.

Publish your skill

Copy this prompt into Claude Code, Codex or any agent. It walks you through your first skill in about 20 minutes, with you as the author.

Click to copy.