-
Notifications
You must be signed in to change notification settings - Fork 19
Perplexity: added telemetry markers to all paths in the code #73
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
Merged
aubreyquinn
merged 13 commits into
main
from
users/aubreyquinn/perplexity-full-telemetry-markers
Nov 20, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
459bd36
work in progress
c84f95e
adding telemetry markers to all paths in the code
570a5d4
added telemetry essentials to env file
e49bb58
Update nodejs/perplexity/sample-agent/src/perplexityAgent.ts
aubreyquinn 90269aa
Merge remote-tracking branch 'origin/main' into users/aubreyquinn/per…
a285565
applying changes from code review
748056e
applying changes from code review
783ac3a
applying changes from code review
28eb9e2
work in progress - tool call
0313ef3
refactored perplexity agent into OOOP pattern
cdab414
updated code comment
e5ba3de
applying changes from code review
a778039
applying changes from code review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { TurnContext, TurnState } from "@microsoft/agents-hosting"; | ||
| import type { InvokeAgentScope } from "@microsoft/agents-a365-observability"; | ||
| import { PerplexityClient } from "./perplexityClient.js"; | ||
| import { ToolRunner } from "./toolRunner.js"; | ||
|
|
||
| /** | ||
| * ChatFlowService manages the chat and tool invocation flow. | ||
| */ | ||
| export class ChatFlowService { | ||
| constructor(private readonly getPerplexityClient: () => PerplexityClient) {} | ||
|
|
||
| /** | ||
| * Runs the main chat and tool flow. | ||
| * @param turnContext The context of the current turn. | ||
| * @param _state The state of the current turn. | ||
| * @param userMessage The user's message. | ||
| * @param invokeScope The scope for invoking the agent. | ||
| */ | ||
| async runChatFlow( | ||
| turnContext: TurnContext, | ||
| _state: TurnState, | ||
| userMessage: string, | ||
| invokeScope: InvokeAgentScope | undefined | ||
| ): Promise<void> { | ||
| const streamingResponse = (turnContext as any).streamingResponse; | ||
| const perplexityClient = this.getPerplexityClient(); | ||
|
|
||
| try { | ||
| invokeScope?.recordInputMessages([userMessage]); | ||
|
|
||
| if (streamingResponse) { | ||
| streamingResponse.queueInformativeUpdate( | ||
| "I'm working on your request..." | ||
| ); | ||
| } | ||
|
|
||
| invokeScope?.recordOutputMessages([ | ||
| "Message path: PerplexityInvocationStarted", | ||
| ]); | ||
|
|
||
| const response = await perplexityClient.invokeAgentWithScope(userMessage); | ||
|
|
||
| invokeScope?.recordOutputMessages([ | ||
| "Message path: PerplexityInvocationSucceeded", | ||
| ]); | ||
|
|
||
| if (streamingResponse) { | ||
| streamingResponse.queueTextChunk(response); | ||
| await streamingResponse.endStream(); | ||
| } else { | ||
| await turnContext.sendActivity(response); | ||
| } | ||
|
|
||
| invokeScope?.recordOutputMessages([ | ||
| "Message path: ChatOnly_CompletedSuccessfully", | ||
| ]); | ||
| } catch (error) { | ||
| const err = error as any; | ||
| const errorMessage = `Error: ${err.message || err}`; | ||
|
|
||
| invokeScope?.recordError(error as Error); | ||
| invokeScope?.recordOutputMessages([ | ||
| "Message path: ChatOnly_Error", | ||
| errorMessage, | ||
| ]); | ||
|
|
||
| if (streamingResponse) { | ||
| streamingResponse.queueTextChunk(errorMessage); | ||
| await streamingResponse.endStream(); | ||
| } else { | ||
| await turnContext.sendActivity(errorMessage); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.