Gå til indhold
Chat→ColleagueArbejd med migKontaktLær
cleverest
Tilbage til alle artikler

Build an AI email assistant with Copilot Studio

What you will build

This guide walks you through creating an automated email assistant that:

  1. Monitors your Outlook inbox for new emails
  2. Classifies each email to determine if it contains a question or request
  3. Searches your FAQ knowledge base for a matching answer
  4. Drafts a professional reply as a threaded response
  5. Flags emails that require manual attention

Prerequisites

Before you begin, verify you have the following:

Licenses and access

  • Copilot Studio access through one of:
    • Copilot Studio user license (free) with a Copilot Credit pack subscription or pay-as-you-go billing via Azure
    • Microsoft 365 Copilot license (includes Copilot Studio)
  • Outlook mailbox

Permissions

  • Environment Maker role in your Power Platform environment (required for Copilot Studio agents and agent flows)

Prepared materials

  • FAQ document in Excel format
  • Excel file saved to OneDrive or SharePoint (the agent cannot access local files)

Create the FAQ Bot agent

To create the FAQ bot agent, follow these steps:

  1. Go to copilotstudio.microsoft.com and select Create an agent. The agent creation page opens with a text field for describing your agent.

  2. In the Details section, select Edit and give the agent a name and description, then select Save. Keep the name short and clear.

    • For example: name "FAQ Bot" and description "Answer questions using our FAQ document"
  3. In the Instructions section, select Edit, add the following instructions, and select Save:

# Purpose

Provide accurate answers to questions by referencing the FAQ document stored in the Excel file.

# Response format

- Return only the answer. No greetings, no follow-up questions, no offers of additional help.
- Be concise and direct.
- Do not include phrases like "According to the FAQ" or "I found that."
- Do not ask if the response was helpful.
- Do not thank the user.

# Instructions

1. **Receive question** - Parse the input and identify the core question.
2. **Search FAQ document** - Find the most relevant answer in the Excel FAQ.
3. **Respond**
   - If a match is found: Return the answer directly.
   - If no match is found: Respond with "NO_MATCH" only.
   - If multiple matches are found: Return the single best match.

# Example

**Input:** "How do I reset my password?"

**Output:** "Click on Forgot Password on the login page, enter your email address, and follow the instructions sent to your email to create a new password."
  • Replace the example with a real example from your FAQ database.
  1. In the Knowledge section, select Add knowledge. The knowledge source dialog opens with available source types.

  2. Add your FAQ database. You can upload a file, connect a file from OneDrive or SharePoint, or use one of the available connectors. You can also add multiple files if necessary. When you add a file, it appears in your knowledge sources list. Indexing may take a few minutes.

    • If the file does not appear, verify it is saved to OneDrive or SharePoint (not locally).
    • If indexing fails, check that your Excel file has clear column headers in the first row.
  3. Test the agent using the test panel on the right side of the screen. Enter a question from your FAQ and verify the agent returns the correct answer. Enter a question not in your FAQ and verify the agent returns "NO_MATCH".

  4. Select Publish at the top of the page, then confirm in the popup. A green success banner confirms publication. The agent is now available for use in flows.


Create the agent flow

To create the flow that processes incoming emails, follow these steps:

  1. In Copilot Studio, select Create workflow. The flow designer appears.

  2. For the trigger, search for "when a new email arrives" and select When a new email arrives (V3) from the Office 365 Outlook connector. This trigger monitors your mailbox for incoming messages.

  3. Configure the trigger by setting Folder to "Inbox". You can add filters here to limit which emails trigger the flow (for example, only emails from external senders).


Classify emails

To classify incoming emails by type, follow these steps:

  1. Select + below the trigger and choose Add an action. The action search panel opens.

  2. Search for "Run a prompt" and select the Run a prompt action from the AI Capabilities section. The prompt configuration panel opens.

  3. In the Prompt dropdown, select AI Classify from the prebuilt prompts list. Two input fields appear: Input text and Input categories.

  4. In the Input text field, select the Body dynamic content from the email trigger. This passes the email content to the classification prompt. Add dynamic content by typing slash (/) or selecting the lightning icon from the right side of the text field.

  5. In the Input categories field, enter your classification categories as a list. The AI Classify prompt will return whichever category best matches the email content:

Question, Request, Information, Other
  1. Select + below the prompt action and from the Control connector, add a Condition action. The condition configuration panel opens with two branches.

  2. Configure the condition to check if the email needs a response:

    • In the first field, add the dynamic content Text from the Run a prompt outputs
    • Set the operator to is equal to
    • Enter Question in the value field
    • Select + Add > Add row to add an OR condition
    • Configure the second row: Text is equal to Request
  3. In the False branch, from the Office 365 Outlook connector, add a Flag email (V2) action. Configure it with Message Id from the trigger. This flags emails that do not require an FAQ response for manual review.

    • Alternatively, you could use the action Move email (V2) to move the email to a specific folder instead.

Query the FAQ Bot

To query the FAQ bot agent with the email content, follow these steps:

  1. In the True branch, select + and add an action.

  2. In the Copilot Studio connector, select the Execute Agent and wait action.

  3. In the Agent dropdown menu, select your FAQ bot agent.

    • If the agent does not appear, verify you published it in Step 1.
  4. In the Message field, select Body from the email trigger dynamic content. This sends the email content to your FAQ bot for processing.

  5. Select + below the agent action and add another Condition action.

  6. Configure the condition to check for a successful FAQ match:

    • In the first field, select the agent's last response output
    • Set the operator to is not equal to
    • Enter NO_MATCH in the value field
  7. In the False branch of this condition, add another Flag email (V2) action. Configure it with Message Id from the trigger. This flags emails where no FAQ match was found.


