Skip to content

Commit 89c6448

Browse files
authored
Merge pull request #1 from codeSTACKr/jacob/versions
feat: Upgrade versions, small fixes
2 parents ed32a0b + 0101b17 commit 89c6448

13 files changed

+259
-1968
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
project: "./tsconfig.json",
1111
sourceType: "module",
1212
},
13-
plugins: ["import", "@typescript-eslint", "no-instanceof"],
13+
plugins: ["import", "@typescript-eslint"],
1414
ignorePatterns: [
1515
".eslintrc.cjs",
1616
"scripts",
@@ -23,7 +23,6 @@ module.exports = {
2323
],
2424
rules: {
2525
"no-process-env": 0,
26-
"no-instanceof/no-instanceof": 2,
2726
"@typescript-eslint/explicit-module-boundary-types": 0,
2827
"@typescript-eslint/no-empty-function": 0,
2928
"@typescript-eslint/no-non-null-assertion": 0,
@@ -48,6 +47,7 @@ module.exports = {
4847
"no-await-in-loop": 0,
4948
"no-bitwise": 0,
5049
"no-console": 0,
50+
"no-constant-condition": 0,
5151
"no-restricted-syntax": 0,
5252
"no-shadow": 0,
5353
"no-continue": 0,

data/hr_policies.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const hrPolicies: HRPolicy[] = [
2424
* Multiple team members taking time off simultaneously
2525
`,
2626
lastUpdated: new Date("2024-01-01"),
27-
requiresManagerApproval: true
27+
requiresManagerApproval: true,
2828
},
2929
{
3030
id: "SICK001",
@@ -42,7 +42,7 @@ export const hrPolicies: HRPolicy[] = [
4242
* Care for immediate family members
4343
`,
4444
lastUpdated: new Date("2024-01-01"),
45-
requiresManagerApproval: false
45+
requiresManagerApproval: false,
4646
},
4747
{
4848
id: "WFH001",
@@ -61,7 +61,7 @@ export const hrPolicies: HRPolicy[] = [
6161
- Permanent remote work requires VP approval
6262
`,
6363
lastUpdated: new Date("2024-02-15"),
64-
requiresManagerApproval: true
64+
requiresManagerApproval: true,
6565
},
6666
{
6767
id: "BEN001",
@@ -81,7 +81,7 @@ export const hrPolicies: HRPolicy[] = [
8181
- New employees: 30-day enrollment window
8282
`,
8383
lastUpdated: new Date("2024-01-15"),
84-
requiresManagerApproval: false
84+
requiresManagerApproval: false,
8585
},
8686
{
8787
id: "PAR001",
@@ -98,6 +98,6 @@ export const hrPolicies: HRPolicy[] = [
9898
- Flexible return-to-work arrangements available
9999
`,
100100
lastUpdated: new Date("2024-01-01"),
101-
requiresManagerApproval: true
102-
}
103-
];
101+
requiresManagerApproval: true,
102+
},
103+
];

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
"test:all": "yarn test && yarn test:int && yarn lint:langgraph"
2020
},
2121
"dependencies": {
22-
"@langchain/core": "^0.1.48",
23-
"@langchain/langgraph": "^0.0.12",
22+
"@langchain/core": "^0.3.40",
23+
"@langchain/langgraph": "^0.2.46",
24+
"@langchain/langgraph-checkpoint-mongodb": "^0.0.5",
2425
"@langchain/mongodb": "^0.1.0",
25-
"@langchain/openai": "^0.0.14",
26+
"@langchain/openai": "^0.4.4",
2627
"dotenv": "^16.4.5",
27-
"langchain": "^0.1.21",
28+
"langchain": "^0.3.15",
2829
"mongodb": "^6.3.0",
2930
"ts-node": "^10.9.2",
3031
"zod": "^3.22.4"
3132
},
3233
"devDependencies": {
34+
"@tsconfig/recommended": "^1.0.8",
3335
"@types/jest": "^29.5.0",
3436
"@types/node": "^20.14.8",
3537
"@typescript-eslint/eslint-plugin": "^5.59.8",

scripts/seed-db.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ async function createSearchIndex(db: any) {
1717

1818
// Create Atlas Vector Search index
1919
await db.collection("hr_policies").createIndex(
20-
{ "vector_embedding": 1 },
20+
{ vector_embedding: 1 },
2121
{
2222
name: "vector_index",
23-
background: true
24-
}
23+
background: true,
24+
},
2525
);
2626

2727
// Create Atlas Vector Search index definition
@@ -32,19 +32,21 @@ async function createSearchIndex(db: any) {
3232
vector_embedding: {
3333
dimensions: 1536,
3434
similarity: "cosine",
35-
type: "knnVector"
36-
}
37-
}
38-
}
35+
type: "knnVector",
36+
},
37+
},
38+
},
3939
};
4040

4141
// Create the vector search index using the Atlas Search API
4242
await db.command({
4343
createSearchIndexes: "hr_policies",
44-
indexes: [{
45-
name: "vector_search_index",
46-
definition: indexDefinition
47-
}]
44+
indexes: [
45+
{
46+
name: "vector_search_index",
47+
definition: indexDefinition,
48+
},
49+
],
4850
});
4951

5052
console.log("Created Atlas Vector Search index");
@@ -70,11 +72,11 @@ async function generateEmbeddings(policies: typeof hrPolicies) {
7072
lastUpdated: policy.lastUpdated,
7173
requiresManagerApproval: policy.requiresManagerApproval,
7274
},
73-
})
75+
}),
7476
);
7577

7678
const vectors = await embeddings.embedDocuments(
77-
documents.map((doc) => doc.pageContent)
79+
documents.map((doc) => doc.pageContent),
7880
);
7981

8082
return documents.map((doc, i) => ({
@@ -92,33 +94,33 @@ async function seedDatabase() {
9294
console.log("Connected to MongoDB");
9395

9496
const db = client.db();
95-
97+
9698
// Create collections if they don't exist
9799
await db.createCollection("hr_policies");
98100
await db.createCollection("checkpoints");
99-
101+
100102
// Clear existing policies
101103
await db.collection("hr_policies").deleteMany({});
102-
104+
103105
// Generate embeddings and insert policies
104106
console.log("Generating embeddings for HR policies...");
105107
const policiesWithEmbeddings = await generateEmbeddings(hrPolicies);
106-
108+
107109
// Insert policies with embeddings
108-
const result = await db.collection("hr_policies").insertMany(policiesWithEmbeddings);
110+
const result = await db
111+
.collection("hr_policies")
112+
.insertMany(policiesWithEmbeddings);
109113
console.log(`Inserted ${result.insertedCount} HR policies with embeddings`);
110114

111115
// Create vector search index
112116
console.log("Creating vector search index...");
113117
await createSearchIndex(db);
114118

115119
// Create TTL index for checkpoints (expire after 24 hours of inactivity)
116-
await db.collection("checkpoints").createIndex(
117-
{ "ts": 1 },
118-
{ expireAfterSeconds: 86400 }
119-
);
120+
await db
121+
.collection("checkpoints")
122+
.createIndex({ ts: 1 }, { expireAfterSeconds: 86400 });
120123
console.log("Created TTL index for checkpoints");
121-
122124
} catch (error) {
123125
console.error("Error seeding database:", error);
124126
process.exit(1);
@@ -129,4 +131,4 @@ async function seedDatabase() {
129131
}
130132

131133
// Run seeding
132-
seedDatabase().catch(console.error);
134+
seedDatabase().catch(console.error);

src/index.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ async function main() {
3737

3838
try {
3939
// Start the workflow with thread configuration
40-
const stream = await agent.stream([
41-
new HumanMessage(question)
42-
], config);
40+
const stream = await agent.stream([new HumanMessage(question)], config);
4341

4442
for await (const step of stream) {
4543
for (const [taskName, update] of Object.entries(step)) {
4644
// Skip the final agent output
4745
if (taskName === "hr_support") continue;
48-
46+
4947
const message = update as BaseMessage;
5048
console.log(`\n${taskName}:`);
5149
prettyPrintMessage(message);
@@ -54,27 +52,34 @@ async function main() {
5452
// Handle interrupt for human assistance
5553
if ("__interrupt__" in step) {
5654
console.log("\nNeeds human assistance!");
57-
console.log("Current AI Response:", step.__interrupt__[0].value.current_response);
55+
console.log(
56+
"Current AI Response:",
57+
step.__interrupt__[0].value.current_response,
58+
);
5859
console.log("Waiting for human guidance...");
5960

6061
// In a real application, you would get the human response from a UI
6162
// For this demo, we'll simulate a human response
62-
const humanResponse = "Please refer the employee to their manager for guidance on this topic.";
63-
63+
const humanResponse =
64+
"Please refer the employee to their manager for guidance on this topic.";
65+
6466
// Resume the workflow with the human response
6567
const resumeStream = await agent.stream(
66-
new Command({ resume: humanResponse }),
67-
config
68+
new Command({ resume: humanResponse }),
69+
config,
6870
);
6971

7072
for await (const resumeStep of resumeStream) {
7173
if (resumeStep.hr_support) {
7274
console.log("\nFinal Response:");
7375
console.log("AI Response:", resumeStep.hr_support.ai_response);
74-
console.log("Human Guidance:", resumeStep.hr_support.human_response);
76+
console.log(
77+
"Human Guidance:",
78+
resumeStep.hr_support.human_response,
79+
);
7580
}
7681
}
77-
}
82+
}
7883
// Handle normal response
7984
else if (step.hr_support) {
8085
console.log("\nFinal Response:");
@@ -87,4 +92,4 @@ async function main() {
8792
}
8893
}
8994

90-
main().catch(console.error);
95+
main().catch(console.error);

src/memory_agent/checkpointer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export async function createCheckpointer() {
66

77
return new MongoDBSaver({
88
client,
9-
checkpointCollectionName: "checkpoints"
9+
checkpointCollectionName: "checkpoints",
1010
});
11-
}
11+
}

src/memory_agent/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function ensureConfiguration(config?: LangGraphRunnableConfig) {
1515
const configurable = config?.configurable || {};
1616
return {
1717
userId: configurable?.userId || "default",
18-
model: configurable?.model || "openai/o3-mini",
18+
model: configurable?.model || "openai:o3-mini",
1919
systemPrompt: configurable?.systemPrompt || AGENT_PROMPT,
2020
};
2121
}

0 commit comments

Comments
 (0)