Skip to content
Merged
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
2 changes: 1 addition & 1 deletion nodejs/claude/sample-agent/src/claudeAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class ClaudeAgent {
if (mcpEnvironmentId && agenticUserId) {
try {

await this.toolServerService.addToolServers(
await this.toolServerService.addToolServersToAgent(
agentOptions,
agenticUserId,
mcpEnvironmentId,
Expand Down
2 changes: 0 additions & 2 deletions nodejs/langchain/sample-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { AgentNotificationActivity } from '@microsoft/agents-a365-notifications'
import { Client, getClient } from './client';

export class A365Agent extends AgentApplication<TurnState> {
agentName = "A365 Agent";

constructor() {
super({
startTypingTimer: true,
Expand Down
43 changes: 16 additions & 27 deletions nodejs/langchain/sample-agent/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { createAgent } from "langchain";
import { createAgent, ReactAgent } from "langchain";
import { ChatOpenAI } from "@langchain/openai";
import { DynamicStructuredTool } from "@langchain/core/tools";

// Tooling Imports
import { ClientConfig } from '@langchain/mcp-adapters';
import { McpToolRegistrationService } from '@microsoft/agents-a365-tooling-extensions-langchain';
import { TurnContext } from '@microsoft/agents-hosting';
import { Authorization, TurnContext } from '@microsoft/agents-hosting';

// Observability Imports
import {
Expand All @@ -32,6 +30,12 @@ sdk.start();

const toolService = new McpToolRegistrationService();

const agentName = "LangChain A365 Agent";
const agent = createAgent({
model: new ChatOpenAI({ temperature: 0 }),
name: agentName,
});

/**
* Creates and configures a LangChain client with Agent365 MCP tools.
*
Expand All @@ -49,14 +53,12 @@ const toolService = new McpToolRegistrationService();
* const response = await client.invokeAgent("Send an email to john@example.com");
* ```
*/
export async function getClient(authorization: any, turnContext: TurnContext): Promise<Client> {
export async function getClient(authorization: Authorization, turnContext: TurnContext): Promise<Client> {
// Get Mcp Tools
let tools: DynamicStructuredTool[] = [];

let agentWithMcpTools = undefined;
try {
const mcpClientConfig = {} as ClientConfig;
tools = await toolService.addMcpToolServers(
mcpClientConfig,
agentWithMcpTools = await toolService.addToolServersToAgent(
agent,
'',
process.env.ENVIRONMENT_ID || "",
authorization,
Expand All @@ -67,30 +69,17 @@ export async function getClient(authorization: any, turnContext: TurnContext): P
console.error('Error adding MCP tool servers:', error);
}

// Create the model
const model = new ChatOpenAI({
model: "gpt-4o-mini",
});

// Create the agent
const agent = createAgent({
model: model,
tools: tools,
name: 'LangChain Agent',
includeAgentName: 'inline'
});

return new LangChainClient(agent);
return new LangChainClient(agentWithMcpTools || agent);
}

/**
* LangChainClient provides an interface to interact with LangChain agents.
* It creates a React agent with tools and exposes an invokeAgent method.
*/
class LangChainClient implements Client {
private agent: any;
private agent: ReactAgent;

constructor(agent: any) {
constructor(agent: ReactAgent) {
this.agent = agent;
}

Expand All @@ -111,7 +100,7 @@ class LangChainClient implements Client {
],
});

let agentMessage = '';
let agentMessage: any = '';

// Extract the content from the LangChain response
if (result.messages && result.messages.length > 0) {
Expand Down