Skip to content

Commit 816dba2

Browse files
committed
Add the Agent by LangChain.js
1 parent d306a46 commit 816dba2

14 files changed

Lines changed: 505 additions & 28 deletions

File tree

.github/dependabot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ updates:
2626
- '/agents/agent-voltagent/'
2727
- '/agents/agent-sdk/'
2828
- '/agents/agent-strands/'
29+
- './agents/agents-langchain/'
2930
- '/basic/cdk/'
3031
- '/basic/app/'
3132
- '/mcp/clients/mastra-mcp-client/'

agents/agent-langchain/.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
10+
!eslint.config.js
11+
12+
!types/*.d.ts
13+
!lambda/awslambda.d.ts
14+
!*.config.js
15+
.env*
16+
vite.config.js
17+
eslint.config.js
18+
tsconfig.tsbuildinfo

agents/agent-langchain/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { defineConfig } from 'eslint/config';
2+
import eslint from '@eslint/js';
3+
import stylistic from '@stylistic/eslint-plugin';
4+
import { configs, parser } from 'typescript-eslint';
5+
import eslintImport from 'eslint-plugin-import';
6+
7+
import { includeIgnoreFile } from '@eslint/compat';
8+
import path from 'node:path';
9+
import { fileURLToPath } from 'node:url';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
13+
const gitignorePath = path.resolve(__dirname, '.gitignore');
14+
15+
export default defineConfig(
16+
includeIgnoreFile(gitignorePath),
17+
{
18+
ignores: [
19+
'**/*.d.ts',
20+
'**/*.js',
21+
'node_modules/**/*',
22+
'out',
23+
'dist',
24+
'cdk.out',
25+
'.output',
26+
],
27+
},
28+
eslint.configs.recommended,
29+
...configs.strict,
30+
...configs.stylistic,
31+
{
32+
files: ['{bin,lib,lambda}/**/*.{ts,tsx}', '*.js'],
33+
plugins: {
34+
'@stylistic': stylistic,
35+
},
36+
languageOptions: {
37+
ecmaVersion: 'latest',
38+
sourceType: 'module',
39+
parser,
40+
parserOptions: {
41+
tsconfigRootDir: __dirname,
42+
project: ['./tsconfig-eslint.json'],
43+
},
44+
},
45+
extends: [
46+
eslintImport.flatConfigs.recommended,
47+
eslintImport.flatConfigs.typescript,
48+
],
49+
settings: {
50+
'import/resolver': {
51+
// You will also need to install and configure the TypeScript resolver
52+
// See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
53+
'typescript': true,
54+
'node': true,
55+
},
56+
},
57+
rules: {
58+
'@stylistic/semi': ['error', 'always'],
59+
'@stylistic/indent': ['error', 2],
60+
'@stylistic/comma-dangle': ['error', 'always-multiline'],
61+
'@stylistic/quotes': ['error', 'single'],
62+
},
63+
},
64+
);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "agent-langchain",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"type": "module",
7+
"scripts": {
8+
"build": "tsc --build --clean && tsc",
9+
"clean": "tsc --build --clean",
10+
"watch": "tsc -w",
11+
"test": "vitest run --passWithNoTests",
12+
"dev": "tsx src/index.ts",
13+
"lint": "eslint .",
14+
"lint-fix": "eslint . --fix"
15+
},
16+
"devDependencies": {
17+
"@eslint/compat": "^2.0.0",
18+
"@eslint/js": "^9.39.2",
19+
"@stylistic/eslint-plugin": "^5.6.1",
20+
"@types/aws-lambda": "^8.10.159",
21+
"@types/node": "^24.10.3",
22+
"@vitest/eslint-plugin": "^1.5.2",
23+
"dotenv": "^17.2.3",
24+
"eslint": "^9.39.2",
25+
"eslint-import-resolver-typescript": "^4.4.4",
26+
"eslint-plugin-import": "^2.32.0",
27+
"eslint-plugin-promise": "^7.2.1",
28+
"jiti": "^2.6.1",
29+
"tsx": "^4.21.0",
30+
"typescript": "^5.9.3",
31+
"typescript-eslint": "^8.49.0",
32+
"vite": "^7.2.7",
33+
"vite-tsconfig-paths": "^5.1.4",
34+
"vitest": "^4.0.15"
35+
},
36+
"dependencies": {
37+
"@arizeai/openinference-instrumentation-bedrock": "^0.4.8",
38+
"@arizeai/openinference-instrumentation-langchain": "^3.4.6",
39+
"@aws-lambda-powertools/logger": "^2.30.0",
40+
"@aws-sdk/credential-provider-node": "^3.948.0",
41+
"@langchain/aws": "^1.1.0",
42+
"@langchain/classic": "^1.0.6",
43+
"@langchain/core": "^1.1.5",
44+
"@langchain/langgraph": "^1.0.4",
45+
"@langchain/mcp-adapters": "^1.1.0",
46+
"@langchain/openai": "^1.2.0",
47+
"@opentelemetry/api": "^1.9.0",
48+
"@opentelemetry/exporter-trace-otlp-http": "^0.206.0",
49+
"@opentelemetry/exporter-trace-otlp-proto": "^0.206.0",
50+
"@opentelemetry/instrumentation": "^0.206.0",
51+
"@opentelemetry/resources": "^2.2.0",
52+
"@opentelemetry/sdk-node": "^0.206.0",
53+
"@opentelemetry/sdk-trace-base": "^2.2.0",
54+
"@opentelemetry/sdk-trace-node": "^2.2.0",
55+
"@opentelemetry/semantic-conventions": "^1.38.0",
56+
"@smithy/eventstream-codec": "^4.2.5",
57+
"constructs": "^10.4.4",
58+
"langchain": "^1.2.0",
59+
"source-map-support": "^0.5.21",
60+
"uuid": "^13.0.0",
61+
"zod": "^4.1.13"
62+
}
63+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
2+
import { createAgent } from "langchain";
3+
4+
const client = new MultiServerMCPClient({
5+
'aws-knowledge-mcp-server': {
6+
transport: "http",
7+
url: 'https://knowledge-mcp.global.api.aws',
8+
},
9+
context7: {
10+
command: 'npx',
11+
args: ['-y', '@upstash/context7-mcp@latest'],
12+
},
13+
14+
});
15+
16+
const tools = await client.getTools();
17+
18+
const agent = createAgent({
19+
model: "bedrock:global.amazon.nova-2-lite-v1:0",
20+
systemPrompt: `
21+
You are an assistant that helps architects design systems using Amazon Web Services (AWS). Your primary function is to answer user questions based on AWS knowledge and propose system architectures. When responding, follow these guidelines:
22+
23+
- If information is not available in aws-knowledge-mcp-server, clearly state that you don't know
24+
- Always cite your sources
25+
- When proposing architectures, provide multiple patterns whenever possible
26+
- Respond in the same language as the question
27+
- Keep responses concise yet informative
28+
- When returning Markdown, ensure it passes markdownlint-cli validation without warnings
29+
- For non-AWS information, use Context7 to resolve queries with up-to-date information
30+
- If Context7 cannot resolve the query, clearly state that you don't know
31+
`,
32+
tools,
33+
});
34+
35+
const stream = await agent.stream({
36+
messages: [{ role: "user", content: "MCPサーバーをサーバーレスで構築するには?" }],
37+
38+
}, { streamMode: "values" });
39+
for await (const chunk of stream) {
40+
console.log('Agent', chunk.messages);
41+
}
42+
process.exit(0);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "./tsconfig-test.json",
3+
"include": [
4+
"eslint.config.*s",
5+
"vitest.config.ts",
6+
"bin/**/*.ts",
7+
"lib/**/*.ts",
8+
"lambda/**/*.ts",
9+
"test/**/*.ts"
10+
],
11+
"exclude": [
12+
"node_modules",
13+
"cdk.out"
14+
]
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true
5+
},
6+
"include": [
7+
"vitest.config.ts"
8+
],
9+
"exclude": [
10+
"node_modules",
11+
"cdk.out"
12+
]
13+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "nodenext",
5+
"lib": [
6+
"esnext",
7+
"dom"
8+
],
9+
"moduleResolution": "nodenext",
10+
"moduleDetection": "force",
11+
"resolveJsonModule": true,
12+
"allowJs": true,
13+
"esModuleInterop": true,
14+
"isolatedModules": true,
15+
"declaration": true,
16+
"strict": true,
17+
"noImplicitAny": true,
18+
"strictNullChecks": true,
19+
"noImplicitThis": true,
20+
"alwaysStrict": true,
21+
"noUnusedLocals": false,
22+
"noUnusedParameters": false,
23+
"noImplicitReturns": true,
24+
"noFallthroughCasesInSwitch": false,
25+
"inlineSourceMap": true,
26+
"inlineSources": true,
27+
"experimentalDecorators": true,
28+
"strictPropertyInitialization": false,
29+
"skipLibCheck": true,
30+
"rootDir": "./src",
31+
"outDir": "./dist",
32+
"typeRoots": [
33+
"./node_modules",
34+
"./node_modules/@types",
35+
"./lambda"
36+
],
37+
"types": [
38+
"node"
39+
]
40+
},
41+
"include": [
42+
"src/**/*"
43+
],
44+
"exclude": [
45+
"node_modules",
46+
"cdk.out",
47+
"eslint.config.*",
48+
"vitest.config.*"
49+
]
50+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/// <reference types="vitest" />
2+
/// <reference types="vite/client" />
3+
4+
import { defineConfig } from 'vitest/config';
5+
import * as dotenv from 'dotenv';
6+
import { resolve } from 'path';
7+
8+
export default defineConfig({
9+
// モノレポ用の共通設定
10+
resolve: {
11+
alias: {
12+
// パッケージ間の直接参照
13+
'@llm-ts-example/common-core': resolve(__dirname, '../../common/core/src'),
14+
'@llm-ts-example/common-backend': resolve(__dirname, '../../common/backend/src'),
15+
},
16+
},
17+
server: {
18+
fs: {
19+
// モノレポ内のファイルアクセスを許可
20+
allow: ['..'],
21+
},
22+
},
23+
build: {
24+
target: 'esnext',
25+
rollupOptions: {
26+
// ESModuleとして出力
27+
output: {
28+
format: 'es',
29+
},
30+
},
31+
},
32+
root: '.',
33+
test: {
34+
environment: 'node',
35+
globals: true,
36+
isolate: true,
37+
env: dotenv.config({ path: '.env.test' }).parsed,
38+
testTimeout: 30000,
39+
},
40+
// resolve: {
41+
// conditions: ['development'],
42+
// }
43+
});

0 commit comments

Comments
 (0)