-
Notifications
You must be signed in to change notification settings - Fork 43
Update nodejs langchain sample with otel and stable sdk #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,32 @@ | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Debug (Agentic Auth + Dev Tunnel)", | ||
| "type": "node", | ||
| "request": "launch", | ||
| "runtimeArgs": ["-r", "ts-node/register"], | ||
| "args": ["${workspaceFolder}/src/index.ts"], | ||
| "env": { | ||
| "NODE_ENV": "production", | ||
| "PORT": "3978", | ||
| "HOST": "0.0.0.0", | ||
| "DEBUG": "agents:*", | ||
| "USE_AGENTIC_AUTH": "true", | ||
| "agentic_type": "agentic", | ||
| "agentic_altBlueprintConnectionName": "service_connection", | ||
| "agentic_scopes": "ea9ffc3e-8a23-4a7d-836d-234d7c7565c1/.default", | ||
| "connectionsMap__0__serviceUrl": "*", | ||
| "connectionsMap__0__connection": "service_connection", | ||
| "connections__service_connection__settings__clientId": "037c994d-fc58-49e3-8b44-816dfe8e4a26" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make palceholder |
||
| }, | ||
| "envFile": "${workspaceFolder}/.env", | ||
| "sourceMaps": true, | ||
| "outFiles": ["${workspaceFolder}/dist/**/*.js"], | ||
| "console": "integratedTerminal", | ||
| "internalConsoleOptions": "neverOpen", | ||
| "preLaunchTask": "Start Dev Tunnel (langchain-agent-debug)" | ||
| }, | ||
| { | ||
| "name": "Attach to Local Service", | ||
| "type": "node", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,26 @@ | |
| } | ||
| } | ||
| }, | ||
| { | ||
| "label": "Start Dev Tunnel (langchain-agent-debug)", | ||
| "type": "shell", | ||
| "command": "devtunnel host langchain-agent-debug --allow-anonymous", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace with placeholder |
||
| "isBackground": true, | ||
| "problemMatcher": { | ||
| "pattern": { | ||
| "regexp": "^$" | ||
| }, | ||
| "background": { | ||
| "activeOnStart": true, | ||
| "beginsPattern": ".", | ||
| "endsPattern": "Ready to accept|Connect via|Hosting port" | ||
| } | ||
| }, | ||
| "presentation": { | ||
| "reveal": "silent", | ||
| "panel": "dedicated" | ||
| } | ||
| }, | ||
| { | ||
| "label": "Start Microsoft 365 Agents Playground", | ||
| "type": "shell", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ import { Activity, ActivityTypes } from '@microsoft/agents-activity'; | |
| import '@microsoft/agents-a365-notifications'; | ||
| import { AgentNotificationActivity, NotificationType, createEmailResponseActivity } from '@microsoft/agents-a365-notifications'; | ||
| // Observability Imports | ||
| import { BaggageBuilder } from '@microsoft/agents-a365-observability'; | ||
| import { AgenticTokenCacheInstance, BaggageBuilderUtils } from '@microsoft/agents-a365-observability-hosting'; | ||
| import { BaggageBuilder, OpenTelemetryConstants } from '@microsoft/opentelemetry'; | ||
| import { AgenticTokenCacheInstance, BaggageBuilderUtils, TurnContextLike } from '@microsoft/opentelemetry'; | ||
| import { getObservabilityAuthenticationScope } from '@microsoft/agents-a365-runtime'; | ||
| import tokenCache, { createAgenticTokenCacheKey } from './token-cache'; | ||
| import { Client, getClient } from './client'; | ||
|
|
@@ -22,8 +22,8 @@ export class A365Agent extends AgentApplication<TurnState> { | |
| storage: new MemoryStorage(), | ||
| authorization: { | ||
| agentic: { | ||
| type: 'agentic', | ||
| } // scopes set in the .env file... | ||
| type: 'AgenticUserAuthorization', | ||
| } | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -76,11 +76,19 @@ export class A365Agent extends AgentApplication<TurnState> { | |
|
|
||
| startTypingLoop(); | ||
|
|
||
| const baggageScope = BaggageBuilderUtils.fromTurnContext( | ||
| const blueprintId = turnContext.activity?.recipient?.agenticAppBlueprintId | ||
| || process.env.connections__service_connection__settings__clientId; | ||
|
|
||
| const baggageBuilder = BaggageBuilderUtils.fromTurnContext( | ||
| new BaggageBuilder(), | ||
| turnContext | ||
| ).sessionDescription('Initial onboarding session') | ||
| .build(); | ||
| turnContext as unknown as TurnContextLike | ||
| ).sessionDescription('Initial onboarding session'); | ||
|
|
||
| if (blueprintId) { | ||
| baggageBuilder.setPairs([[OpenTelemetryConstants.GEN_AI_AGENT_BLUEPRINT_ID_KEY, blueprintId]]); | ||
| } | ||
|
|
||
| const baggageScope = baggageBuilder.build(); | ||
|
|
||
| // Preload/refresh exporter token | ||
| await this.preloadObservabilityToken(turnContext); | ||
|
|
@@ -89,7 +97,7 @@ export class A365Agent extends AgentApplication<TurnState> { | |
| await baggageScope.run(async () => { | ||
| try { | ||
| const client: Client = await getClient(this.authorization, A365Agent.authHandlerName, turnContext, displayName); | ||
| const response = await client.invokeInferenceScope(userMessage); | ||
| const response = await client.invoke(userMessage); | ||
| await turnContext.sendActivity(response); | ||
| } catch (error) { | ||
| console.error('LLM query error:', error); | ||
|
|
@@ -118,11 +126,11 @@ export class A365Agent extends AgentApplication<TurnState> { | |
| const cacheKey = createAgenticTokenCacheKey(agentId, tenantId); | ||
| tokenCache.set(cacheKey, aauToken?.token || ''); | ||
| } else { | ||
| await AgenticTokenCacheInstance.RefreshObservabilityToken( | ||
| await AgenticTokenCacheInstance.refreshObservabilityToken( | ||
| agentId, | ||
| tenantId, | ||
| turnContext, | ||
| this.authorization, | ||
| turnContext as unknown as TurnContextLike, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bug in otel package needs to be fixed upstream |
||
| this.authorization as any, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bug in otel package needs to be fixed upstream |
||
| getObservabilityAuthenticationScope() | ||
| ); | ||
| } | ||
|
|
@@ -151,13 +159,13 @@ export class A365Agent extends AgentApplication<TurnState> { | |
| const client: Client = await getClient(this.authorization, A365Agent.authHandlerName, context); | ||
|
|
||
| // First, retrieve the email content | ||
| const emailContent = await client.invokeInferenceScope( | ||
| const emailContent = await client.invoke( | ||
| `You have a new email from ${context.activity.from?.name} with id '${emailNotification.id}', ` + | ||
| `ConversationId '${emailNotification.conversationId}'. Please retrieve this message and return it in text format.` | ||
| ); | ||
|
|
||
| // Then process the email | ||
| const response = await client.invokeInferenceScope( | ||
| const response = await client.invoke( | ||
| `You have received the following email. Please follow any instructions in it. ${emailContent}` | ||
| ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add instructions to readme