Edit

Share via


Work with Azure AI Foundry Agent Service in Visual Studio Code (Preview)

After you get started with the AI Foundry the VS Code extension, you can work with Azure AI Foundry Agent Service. Agents are "smart" microservices that:

  • Answer questions using their training data or search other sources with Retrieval Augmented Generation (RAG)
  • Perform specific actions
  • Automate complete workflows

Agents combine AI models with tools to access and interact with your data.

Azure AI Foundry developers can stay productive by developing, testing, and deploying agents in the familiar and powerful environment of VS Code.

Important

Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.

Create and edit Azure AI Agents within the designer view

Follow these steps to create an Azure AI Agent:

  1. First, finish the Get Started section to sign in to your Azure resources and set your default project.

  2. Deploy a model to use with your agent.

  3. In the Azure AI Foundry Extension view, find the Resources section.

  4. Select the + (plus) icon next to the Agents subsection to create a new AI Agent.

    Screenshot of the plus sign next to the Agents subsection.

Interact with your agent in the designer

After you choose your save ___location, both the agent .yaml file and the Designer view will open to edit your AI Agent.

  1. Perform the following tasks in the agent designer:

    1. Enter a name for your agent in the prompt.

    2. Select your model deployment name from the dropdown. The deployment name is what you chose when you deployed an existing model.

    3. Configure the following fields. The ID is generated by the extension:

      • Add a description for your agent
      • Set system instructions
      • Configure tools for agent use

      Screenshot of the Agent designer that enables you to edit and interact with your AI Agent.

    4. To save the .yaml file, select File > Save in the VS Code menu bar.

Explore the Azure AI Agent YAML definition

Your AI Agent .yaml file was opened at the same time the designer was. This file contains the details and setup information for your agent, similar to the following .yaml file example:

# yaml-language-server: $schema=https://aka.ms/ai-foundry-vsc/agent/1.0.0
version: 1.0.0
name: my-agent
description: Description of the agent
id: ''
metadata:
  authors:
    - author1
    - author2
  tags:
    - tag1
    - tag2
model:
  id: 'gpt-4o-1'
  options:
    temperature: 1
    top_p: 1
instructions: Instructions for the agent
tools: []

Add tools to the Azure AI Agent

Azure AI Agent Service has a set of knowledge and action tools that you can use to interact with your data sources.

Available tools for Azure AI Agents

The following tools are available:

Azure AI Foundry Agent Service has a set of knowledge and action tools that you can use to interact with your data sources, such as:

Configure the tools YAML file

The Agent Designer adds tools to an AI Agent via .yaml files.

Create a tool configuration .yaml file using the following steps:

  1. Choose a tool from the available tools for Azure AI Agents. Perform any setup steps that might be required. For example, Grounding with Bing search.

  2. Once you complete the setup, create a yaml code file that specifies the tool's configuration. For example, this format for Grounding with Bing Search:

    type: bing_grounding
    options:
      tool_connections:
        - >-
          /subscriptions/<Azure Subscription ID>/resourceGroups/<Azure Resource Group name>/providers/Microsoft.MachineLearningServices/workspaces/<Azure AI Foundry Project name>/connections/<Bing connection name>
    
  3. Replace the placeholders in the connection string under the tool_connections section with your information:

    • Azure Subscription ID
    • Azure Resource Group name
    • Azure AI Foundry Project name
    • Bing connection name
  4. To save the .yaml file, select File > Save in the VS Code menu bar.

Connect the tools file to the AI Agent

Add a tool to the AI Agent with the following steps:

  1. Select the Add tool button in the top-right corner of the TOOL section in the designer to show the dropdown. Choose the tool you want to add.

    Screenshot of the Agent designer TOOL section with the plus icon highlighted.

  2. In the file explorer that appears, select the .yaml tool file to use. Select the Select a tool file button to add the tool to the agent.

    Screenshot of the file explorer with the selected file and the 'Select a tool file' button highlighted.

  3. The tool is displayed in the TOOL section.

    Screenshot of the Agent designer TOOL section with the new tool highlighted.

  4. To save the tool .yaml file, select File > Save in the VS Code menu bar.

Create Azure AI Agents on the Azure AI Foundry Studio

Create your agent directly on Azure AI Foundry with the following steps:

  1. Select the Create on Azure AI Foundry button in the bottom-left of the designer.

    Screenshot of the Agent designer with the 'Deploy to Azure AI Foundry' button highlighted.

  2. In the VS Code navbar, refresh the Azure Resources view. The deployed agent is displayed under the Agents subsection.

    Screenshot of the 'Azure Resources' view. The deployed agent is highlighted under the 'Agents' subsection.