Draft the response

To generate a professional email reply using the FAQ answer, follow these steps:

  1. In the True branch (FAQ match found), select + and add a Run a prompt action.

  2. In the Prompt dropdown, select + New custom prompt. The prompt builder opens.

  3. Enter "Email Reply Drafter" as the prompt name.

  4. In the prompt instructions, enter:

You are a personal assistant for [your name], a [your role]. Create a professional email reply to the following email. Only write the body of the email.

Start with:
Hi [first name],

Sign off with:
Best regards,
[your name]

Output your response as HTML. Use <br> for line breaks and <strong> for emphasis.

Do not use quotation marks anywhere in your response - rephrase if needed.

If you include links, use single quotes for attributes: <a href='...'>.

Email to reply to:
[email_body]

Sender name:
[sender_name]

Answer to include:
[faq_answer]
  1. Add three input variables by selecting + Add input for each:

    • email_body (text) - The original email content
    • sender_name (text) - The sender's name
    • faq_answer (text) - The answer from the FAQ bot
  2. Select Save and return to the flow designer.

  3. Configure the prompt inputs:

    • email_body: Select Body from the Outlook email trigger action
    • sender_name: Select From from the Outlook email trigger action
    • faq_answer: Select the last response output from the FAQ bot action

Save as threaded draft

To save the generated reply as a draft in the original email thread, follow these steps:

Create a blank reply draft

  1. Select + and add an action. Search for "Send an HTTP request" and select Send an HTTP request from the Office 365 Outlook connector. This action lets you call Microsoft Graph API endpoints directly using your existing Outlook connection.

  2. Configure the HTTP action:

    • Method: POST
    • URI: /me/messages/[Message Id]/createReply

    Add dynamic content and select the Message Id from the Outlook trigger action. This creates an empty draft reply attached to the original email thread.

Parse the response

  1. Select + and add a Parse JSON action. This extracts the new draft message ID from the Graph API response.

  2. Configure the action:

    • Content: Select Body from the HTTP action dynamic content
    • Schema: Enter the following:
{
  "type": "object",
  "properties": {
    "id": { "type": "string" }
  }
}

Populate the draft with the generated reply

  1. Select + and add another Send an HTTP request action from the Office 365 Outlook connector.

  2. Configure the HTTP action:

    • Method: PATCH
    • URI: /me/messages/[Message Id]
    • Body:
{
  "body": {
    "contentType": "HTML",
    "content": "[Text]"
  }
}

Select the Message Id dynamic content from the Parse JSON action and the Text dynamic content from your email drafter prompt action for the content value.

  1. Select Save to save the complete flow.

Test the flow

To verify the flow works correctly, follow these steps:

  1. Select Test in the top right corner of the flow designer.

  2. Select Manually and then Test.

  3. Send a test email to your inbox containing a question from your FAQ. The flow should trigger within a few minutes.

  4. Monitor the flow run to verify each step completes successfully. Select the running flow to see step-by-step execution details.

  5. Check your Outlook Drafts folder for the generated reply. The draft should appear as a reply to the original email thread.

Test scenarios

Scenario Expected Result What to Check
Email contains question from FAQ Draft reply appears in Drafts folder Draft contains correct FAQ answer formatted as professional reply
Email contains question not in FAQ Original email is flagged Email appears with flag in inbox
Email is informational (not a question) Original email is flagged Classification returned "Information" or "Other"

Troubleshooting

FAQ Bot returns NO_MATCH for questions that exist in your FAQ

Symptoms:

  • Valid questions return "NO_MATCH"
  • Agent works in test panel but not in flow

Resolution:

  1. Open the FAQ bot in Copilot Studio and check the Knowledge section. Verify your Excel file shows "Indexed" status.

  2. Test the agent directly in the test panel with the exact email text. If the agent fails here, the issue is with knowledge indexing.

  3. Check your Excel file format. The first row must contain clear column headers. Remove any merged cells or formatting.

  4. Re-add the knowledge source if indexing appears stuck. Delete the existing source and add it again.

Draft does not appear in Outlook

Symptoms:

  • Flow completes successfully
  • No draft visible in Drafts folder

Resolution:

  1. Check the HTTP action responses in the flow run history. The createReply action should return a 201 status code with a message ID.

  2. Verify the PATCH action completed successfully. Look for a 200 status code in the response.

  3. Check for the draft in Outlook Web App. Desktop Outlook may take a few minutes to sync.

  4. Verify the Message Id from the trigger is correct. If the original email was moved or deleted, the createReply will fail.

  5. Check your Outlook connection in the flow. If the connection expired, re-authenticate by editing the connection.

Classification returns unexpected categories

Symptoms:

  • Emails classified as "Other" when they contain questions
  • Inconsistent classification results

Resolution:

  1. Review the email content being passed to the classifier. Select the flow run and check what text was sent to the AIClassify prompt.

  2. Simplify your categories. Using fewer, more distinct categories improves accuracy.

  3. Consider adding a confidence threshold. Add a condition to flag emails where the classification confidence is below 0.7.


Inspiration for enhancing the workflow

  • Add sender filtering: Modify the trigger to only process emails from specific domains or contacts
  • Add approval workflow: Insert an approval step after the email drafting step and then add an action to send the reply instead of just generating a draft.
  • Track metrics: Add a SharePoint list to log all processed emails and their outcomes