6
6
conducting research, and formulating responses.
7
7
"""
8
8
9
- from typing import Any , Literal , TypedDict , cast
9
+ from typing import Any , Literal , Type , TypedDict , cast
10
10
11
11
from langchain_core .messages import BaseMessage
12
12
from langchain_core .runnables import RunnableConfig
@@ -33,6 +33,10 @@ async def analyze_and_route_query(
33
33
Returns:
34
34
dict[str, Router]: A dictionary containing the 'router' key with the classification result (classification type and logic).
35
35
"""
36
+ # allow skipping the router for testing
37
+ if state .router and state .router ["logic" ]:
38
+ return {"router" : state .router }
39
+
36
40
configuration = AgentConfiguration .from_runnable_config (config )
37
41
model = load_chat_model (configuration .query_model )
38
42
messages = [
@@ -207,22 +211,31 @@ async def respond(
207
211
208
212
209
213
# Define the graph
210
- builder = StateGraph (AgentState , input = InputState , config_schema = AgentConfiguration )
211
- builder .add_node (analyze_and_route_query )
212
- builder .add_node (ask_for_more_info )
213
- builder .add_node (respond_to_general_query )
214
- builder .add_node (conduct_research )
215
- builder .add_node (create_research_plan )
216
- builder .add_node (respond )
217
-
218
- builder .add_edge (START , "analyze_and_route_query" )
219
- builder .add_conditional_edges ("analyze_and_route_query" , route_query )
220
- builder .add_edge ("create_research_plan" , "conduct_research" )
221
- builder .add_conditional_edges ("conduct_research" , check_finished )
222
- builder .add_edge ("ask_for_more_info" , END )
223
- builder .add_edge ("respond_to_general_query" , END )
224
- builder .add_edge ("respond" , END )
225
-
226
- # Compile into a graph object that you can invoke and deploy.
227
- graph = builder .compile ()
228
- graph .name = "RetrievalGraph"
214
+
215
+
216
+ def make_graph (* , input_schema : Type [Any ]):
217
+ builder = StateGraph (
218
+ AgentState , input = input_schema , config_schema = AgentConfiguration
219
+ )
220
+ builder .add_node (analyze_and_route_query )
221
+ builder .add_node (ask_for_more_info )
222
+ builder .add_node (respond_to_general_query )
223
+ builder .add_node (conduct_research )
224
+ builder .add_node (create_research_plan )
225
+ builder .add_node (respond )
226
+
227
+ builder .add_edge (START , "analyze_and_route_query" )
228
+ builder .add_conditional_edges ("analyze_and_route_query" , route_query )
229
+ builder .add_edge ("create_research_plan" , "conduct_research" )
230
+ builder .add_conditional_edges ("conduct_research" , check_finished )
231
+ builder .add_edge ("ask_for_more_info" , END )
232
+ builder .add_edge ("respond_to_general_query" , END )
233
+ builder .add_edge ("respond" , END )
234
+
235
+ # Compile into a graph object that you can invoke and deploy.
236
+ graph = builder .compile ()
237
+ graph .name = "RetrievalGraph"
238
+ return graph
239
+
240
+
241
+ graph = make_graph (input_schema = InputState )
0 commit comments