View the deployed AI Agent details

Selecting the deployed agent opens the Agent Preferences page in a view only mode.

  • Select the Edit Agent button to view the Agent designer and yaml definition of the agent for editing.

  • Select the Open Code File button to create a sample code file that uses the agent.

  • Select the Open Playground button to open the Agent Playground.

    Screenshot of the Agent Preferences page with the 'Edit Agent', 'Open Code File', and 'Open Playground' buttons highlighted.

Edit and update the deployed AI Agent

To edit the deployed agent, select the Edit Agent button in the Agent Preferences page. The agent designer opens with the agent .yaml file. Edit the agent's configuration, such as the model, tools, and instructions. After you finish editing, select the Update on Azure AI Foundry button in the lower left corner to save your changes.

Screenshot of the Agent Preferences page with the 'Update on Azure AI Foundry' button highlighted.

Explore the agent sample code

Create a sample code file using the following steps.

  1. Right-click on your deployed agent and select the Open Code File option or select the Open Code File button in the Agent Preferences page.

    Screenshot of the agent context menu with the Open Code file option highlighted.

  2. In the top center, select your preferred SDK to use in the Choose preferred SDK dropdown and press Enter.

    Screenshot of the Choose preferred SDK dropdown for agent code file selection.

  3. In the top center, select your preferred language to use in the Choose language dropdown and press Enter.

    Screenshot of the Choose language dropdown for agent code file selection.

  4. In the top center, select your preferred authentication method to use in the Choose auth method dropdown and press Enter.

    Screenshot of the Choose authentication method dropdown for agent code file selection.

Explore the sample code file

This Python sample code file that demonstrates a basic call to interact with the agent through the AI Foundry projects API:

Screenshot of generated agent sample code file.

Interact with Agents using agents playground

Open the Agents Playground using the following steps:

  1. Right-click on your deployed agent and select the Open Playground option This action starts a thread with your agent and let you send messages.

  2. Alternatively, select the Agent Playground link in the Tools subsection, and select your agent from the top-center list.

  3. The Playground page is displayed.

    Screenshot of the **Agents Playground** VS Code page.

  4. Type your prompt and see the outputs. The Grounding with Bing search tool is used to search the web for information. The agent uses the model and tools you configured in the agent designer. The source of the information is displayed in the Agent Annotations section, highlighted in the following image.

    Screenshot of the Agents Playground page with agent annotations highlighted in VS Code.

Explore Threads

The Threads subsection displays the threads created during a run with your agent. In the Azure Resources Extension view, select the caret icon in front of the Threads subsection to view the list of threads.

Screenshot of the threads in the Threads subsection.

View thread details

Select a thread to see the Thread Details page.

Screenshot of the thread details view.

  • A Thread is a conversation session between an agent and a user. Threads store Messages and automatically handle truncation to fit content into a model's context.

  • A Message is a single interaction between the agent and the user. Messages can include text, images, and other files. Messages are stored as a list on the Thread.

  • A Run is a single execution of an agent. Each run can have multiple threads, and each thread can have multiple messages. The agent uses its configuration and Thread's Messages to perform tasks by calling models and tools. As part of a Run, the agent appends Messages to the Thread.

View run details

Select the View run info button in the Thread Details page to see the run information in a JSON file.

Screenshot of the run details .json file.

Cleanup resources

The Azure resources that you created in this article are billed to your Azure subscription. If you don't expect to need these resources in the future, delete them to avoid incurring more charges.

Delete your agents

Tip

Because you can customize the left pane in the Azure AI Foundry portal, you might see different items than shown in these steps. If you don't see what you're looking for, select ... More at the bottom of the left pane.

Delete the deployed agent in the online AI Foundry portal. Select Agents from the navigation menu on the left, select your agent, then select the Delete button.

Screenshot of the AI Foundry portal with Agents from the navigation menu on the left and the Delete button highlighted.

Delete your models

  1. In the VS Code navbar, refresh the Azure Resources view. Expand the Models subsection to display the list of deployed models.

  2. Right-click on your deployed model to delete and select the Delete option.

    Screenshot of the model context menu with the Delete option highlighted.

Delete your tools

Delete the connected tool with the following steps:

  1. Open the Azure portal
  2. Select the Azure Resource Group containing the tool.
  3. Select the Delete button.

Next steps