Share via


Pass files to agent flows, connectors, and tools

Pass files from your Copilot Studio agent to downstream systems using agent flows, connectors, and tools. This functionality unlocks powerful automation scenarios such as ticket creation with attachments, document processing, and more.

Turn on file input

Makers can allow users of their agent to upload files during chat interactions with their agent. Create a new topic to retrieve the user's file.

There are three different options to request the file.

Question node interaction

The first option is done using a Question node.

  1. Add a Question node in a topic.

  2. Under Identify, select File.

  3. Open the Question properties panel and select the Entity recognition category.

  4. Turn on Include file metadata.

Set a variable

The next option is to use the First(System.Activity.Attachements) variable to determine if a file was already attached. This might happen in a Microsoft Teams conversation, for example. To use this option, in your topic, use a Set variable value node to retrieve a Record with keys.Name.ContentType and .Content to be passed to actions.

Combine the options

The third option is to use both options together. Begin by using the First(System.Activity.Attachements) variable to determine if a file was already attached. Then use a Condition node to incorporate a Question node to prompt the user to upload a file.

This option lets the topic run automatically if the user triggered the conversation flow and attached a file in the same conversation. For example, if the user says, "Send an email with this file 'my.file'."

However, if the user says, "Send an email with this file," but the user didn't attach the file, the user is prompted to provide the file before continuing the conversation flow.

Pass a user file to a Power Automate flow

To pass the user file to a Power Automate flow, in your topic after your Question node to request a file, create a new agent flow. The variable in the agent flow receives the file from Copilot Studio.

Optionally, you can add logic in your flow to send this file to SharePoint, ServiceNow, Dynamics 365 Customer Service, and such. To pass the variable, use this Power Fx formula:

{ contentBytes: Topic.userReceipt.Content, name: Topic.userReceipt.Name }

Pass a user file to a connector

The same principle to pass a user file to a Power Automate flow applies to passing files to connectors. To pass the user file to a connector, in your topic after your Question node to request a file, add a tool from a connector. The variable in the connector receives the file from Copilot Studio.

Note

Some connectors have a requirement to wrap "file" inputs. For example, the Send an email (V2) connector has an Attachments input this is a table of records with contentBytes and name keys.

The attachment object works with the same Power Fx formula:

{ contentBytes: Topic.userReceipt.Content, name: Topic.userReceipt.Name }

Pass a user file to a tool

On the Tools page, file inputs only work when set as a PowerFx formula using the Custom value option. It doesn't work with the Dynamically fill with AI option. Use the System.Activity.Attachments variable to fill the value with a PowerFx formula that matches the connector input.

The following PowerFx formula is an example:

If(
    IsEmpty(System.Activity.Attachments), 
    [], 
    [{ contentBytes: First(System.Activity.Attachments).Content, name: First(System.Activity.Attachments).Name }])