Skip to content

Commit 0f6f144

Browse files
committed
update interrupt
1 parent c310945 commit 0f6f144

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

src/memory_agent/graph.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ChatOpenAI } from "@langchain/openai";
22
import {
33
task,
44
entrypoint,
5-
interrupt,
65
addMessages,
76
getPreviousState,
87
} from "@langchain/langgraph";
@@ -13,7 +12,7 @@ import {
1312
} from "@langchain/core/messages";
1413
import { initializeTools } from "./tools.js";
1514
import { createCheckpointer } from "./checkpointer.js";
16-
import { AGENT_PROMPT, HELP_PHRASE } from "./prompts.js";
15+
import { AGENT_PROMPT } from "./prompts.js";
1716
import { ToolCall } from "@langchain/core/messages/tool";
1817

1918
// Create workflow
@@ -73,17 +72,6 @@ export const agent = entrypoint(
7372

7473
while (true) {
7574
if (!llmResponse.tool_calls?.length) {
76-
if (llmResponse.content.toString().includes(HELP_PHRASE)) {
77-
const humanResponse = interrupt({
78-
current_response: llmResponse.content,
79-
action: "Please provide guidance on how to answer this question.",
80-
});
81-
currentMessages = addMessages(currentMessages, [
82-
llmResponse,
83-
humanResponse,
84-
]);
85-
continue;
86-
}
8775
break;
8876
}
8977

src/memory_agent/prompts.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Define default prompts
22

3-
export const HELP_PHRASE = `I am calling my supervisor for assistance.`;
4-
53
export const AGENT_PROMPT = `You are an HR Support Assistant. Your role is to help employees with questions about company policies.
64
You have access to a database of HR policies through the searchPolicies tool.
75
@@ -21,6 +19,4 @@ Think through this step by step:
2119
1. What specific policy information is needed?
2220
2. Do I have this information in the current policies?
2321
3. Should I search for more policies or request human help?
24-
4. How should I format my response?
25-
26-
If you get stuck, you can always respond directly with a message containing the following: "${HELP_PHRASE}"`;
22+
4. How should I format my response?`

src/memory_agent/tools.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { LangGraphRunnableConfig } from "@langchain/langgraph";
1+
import { LangGraphRunnableConfig, interrupt } from "@langchain/langgraph";
22
import { tool } from "@langchain/core/tools";
33
import { z } from "zod";
44
import { MongoDBAtlasVectorSearch } from "@langchain/mongodb";
55
import { OpenAIEmbeddings } from "@langchain/openai";
66
import { Document } from "@langchain/core/documents";
77
import { MongoClient } from "mongodb";
8-
import { HELP_PHRASE } from "./prompts.js";
98

109
/**
1110
* Initialize tools within a function so that they have access to the current
@@ -77,9 +76,8 @@ export function initializeTools(config?: LangGraphRunnableConfig) {
7776
*/
7877
async function humanAssistance(opts: { query: string }): Promise<string> {
7978
const { query } = opts;
80-
81-
// This will be intercepted by the interrupt handler
82-
return `Be sure to include the following in your response: "${HELP_PHRASE} ${query}"`;
79+
const humanResponse = await interrupt({query});
80+
return humanResponse.content.toString();
8381
}
8482

8583
const humanAssistanceTool = tool(humanAssistance, {

0 commit comments

Comments
 (0)