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.

  5. In the Save As dialog box, select a directory and enter a name for your new AI Agent .yaml file.

  6. Select the Save Agent File button to save your AI Agent file.

    Screenshot of the VS Code Save As dialog to save the agent yaml file.

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. Enter your model deployment name. The deployment name you chose when you deployed an existing model.

      Tip

      The model deployment name must be the exact name you chose for the model you deployed in your Azure AI Foundry project. In the following image, gpt-4o-1 is the model deployment name you chose at deployment. gpt-4o is the model name. Screenshot of the highlighted deployment model names, an arrow between them, and the model name highlighted in a different color.

    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 + (plus) icon next to the TOOL section in the designer.

    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 .yaml file, select File > Save in the VS Code menu bar.

Deploy Azure AI Agents to the Azure AI Foundry Studio

Deploy your agent directly to Azure AI Foundry with the following steps:

  1. Select the Deploy to 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 Open Yaml File to view the yaml definition of the agent.

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

    Screenshot of the Agent Preferences page with the 'Open Yaml File' and 'Open Playground' buttons highlighted.

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** page in VS Code.

  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