Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jojohannsen committed Aug 9, 2024
1 parent 0071260 commit a77819c
Show file tree
Hide file tree
Showing 5 changed files with 922 additions and 270 deletions.
2 changes: 1 addition & 1 deletion graph_gen/gen_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ def gen_graph(graph_name, graph_spec, memory=None):
mem_spec = ""
if memory:
mem_spec = f"checkpointer={memory}"
return graph_setup + "\n".join(node_code) + "\n\n" + f"{graph_name} = {graph_name}.compile({mem_spec})"
return graph_setup + "\n".join(node_code) + "\n\n" + f"{graph_name} = {graph_name}.compile({mem_spec})"
43 changes: 38 additions & 5 deletions human-in-loop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"id": "3498f044-2381-4e02-bc8c-d1b3c4c0dabb",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "5e71f0e6-2cf4-4f4b-86eb-07594bedbda2",
"metadata": {},
"outputs": [],
Expand All @@ -58,10 +58,43 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"id": "b8616228-ae71-46a9-82c3-9d54483729fc",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"human_in_loop = StateGraph(AgentState)\n",
"human_in_loop.add_node('call_model', call_model)\n",
"human_in_loop.add_node('ask_human_approval', ask_human_approval)\n",
"human_in_loop.add_node('call_tool', call_tool)\n",
"\n",
"human_in_loop.set_entry_point('call_model')\n",
"\n",
"def after_call_model(state: AgentState):\n",
" if should_call_tool(state):\n",
" return 'ask_human_approval'\n",
" return END\n",
"\n",
"call_model_dict = {'ask_human_approval': 'ask_human_approval', END: END}\n",
"human_in_loop.add_conditional_edges('call_model', after_call_model, call_model_dict)\n",
"\n",
"def after_ask_human_approval(state: AgentState):\n",
" if human_allows_tool_call(state):\n",
" return 'call_tool'\n",
" return END\n",
"\n",
"ask_human_approval_dict = {'call_tool': 'call_tool', END: END}\n",
"human_in_loop.add_conditional_edges('ask_human_approval', after_ask_human_approval, ask_human_approval_dict)\n",
"\n",
"human_in_loop.add_edge('call_tool', 'call_model')\n",
"\n",
"human_in_loop = human_in_loop.compile()\n"
]
}
],
"source": [
"# Tools\n",
"tools = [TavilySearchResults(max_results=1)]\n",
Expand Down Expand Up @@ -140,7 +173,7 @@
"\n",
"# The graph code\n",
"graph_code = gen_graph(\"human_in_loop\", graph_spec)\n",
"#print(graph_code)\n",
"print(graph_code)\n",
"exec(graph_code)"
]
},
Expand Down
Loading

0 comments on commit a77819c

Please sign in to comment.