-
Notifications
You must be signed in to change notification settings - Fork 342
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
WIP: Example: Human in the loop over the network #58
base: main
Are you sure you want to change the base?
WIP: Example: Human in the loop over the network #58
Conversation
@albertpurnama is attempting to deploy a commit to the LangChain Team on Vercel. A member of the Team first needs to authorize it. |
// Get the agent state, check whether the agent can be resumed. | ||
const state = await agent.getState({ | ||
configurable: { thread_id: threadId }, | ||
}); | ||
|
||
const isBeginning = | ||
state.next.length === 0 && Object.keys(state.values).length === 0; | ||
|
||
let runInput: { messages: (AIMessage | HumanMessage)[] } | Command = | ||
new Command({ | ||
resume: messages.findLast((m: any) => m.role === "user")?.content, | ||
update: { | ||
isResuming: true, // Important if you have workflows that you want to ignore when resuming | ||
}, | ||
}); | ||
|
||
if (isBeginning) { | ||
runInput = { | ||
messages, | ||
}; | ||
} |
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.
there's gotta be a simpler way to do this, I simply want to check whether the current state is resumable or not, or whether it is in its end node?
I'm hoping for something like state.currentNode
to get the string name of the node, if it is __end__
then I know it's not resumable. something like this exist?
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.
Wouldn't it just be if state.next
were populated?
@@ -0,0 +1,88 @@ | |||
import { ChatWindow } from "@/components/ChatWindow"; |
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.
these are copied over from agents/page.tsx
// isResuming is very useful if you want to ignore some workflow in some node | ||
// that you want to ignore when the graph is resuming the run for the first time | ||
// after interrupt happened | ||
isResuming: Annotation<boolean>({ |
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.
If you are just want to override the last value in the state, you can just do:
isResuming: Annotation<boolean>,
...
"calculatorAgent helps with calculations" + | ||
"mainAgent is the main agent that handles the user's message", | ||
), | ||
response: z.string().describe("Human readable response to user's message"), |
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.
Small potential optimization: put response
first. The LLM will generate it before generating a goto
value and it can help steer it to better decisions.
const { gotoNext } = state; | ||
|
||
// we're not using the object here. we ask for string feedback. | ||
const input = await interrupt<{}, string>({}); |
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.
Any reason for the type params?
}; | ||
|
||
const convertLangChainMessageToVercelMessage = (message: BaseMessage) => { | ||
if (message._getType() === "human") { |
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.
You can use .getType()
now
"@langchain/langgraph": "^0.2.20", | ||
"@langchain/core": "^0.3.27", | ||
"@langchain/langgraph": "^0.2.39", | ||
"@langchain/langgraph-checkpoint-postgres": "^0.0.2", |
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.
Small nit - should we make this a peer dep?
This PR adds an example page for human in the loop process over the network
There's a couple of package updates that is required for
interrupt
to run one of them is@langchain/core
.TODOs: