From 33a925fcf481f8153519f975589bbccc0c5bc403 Mon Sep 17 00:00:00 2001 From: prajapatiy9826 Date: Wed, 1 Apr 2026 14:30:41 +0530 Subject: [PATCH 1/2] feat: update client to support Azure AI Foundry endpoints and enhance inference request structure --- .gitignore | 4 +++ nodejs/langchain/sample-agent/src/client.ts | 34 ++++++++++++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 938dae64..8802f296 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,7 @@ coverage/ # OS-specific files .DS_Store Thumbs.db + +# Agent 365 generated config (contains secrets and environment-specific values) +a365.config.json +a365.generated.config.json diff --git a/nodejs/langchain/sample-agent/src/client.ts b/nodejs/langchain/sample-agent/src/client.ts index b24e5072..9a5e9b47 100644 --- a/nodejs/langchain/sample-agent/src/client.ts +++ b/nodejs/langchain/sample-agent/src/client.ts @@ -16,8 +16,8 @@ import { Builder, InferenceOperationType, AgentDetails, - TenantDetails, InferenceDetails, + Request, Agent365ExporterOptions, } from '@microsoft/agents-a365-observability'; import { AgenticTokenCacheInstance } from '@microsoft/agents-a365-observability-hosting'; @@ -57,10 +57,30 @@ const agentName = "LangChainA365Agent"; function createChatModel(): BaseChatModel { // Check for Azure OpenAI configuration first if (process.env.AZURE_OPENAI_API_KEY && process.env.AZURE_OPENAI_ENDPOINT && process.env.AZURE_OPENAI_DEPLOYMENT) { + const endpoint = process.env.AZURE_OPENAI_ENDPOINT; + + // Azure AI Foundry endpoints use a /v1 path and are OpenAI-compatible. + // They do not accept the api-version query parameter, so use ChatOpenAI + // with a custom baseURL instead of AzureChatOpenAI. + if (endpoint.includes('/v1')) { + console.log('Using Azure AI Foundry OpenAI-compatible endpoint'); + const baseURL = endpoint.substring(0, endpoint.indexOf('/v1') + 3); + return new ChatOpenAI({ + openAIApiKey: process.env.AZURE_OPENAI_API_KEY, + modelName: process.env.AZURE_OPENAI_DEPLOYMENT, + temperature: 0, + configuration: { + baseURL, + apiKey: process.env.AZURE_OPENAI_API_KEY, + defaultHeaders: { 'api-key': process.env.AZURE_OPENAI_API_KEY }, + }, + }); + } + console.log('Using Azure OpenAI'); return new AzureChatOpenAI({ azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY, - azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_ENDPOINT?.replace('https://', '').replace('.openai.azure.com/', '').replace('.openai.azure.com', ''), + azureOpenAIApiInstanceName: endpoint.replace('https://', '').replace('.openai.azure.com/', '').replace('.openai.azure.com', ''), azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_DEPLOYMENT, azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION || "2024-12-01-preview", temperature: 0, @@ -204,6 +224,10 @@ class LangChainClient implements Client { } async invokeInferenceScope(prompt: string) { + const request: Request = { + conversationId: this.turnContext?.activity?.conversation?.id || `conv-${Date.now()}`, + }; + const inferenceDetails: InferenceDetails = { operationName: InferenceOperationType.CHAT, model: "gpt-4o-mini", @@ -212,15 +236,11 @@ class LangChainClient implements Client { const agentDetails: AgentDetails = { agentId: this.turnContext?.activity?.recipient?.agenticAppId || agentName, agentName: agentName, - conversationId: this.turnContext?.activity?.conversation?.id || `conv-${Date.now()}`, - }; - - const tenantDetails: TenantDetails = { tenantId: this.turnContext?.activity?.recipient?.tenantId || 'sample-tenant', }; let response = ''; - const scope = InferenceScope.start(inferenceDetails, agentDetails, tenantDetails); + const scope = InferenceScope.start(request, inferenceDetails, agentDetails); try { await scope.withActiveSpanAsync(async () => { response = await this.invokeAgent(prompt); From 1aeebda87b2ea4815369460aca383b59405f3ac5 Mon Sep 17 00:00:00 2001 From: Yogeshp-MSFT Date: Fri, 24 Apr 2026 14:52:57 +0530 Subject: [PATCH 2/2] Improved formatting --- nodejs/langchain/sample-agent/src/client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/nodejs/langchain/sample-agent/src/client.ts b/nodejs/langchain/sample-agent/src/client.ts index f24ab84b..6888ce0d 100644 --- a/nodejs/langchain/sample-agent/src/client.ts +++ b/nodejs/langchain/sample-agent/src/client.ts @@ -78,6 +78,7 @@ function createChatModel(): BaseChatModel { } console.log('Using Azure OpenAI'); + return new AzureChatOpenAI({ azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY, azureOpenAIApiInstanceName: endpoint.replace('https://', '').replace('.openai.azure.com/', '').replace('.openai.azure.com', ''),