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
Binary file added docs/images/simplified-architecture.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,056 changes: 1,468 additions & 1,588 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"xo": [
{
"ignores": [
"**/*.genai.mjs"
"**/*.genai.mjs",
"**/vite.config.ts"
]
},
{
Expand Down Expand Up @@ -90,6 +91,7 @@
"import/extensions": "off",
"n/prefer-global/process": "off",
"no-new-func": "off",
"capitalized-comments": "off",
"unicorn/no-process-exit": "off",
"unicorn/prefer-add-event-listener": "off",
"unicorn/prefer-switch": "off",
Expand Down
12 changes: 6 additions & 6 deletions packages/agent-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
"@azure/identity": "^4.2.0",
"@azure/monitor-opentelemetry": "^1.12.0",
"@azure/storage-blob": "^12.17.0",
"@langchain/azure-cosmosdb": "^0.2.9",
"@langchain/core": "^0.3.18",
"@langchain/langgraph": "^0.4.9",
"@langchain/mcp-adapters": "^0.6.0",
"@langchain/openai": "^0.6.13",
"@langchain/azure-cosmosdb": "^1.0.0",
"@langchain/core": "^1.0.0",
"@langchain/langgraph": "^1.0.0",
"@langchain/mcp-adapters": "^1.0.0",
"@langchain/openai": "^1.0.0",
"@modelcontextprotocol/sdk": "^1.20.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.206.0",
"@opentelemetry/instrumentation": "^0.206.0",
"@opentelemetry/sdk-trace-base": "^2.1.0",
"@opentelemetry/sdk-trace-node": "^2.0.1",
"langchain": "^0.3.34"
"langchain": "^1.0.0"
},
"devDependencies": {
"@types/node": "^22",
Expand Down
14 changes: 7 additions & 7 deletions packages/agent-api/src/functions/chats-post.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Readable } from 'node:stream';
import { randomUUID } from 'node:crypto';
import { HttpRequest, InvocationContext, HttpResponseInit, app } from '@azure/functions';
import { createAgent, AIMessage, HumanMessage } from 'langchain';
import { ChatOpenAI } from '@langchain/openai';
import { AzureCosmsosDBNoSQLChatMessageHistory } from '@langchain/azure-cosmosdb';
import { createReactAgent } from '@langchain/langgraph/prebuilt';
import { AIMessage, HumanMessage } from '@langchain/core/messages';
import { loadMcpTools } from '@langchain/mcp-adapters';
import { StreamEvent } from '@langchain/core/tracers/log_stream.js';
import { StreamEvent } from '@langchain/core/dist/tracers/log_stream.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { getAzureOpenAiTokenProvider, getCredentials, getInternalUserId } from '../auth.js';
Expand Down Expand Up @@ -117,10 +116,10 @@ export async function postChats(request: HttpRequest, context: InvocationContext
const tools = await loadMcpTools('burger', client);
context.log(`Loaded ${tools.length} tools from Burger MCP server`);

const agent = createReactAgent({
llm: model,
const agent = createAgent({
model,
tools,
prompt: agentSystemPrompt,
systemPrompt: agentSystemPrompt,
});

const question = messages.at(-1)!.content;
Expand Down Expand Up @@ -160,7 +159,8 @@ export async function postChats(request: HttpRequest, context: InvocationContext
try {
if (content) {
// When no content is generated, do not update the history as it's likely an error
await chatHistory.addMessages([new HumanMessage(question), new AIMessage(content)]);
await chatHistory.addMessage(new HumanMessage(question));
await chatHistory.addMessage(new AIMessage(content));
context.log('Chat history updated successfully');

// Ensure the session title has finished generating
Expand Down
9 changes: 5 additions & 4 deletions packages/agent-api/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { useAzureMonitor } from '@azure/monitor-opentelemetry';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { LangChainInstrumentation } from '@arizeai/openinference-instrumentation-langchain';
import * as CallbackManagerModule from '@langchain/core/callbacks/manager';
// import { LangChainInstrumentation } from '@arizeai/openinference-instrumentation-langchain';
// import * as CallbackManagerModule from 'langchain';

let isTracingInitialized = false;
if (!isTracingInitialized) {
Expand Down Expand Up @@ -35,8 +35,9 @@ if (!isTracingInitialized) {
}

// Manually instrument LangChain's CallbackManager to capture traces
const langchainInstrumentation = new LangChainInstrumentation();
langchainInstrumentation.manuallyInstrument(CallbackManagerModule);
// TODO: temporarily disabled due to compatibility issues with LangChain v1 (PR in progress)
// const langchainInstrumentation = new LangChainInstrumentation();
// langchainInstrumentation.manuallyInstrument(CallbackManagerModule);

isTracingInitialized = true;
}
9 changes: 4 additions & 5 deletions packages/agent-cli/agent-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import path from 'node:path';
import fs from 'node:fs/promises';
import os from 'node:os';
import { DefaultAzureCredential, getBearerTokenProvider } from '@azure/identity';
import { createAgent, BaseMessage, HumanMessage, AIMessage } from 'langchain';
import { ChatOpenAI } from '@langchain/openai';
import { createReactAgent } from '@langchain/langgraph/prebuilt';
import { loadMcpTools } from '@langchain/mcp-adapters';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { BaseMessage, HumanMessage, AIMessage } from '@langchain/core/messages';
import dotenv from 'dotenv';

dotenv.config({ path: path.join(process.cwd(), '../../.env'), quiet: true });
Expand Down Expand Up @@ -179,10 +178,10 @@ export async function run() {
const tools = await loadMcpTools('burger', client);
console.log(`Loaded ${tools.length} tools from Burger MCP server`);

const agent = createReactAgent({
llm: model,
const agent = createAgent({
model,
tools,
prompt: agentSystemPrompt + (session.userId ? `\n\nUser ID: ${session.userId}` : ''),
systemPrompt: agentSystemPrompt + (session.userId ? `\n\nUser ID: ${session.userId}` : ''),
});

const chatHistory = convertHistoryToMessages(session.history);
Expand Down
10 changes: 5 additions & 5 deletions packages/agent-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"license": "MIT",
"dependencies": {
"@azure/identity": "^4.2.0",
"@langchain/core": "^0.3.18",
"@langchain/langgraph": "^0.4.9",
"@langchain/mcp-adapters": "^0.6.0",
"@langchain/openai": "^0.6.9",
"@langchain/core": "^1.0.0",
"@langchain/langgraph": "^1.0.0",
"@langchain/mcp-adapters": "^1.0.0",
"@langchain/openai": "^1.0.0",
"@modelcontextprotocol/sdk": "^1.20.0",
"dotenv": "^17.0.1",
"langchain": "^0.3.6"
"langchain": "^1.0.0"
},
"devDependencies": {
"@types/node": "^22",
Expand Down