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 by 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. Select Include file metadata.

Set a variable

The next option is to use the First(System.Activity.Attachments) variable to determine if a file was already attached—for example, in a Microsoft Teams conversation. 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

You can use both options together. Start by using the First(System.Activity.Attachments) variable to check if a file is already attached. Then, use a Condition node to add a Question node that asks the user to upload a file.

This option lets the topic run automatically if the user starts the conversation flow and attaches 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 doesn't attach the file, the agent asks the user 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, add an agent flow in your topic after the Question node that requests a file. 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 similar services. To pass the variable, use this Power Fx formula:

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

Pass a user file to a Power Automate Flow added as a tool

To pass a user file to an agent or Power Automate flow added as a tool, perform the following steps:

  1. Open the Tools page.

  2. Select your tool.

  3. On the tool's Details page, go to Inputs.

  4. For each flow input variable, a ContentBytes and name input should be displayed. If inputs are missing, select Add input to add them.

  5. Set contentBytes to the following formula:

    First(System.Activity.Attachments).Content
    
  6. Set name to the following formula:

    First(System.Activity.Attachments).Name
    
  7. Once configured, the Inputs should be displayed like the following configuration:

    Screenshot of the Inputs dialog, illustrating the Input name when configured with contentBytes and name fields.

  8. You then can select File as the type of user input in the flow.

    Screenshot of a flow highlighting the file as a type of user input.

Pass a user file to a connector

The same principle that passes a user file to a Power Automate flow also applies to passing files to connectors. To pass the user file to a connector, add a tool from a connector in your topic after the Question node that requests a file. The variable in the connector receives the file from your agent.

Note

Some connectors require you to wrap inputs of type file. For example, the Send an email (V2) connector has an Attachments input, which 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 you set them as a Power Fx formula by using the Custom value option. It doesn't work by using the Dynamically fill with AI option. Use the System.Activity.Attachments variable to fill the value by using a Power Fx formula that matches the connector input.

The following Power Fx formula is an example:

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