Skip to content

Commit

Permalink
updated dynamically returning directly ntbk
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Aug 19, 2024
1 parent cc6d3b5 commit bffdc64
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions examples/how-tos/dynamically-returning-directly.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,14 @@
},
"outputs": [],
"source": [
"import { StateGraphArgs } from \"@langchain/langgraph\";\n",
"\n",
"interface AgentState {\n",
" messages: BaseMessage[];\n",
"}\n",
"import { Annotation } from \"@langchain/langgraph\";\n",
"import { BaseMessage } from \"@langchain/core/messages\";\n",
"\n",
"const agentState: StateGraphArgs<AgentState>[\"channels\"] = {\n",
" messages: {\n",
" value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),\n",
" default: () => [],\n",
" },\n",
"};"
"const AgentState = Annotation.Root({\n",
" messages: Annotation<BaseMessage[]>({\n",
" reducer: (x, y) => x.concat(y),\n",
" }),\n",
"});"
]
},
{
Expand Down Expand Up @@ -266,7 +262,7 @@
"import { AIMessage } from \"@langchain/core/messages\";\n",
"\n",
"// Define the function that determines whether to continue or not\n",
"const shouldContinue = (state: AgentState) => {\n",
"const shouldContinue = (state: typeof AgentState.State) => {\n",
" const { messages } = state;\n",
" const lastMessage = messages[messages.length - 1] as AIMessage;\n",
" // If there is no function call, then we finish\n",
Expand All @@ -284,7 +280,7 @@
"};\n",
"\n",
"// Define the function that calls the model\n",
"const callModel = async (state: AgentState, config?: RunnableConfig) => {\n",
"const callModel = async (state: typeof AgentState.State, config?: RunnableConfig) => {\n",
" const messages = state.messages;\n",
" const response = await boundModel.invoke(messages, config);\n",
" // We return an object, because this will get added to the existing list\n",
Expand Down Expand Up @@ -312,7 +308,7 @@
"import { START, StateGraph } from \"@langchain/langgraph\";\n",
"\n",
"// Define a new graph\n",
"const workflow = new StateGraph({ channels: agentState })\n",
"const workflow = new StateGraph(AgentState)\n",
" // Define the two nodes we will cycle between\n",
" .addNode(\"agent\", callModel)\n",
" // Note the \"action\" and \"final\" nodes are identical!\n",
Expand Down Expand Up @@ -359,13 +355,7 @@
"text": [
"[human]: what is the weather in sf\n",
"-----\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"[ai]: \n",
"Tools: \n",
"- search({\"query\":\"weather in San Francisco\"})\n",
Expand Down Expand Up @@ -455,14 +445,6 @@
"```\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e7f7cbc2-6b5d-4708-bed9-4a977fd72476",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit bffdc64

Please sign in to comment.