Share via

Azure AI Agents client library samples for TypeScript (Beta)

These sample programs show how to use the TypeScript client libraries for Azure AI Agents in some common scenarios.

File Name Description
codeInterpreterWithStreaming.ts demonstrates how to use agent operations with code interpreter.
agentTokenUsage.ts demonstrates how to track the token usage of an Agent.
agentsAzureAiSearch.ts demonstrates how to use agent operations with the Azure AI Search tool.
agentsBasics.ts demonstrates how to use basic agent operations.
agentsBingGrounding.ts demonstrates how to use agent operations with the Grounding with Bing Search tool.
agentsBingGroundingWithStreaming.ts demonstrates how to use agent operations with the Grounding with Bing Search tool using streaming.
agentsConnectedAgents.ts This sample demonstrates how to use Agent operations with the Connected Agent tool from the Azure Agents service.
agentsFabric.ts demonstrates how to use agent operations with the Microsoft Fabric tool.
agentsImageInputWithBase64.ts This sample demonstrates how to use basic agent operations with image input (base64 encoded) for the Azure Agents service.
agentsImageInputWithFile.ts This sample demonstrates how to use basic agent operations using image file input for the Azure Agents service.
agentsImageInputWithUrl.ts This sample demonstrates how to use basic agent operations using image url input for the Azure Agents service.
agentsSharepoint.ts demonstrates how to use agent operations with the Sharepoint tool.
agentsWithFunctionTool.ts demonstrates how to use basic agent operations using function tool.
agentsWithOpenApi.ts demonstrates how to use agent operations with an OpenApi tool.
agentsWithToolset.ts demonstrates how to use agent operations with toolset.
batchVectorStoreWithFiles.ts demonstrates how to create the batch vector store with the list of files.
batchVectorStoreWithFilesAndPolling.ts demonstrates how to create the batch vector store with the list of files using polling operation.
codeInterpreter.ts demonstrates how to use agent operations with code interpreter.
fileSearch.ts This sample demonstrates how to use agent operations with file searching.
files.ts demonstrates how to use basic files agent operations.
filesWithLocalUpload.ts demonstrates how to use basic files agent operations with local file upload.
filesWithPolling.ts demonstrates how to upload a file and poll for its status.
messages.ts demonstrates how to use basic message agent operations.
runSteps.ts demonstrates how to use basic run agent operations.
streaming.ts demonstrates how to use agent operations in streaming.
threads.ts demonstrates how to use basic thread agent operations.
vectorStoreWithFiles.ts demonstrates how to create the vector store with the list of files.
vectorStoreWithFilesAndPolling.ts demonstrates how to create the vector store with the list of files using polling operation.
vectorStores.ts demonstrates how to create the vector store.
vectorStoresWithPolling.ts demonstrates how to create the vector store using polling operation.

Prerequisites

The sample programs are compatible with LTS versions of Node.js.

Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the TypeScript documentation. Install the TypeScript compiler using:

npm install -g typescript

You need an Azure subscription to run these sample programs.

Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.

Adapting the samples to run in the browser may require some additional consideration. For details, please see the package README.

Setup

To run the samples using the published version of the package:

  1. Install the dependencies using npm:
npm install
  1. Compile the samples:
npm run build
  1. Edit the file sample.env, adding the correct credentials to access the Azure service and run the samples. Then rename the file from sample.env to just .env. The sample programs will read this file automatically.

  2. Run whichever samples you like (note that some samples may require additional setup, see the table above):

node dist/codeInterpreterWithStreaming.js

Alternatively, run a single sample with the correct environment variables set (setting up the .env file is not required if you do this), for example (cross-platform):

npx dev-tool run vendored cross-env PROJECT_ENDPOINT="<project endpoint>" MODEL_DEPLOYMENT_NAME="<model deployment name>" node dist/codeInterpreterWithStreaming.js

Next Steps

Take a look at our API Documentation for more information about the APIs that are available in the clients.