-
Notifications
You must be signed in to change notification settings - Fork 134
improve langchain.js support #165
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?
Conversation
…I_API_KEY and upgrade dependencies
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.
Pull request overview
This PR updates the LangChain.js integration to improve compatibility with newer versions of LangChain packages and the DeepAgents library. The changes include dependency version upgrades, refactoring of agent structures, updates to the event streaming API, improved error handling in the UI, and configuration adjustments for Azure OpenAI authentication.
- Upgraded key dependencies including
@langchain/core,@langchain/mcp-adapters,deepagents, andlangchainto newer versions - Refactored agent configuration to use new DeepAgents API structure with direct properties instead of wrapped runnables
- Updated event streaming API from v1 to v2 with destructured event handling
- Added server error handling in the Angular UI service
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui-angular/src/app/services/api.service.ts | Added error handling for server errors in streaming responses |
| packages/mcp-servers/echo-ping/src/server.ts | Reordered imports to follow standard convention (external imports before internal) and added whitespace for readability |
| packages/api-langchain-js/src/tools/mcp-bridge.ts | Changed import to use type-only import for DynamicStructuredTool |
| packages/api-langchain-js/src/tools/index.ts | Simplified auth configuration by replacing requestInit headers with direct accessToken property |
| packages/api-langchain-js/src/server.ts | Removed debug console.log statement for cleaner output |
| packages/api-langchain-js/src/providers/azure-openai.ts | Added FORCE_AZURE_OPENAI_API_KEY environment variable support, changed default model fallback, and reordered configuration properties |
| packages/api-langchain-js/src/graph/index.ts | Updated streamEvents API to v2 with destructured event parameters and simplified event property access |
| packages/api-langchain-js/src/agents/index.ts | Refactored agent configuration to use DeepAgents SubAgent structure with direct model/tools/systemPrompt properties instead of runnable wrappers |
| packages/api-langchain-js/package.json | Updated dependency versions, added FORCE_AZURE_OPENAI_API_KEY to start script, and removed unused langchain packages |
| "Authorization": "Bearer " + process.env["MCP_ECHO_PING_ACCESS_TOKEN"], | ||
| } | ||
| }, | ||
| accessToken: process.env["MCP_ECHO_PING_ACCESS_TOKEN"], |
Copilot
AI
Jan 7, 2026
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.
The authentication configuration has been changed from using 'requestInit.headers' with an Authorization header to using 'accessToken'. However, the 'mcp-bridge.ts' implementation still only extracts headers from 'requestInit.headers' (lines 16-19) and does not handle the new 'accessToken' field. This means the access token will not be sent with the requests, breaking authentication for the echo-ping service.
| accessToken: process.env["MCP_ECHO_PING_ACCESS_TOKEN"], | |
| requestInit: { | |
| headers: { | |
| Authorization: `Bearer ${process.env["MCP_ECHO_PING_ACCESS_TOKEN"]}`, | |
| }, | |
| }, |
| baseURL: process.env.AZURE_OPENAI_ENDPOINT, | ||
| }, | ||
| modelName: process.env.AZURE_OPENAI_DEPLOYMENT_NAME ?? "gpt-5", | ||
| modelName: process.env.AZURE_OPENAI_DEPLOYMENT_NAME ?? "gpt-5-mini", |
Copilot
AI
Jan 7, 2026
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.
The default model name has been changed to "gpt-5-mini", but this model does not exist in Azure OpenAI. Valid GPT-4 model names include "gpt-4", "gpt-4-turbo", "gpt-4o", "gpt-4o-mini", or valid GPT-3.5 models like "gpt-35-turbo". The model name "gpt-5-mini" will cause runtime errors when Azure OpenAI API is called without a valid AZURE_OPENAI_DEPLOYMENT_NAME environment variable.
| const agent = { | ||
| name: "EchoAgent", | ||
| description: "Echo back the received input. Do not respond with anything else. Always call the tools.", | ||
| runnable: createAgent({ | ||
| description: | ||
| "Echo back the received input. Do not respond with anything else. Always call the tools.", | ||
| model, | ||
| tools: echoTools, | ||
| systemPrompt: "You are an Echo Agent that echoes back the received input. Do not respond with anything else. Always call the tools.", | ||
| }) | ||
| systemPrompt: | ||
| "You are an Echo Agent that echoes back the received input. Do not respond with anything else. Always call the tools.", | ||
| }; |
Copilot
AI
Jan 7, 2026
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.
The agent structure has been changed to remove the 'runnable' property and instead spread the model, tools, and systemPrompt properties directly on the agent object. However, this change is incompatible with the 'SubAgent' type from 'deepagents' which expects an object with 'name', 'description', and 'runnable' properties. The new structure directly includes 'model', 'tools', and 'systemPrompt' which may not match the expected interface. This could cause type errors or runtime failures when creating the deep agent.
| const agent = { | ||
| name: "CustomerQueryAgent", | ||
| description: "Assists employees in better understanding customer needs, facilitating more accurate and personalized service. This agent is particularly useful for handling nuanced queries, such as specific travel preferences or budget constraints, which are common in travel agency interactions.", | ||
| runnable: createAgent({ | ||
| model, | ||
| name: "CustomerQueryAgent", | ||
| tools: customerTools, | ||
| systemPrompt: "You are a Customer Query Agent that assists employees in better understanding customer needs, facilitating more accurate and personalized service. This agent is particularly useful for handling nuanced queries, such as specific travel preferences or budget constraints, which are common in travel agency interactions.", | ||
| }), | ||
| description: | ||
| "Assists employees in better understanding customer needs, facilitating more accurate and personalized service. This agent is particularly useful for handling nuanced queries, such as specific travel preferences or budget constraints, which are common in travel agency interactions.", | ||
| model, | ||
| tools: customerTools, | ||
| systemPrompt: | ||
| "You are a Customer Query Agent that assists employees in better understanding customer needs, facilitating more accurate and personalized service. This agent is particularly useful for handling nuanced queries, such as specific travel preferences or budget constraints, which are common in travel agency interactions.", | ||
| }; |
Copilot
AI
Jan 7, 2026
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.
The agent structure has been changed to remove the 'runnable' property and instead spread the model, tools, and systemPrompt properties directly on the agent object. However, this change is incompatible with the 'SubAgent' type from 'deepagents' which expects an object with 'name', 'description', and 'runnable' properties. The new structure directly includes 'model', 'tools', and 'systemPrompt' which may not match the expected interface. This could cause type errors or runtime failures when creating the deep agent.
| "types": "dist/index.d.ts", | ||
| "scripts": { | ||
| "start": "tsx --watch src/server.ts", | ||
| "start": "FORCE_AZURE_OPENAI_API_KEY=true tsx --watch src/server.ts", |
Copilot
AI
Jan 7, 2026
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.
The start script sets FORCE_AZURE_OPENAI_API_KEY=true using Unix/Linux shell syntax, which will not work on Windows systems. This makes the project less portable. Consider using cross-platform tools like 'cross-env' (e.g., "cross-env FORCE_AZURE_OPENAI_API_KEY=true tsx --watch src/server.ts") to ensure the script works across all operating systems.
| if (parsedData.data.error) { | ||
| this.handleApiError( | ||
| "Server error: " + parsedData.data.error, | ||
| 0 | ||
| ); | ||
| return null; | ||
| } |
Copilot
AI
Jan 7, 2026
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.
The error handling logic accesses 'parsedData.data.error' without first verifying that 'parsedData.data' exists. If parsedData.data is null or undefined, this will throw a TypeError. Consider adding a null/undefined check for parsedData.data before accessing its error property.
| baseURL: process.env.AZURE_OPENAI_ENDPOINT, | ||
| }, | ||
| modelName: process.env.AZURE_OPENAI_DEPLOYMENT_NAME ?? "gpt-5", | ||
| modelName: process.env.AZURE_OPENAI_DEPLOYMENT_NAME ?? "gpt-5-mini", |
Copilot
AI
Jan 7, 2026
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.
The default model name has been changed to "gpt-5-mini", but this model does not exist in Azure OpenAI. Valid GPT-4 model names include "gpt-4", "gpt-4-turbo", "gpt-4o", "gpt-4o-mini", or valid GPT-3.5 models like "gpt-35-turbo". The model name "gpt-5-mini" will cause runtime errors when Azure OpenAI API is called without a valid AZURE_OPENAI_DEPLOYMENT_NAME environment variable.
| const agent = { | ||
| name: "ItineraryPlanningAgent", | ||
| description: "Creates a travel itinerary based on user preferences and requirements.", | ||
| runnable: createAgent({ | ||
| model, | ||
| tools: itineraryTools, | ||
| systemPrompt: "You are an Itinerary Planning Agent that creates travel itineraries based on user preferences and requirements.", | ||
| }), | ||
| description: | ||
| "Creates a travel itinerary based on user preferences and requirements.", | ||
| model, | ||
| tools: itineraryTools, | ||
| systemPrompt: | ||
| "You are an Itinerary Planning Agent that creates travel itineraries based on user preferences and requirements.", | ||
| }; |
Copilot
AI
Jan 7, 2026
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.
The agent structure has been changed to remove the 'runnable' property and instead spread the model, tools, and systemPrompt properties directly on the agent object. However, this change is incompatible with the 'SubAgent' type from 'deepagents' which expects an object with 'name', 'description', and 'runnable' properties. The new structure directly includes 'model', 'tools', and 'systemPrompt' which may not match the expected interface. This could cause type errors or runtime failures when creating the deep agent.
| const agent = { | ||
| name: "DestinationRecommendationAgent", | ||
| description: "Suggests destinations based on customer preferences and requirements.", | ||
| runnable: createAgent({ | ||
| model, | ||
| tools: destinationTools, | ||
| systemPrompt: "You are a Destination Recommendation Agent that suggests destinations based on customer preferences and requirements.", | ||
| }) | ||
| description: | ||
| "Suggests destinations based on customer preferences and requirements.", | ||
| model, | ||
| tools: destinationTools, | ||
| systemPrompt: | ||
| "You are a Destination Recommendation Agent that suggests destinations based on customer preferences and requirements.", | ||
| }; |
Copilot
AI
Jan 7, 2026
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.
The agent structure has been changed to remove the 'runnable' property and instead spread the model, tools, and systemPrompt properties directly on the agent object. However, this change is incompatible with the 'SubAgent' type from 'deepagents' which expects an object with 'name', 'description', and 'runnable' properties. The new structure directly includes 'model', 'tools', and 'systemPrompt' which may not match the expected interface. This could cause type errors or runtime failures when creating the deep agent.
| } else if (event.event === "on_tool_start") { | ||
| // Tool execution started | ||
| } else if (event === "on_tool_start") { | ||
| // // Tool execution started |
Copilot
AI
Jan 7, 2026
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.
The comment has an extra leading space and appears to be commented out or incomplete ("// // Tool execution started"). This should either be removed entirely or properly completed as a single-line comment without the extra spaces and duplicate comment markers.
| // // Tool execution started | |
| // Tool execution started |
No description provided.