Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions nodejs/perplexity/sample-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"express": "^5.1.0",
"mammoth": "^1.11.0",
"pdf-parse": "^2.4.5",
"@types/express": "^4.17.21",
"@types/node": "^20.14.9",
"typescript": "^5.9.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@microsoft/m365agentsplayground": "^0.2.18",
"@types/express": "^4.17.21",
"@types/node": "^20.14.9",
"nodemon": "^3.1.10",
"rimraf": "^5.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.9.2"
"ts-node": "^10.9.2"
}
}
30 changes: 18 additions & 12 deletions nodejs/perplexity/sample-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { PerplexityClient } from "./perplexityClient";

// Load environment variables from .env file FIRST
config();

/**
* Create a cache key for the agentic token
*/
Expand Down Expand Up @@ -98,7 +97,6 @@ console.log(" - CLUSTER_CATEGORY:", process.env["CLUSTER_CATEGORY"]);
async function queryModel(
userInput: string,
agentDetails: AgentDetails,
tenantDetails: TenantDetails,
client: PerplexityClient,
systemPrompt: string,
) {
Expand All @@ -109,13 +107,12 @@ async function queryModel(
inputTokens: Math.ceil(userInput.length / 4), // Rough estimate
outputTokens: 0, // Will be updated after response
finishReasons: [],
responseId: `inference-${Date.now()}`,
};

const inferenceScope = InferenceScope.start(
{ content: userInput },
inferenceDetails,
agentDetails,
tenantDetails,
);

try {
Expand Down Expand Up @@ -232,13 +229,12 @@ app.onActivity(ActivityTypes.Message, async (context) => {
const baggageScope = new BaggageBuilder()
.tenantId(tenantId)
.agentId(agentId)
.correlationId(activityId || `corr-${Date.now()}`)
.agentName(agentName)
.agentDescription(
"AI answer engine for research, writing, and task assistance using live web search and citations",
)
.callerId(userId)
.callerName(userName)
.userId(userId)
.userName(userName)
.conversationId(conversationId)
.operationSource("sdk")
.build();
Expand All @@ -247,6 +243,7 @@ app.onActivity(ActivityTypes.Message, async (context) => {
const agentDetails = {
agentId: agentId,
agentName: agentName,
tenantId: tenantId,
agentDescription:
"AI answer engine for research, writing, and task assistance using live web search and citations",
botId: activity.recipient?.id,
Expand Down Expand Up @@ -334,10 +331,20 @@ app.onActivity(ActivityTypes.Message, async (context) => {
await baggageScope.run(async () => {
// Start agent invocation scope
const agentScope = InvokeAgentScope.start(
invokeDetails,
tenantDetails,
undefined, // No caller agent (human-to-agent interaction)
callerDetails,
{
content: userMessage,
sessionId: sessionId,
conversationId: conversationId,
},
{ endpoint: invokeDetails.endpoint },
agentDetails,
{
userDetails: {
userId: userId,
userName: userName,
tenantId: tenantId,
},
},
);

try {
Expand Down Expand Up @@ -382,7 +389,6 @@ app.onActivity(ActivityTypes.Message, async (context) => {
let modelResponse = await queryModel(
userMessage,
agentDetails,
tenantDetails,
perplexityClient,
systemPrompt,
);
Expand Down
Loading