Skip to content

Commit ef12477

Browse files
evan-onyxaronszanto
authored andcommitted
v1 answer refactor (onyx-dot-app#4721)
* v1 answer refactor * fix tests * good catch, tests * more cleanup
1 parent 975a30d commit ef12477

File tree

32 files changed

+123
-173
lines changed

32 files changed

+123
-173
lines changed

backend/onyx/agents/agent_search/dc_search_analysis/nodes/a1_search_objects.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ def search_objects(
3434
"""
3535

3636
graph_config = cast(GraphConfig, config["metadata"]["config"])
37-
question = graph_config.inputs.search_request.query
37+
question = graph_config.inputs.prompt_builder.raw_user_query
3838
search_tool = graph_config.tooling.search_tool
3939

40-
if search_tool is None or graph_config.inputs.search_request.persona is None:
40+
if search_tool is None or graph_config.inputs.persona is None:
4141
raise ValueError("Search tool and persona must be provided for DivCon search")
4242

4343
try:
44-
instructions = graph_config.inputs.search_request.persona.prompts[
45-
0
46-
].system_prompt
44+
instructions = graph_config.inputs.persona.prompts[0].system_prompt
4745

4846
agent_1_instructions = extract_section(
4947
instructions, "Agent Step 1:", "Agent Step 2:"

backend/onyx/agents/agent_search/dc_search_analysis/nodes/a2_research_object_source.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@ def research_object_source(
3535
datetime.now()
3636

3737
graph_config = cast(GraphConfig, config["metadata"]["config"])
38-
graph_config.inputs.search_request.query
3938
search_tool = graph_config.tooling.search_tool
40-
question = graph_config.inputs.search_request.query
39+
question = graph_config.inputs.prompt_builder.raw_user_query
4140
object, document_source = state.object_source_combination
4241

43-
if search_tool is None or graph_config.inputs.search_request.persona is None:
42+
if search_tool is None or graph_config.inputs.persona is None:
4443
raise ValueError("Search tool and persona must be provided for DivCon search")
4544

4645
try:
47-
instructions = graph_config.inputs.search_request.persona.prompts[
48-
0
49-
].system_prompt
46+
instructions = graph_config.inputs.persona.prompts[0].system_prompt
5047

5148
agent_2_instructions = extract_section(
5249
instructions, "Agent Step 2:", "Agent Step 3:"

backend/onyx/agents/agent_search/dc_search_analysis/nodes/a3_structure_research_by_object.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from collections import defaultdict
2-
from datetime import datetime
3-
from typing import cast
42
from typing import Dict
53
from typing import List
64

@@ -11,7 +9,6 @@
119
from onyx.agents.agent_search.dc_search_analysis.states import (
1210
ObjectResearchInformationUpdate,
1311
)
14-
from onyx.agents.agent_search.models import GraphConfig
1512
from onyx.agents.agent_search.shared_graph_utils.utils import write_custom_event
1613
from onyx.chat.models import AgentAnswerPiece
1714
from onyx.utils.logger import setup_logger
@@ -25,10 +22,6 @@ def structure_research_by_object(
2522
"""
2623
LangGraph node to start the agentic search process.
2724
"""
28-
datetime.now()
29-
30-
graph_config = cast(GraphConfig, config["metadata"]["config"])
31-
graph_config.inputs.search_request.query
3225

3326
write_custom_event(
3427
"initial_agent_answer",

backend/onyx/agents/agent_search/dc_search_analysis/nodes/a4_consolidate_object_research.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ def consolidate_object_research(
2727
LangGraph node to start the agentic search process.
2828
"""
2929
graph_config = cast(GraphConfig, config["metadata"]["config"])
30-
graph_config.inputs.search_request.query
3130
search_tool = graph_config.tooling.search_tool
32-
question = graph_config.inputs.search_request.query
31+
question = graph_config.inputs.prompt_builder.raw_user_query
3332

34-
if search_tool is None or graph_config.inputs.search_request.persona is None:
33+
if search_tool is None or graph_config.inputs.persona is None:
3534
raise ValueError("Search tool and persona must be provided for DivCon search")
3635

37-
instructions = graph_config.inputs.search_request.persona.prompts[0].system_prompt
36+
instructions = graph_config.inputs.persona.prompts[0].system_prompt
3837

3938
agent_4_instructions = extract_section(
4039
instructions, "Agent Step 4:", "Agent Step 5:"

backend/onyx/agents/agent_search/dc_search_analysis/nodes/a5_consolidate_research.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ def consolidate_research(
2828
"""
2929
LangGraph node to start the agentic search process.
3030
"""
31-
datetime.now()
3231

3332
graph_config = cast(GraphConfig, config["metadata"]["config"])
34-
graph_config.inputs.search_request.query
3533

3634
search_tool = graph_config.tooling.search_tool
3735

@@ -46,11 +44,11 @@ def consolidate_research(
4644
writer,
4745
)
4846

49-
if search_tool is None or graph_config.inputs.search_request.persona is None:
47+
if search_tool is None or graph_config.inputs.persona is None:
5048
raise ValueError("Search tool and persona must be provided for DivCon search")
5149

5250
# Populate prompt
53-
instructions = graph_config.inputs.search_request.persona.prompts[0].system_prompt
51+
instructions = graph_config.inputs.persona.prompts[0].system_prompt
5452

5553
try:
5654
agent_5_instructions = extract_section(

backend/onyx/agents/agent_search/deep_search/initial/generate_individual_sub_answer/nodes/generate_sub_answer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def generate_sub_answer(
8585
context_docs = dedup_sort_inference_section_list(context_docs)
8686

8787
persona_contextualized_prompt = get_persona_agent_prompt_expressions(
88-
graph_config.inputs.search_request.persona
88+
graph_config.inputs.persona
8989
).contextualized_prompt
9090

9191
if len(context_docs) == 0:
@@ -106,7 +106,7 @@ def generate_sub_answer(
106106
fast_llm = graph_config.tooling.fast_llm
107107
msg = build_sub_question_answer_prompt(
108108
question=question,
109-
original_question=graph_config.inputs.search_request.query,
109+
original_question=graph_config.inputs.prompt_builder.raw_user_query,
110110
docs=context_docs,
111111
persona_specification=persona_contextualized_prompt,
112112
config=fast_llm.config,

backend/onyx/agents/agent_search/deep_search/initial/generate_initial_answer/nodes/generate_initial_answer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def generate_initial_answer(
105105
node_start_time = datetime.now()
106106

107107
graph_config = cast(GraphConfig, config["metadata"]["config"])
108-
question = graph_config.inputs.search_request.query
108+
question = graph_config.inputs.prompt_builder.raw_user_query
109109
prompt_enrichment_components = get_prompt_enrichment_components(graph_config)
110110

111111
# get all documents cited in sub-questions

backend/onyx/agents/agent_search/deep_search/initial/generate_sub_answers/nodes/decompose_orig_question.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def decompose_orig_question(
7575
node_start_time = datetime.now()
7676

7777
graph_config = cast(GraphConfig, config["metadata"]["config"])
78-
question = graph_config.inputs.search_request.query
78+
question = graph_config.inputs.prompt_builder.raw_user_query
7979
perform_initial_search_decomposition = (
8080
graph_config.behavior.perform_initial_search_decomposition
8181
)

backend/onyx/agents/agent_search/deep_search/initial/retrieve_orig_question_docs/nodes/format_orig_question_search_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def format_orig_question_search_input(
2121
logger.debug("generate_raw_search_data")
2222
graph_config = cast(GraphConfig, config["metadata"]["config"])
2323
return ExpandedRetrievalInput(
24-
question=graph_config.inputs.search_request.query,
24+
question=graph_config.inputs.prompt_builder.raw_user_query,
2525
base_search=True,
2626
sub_question_id=None, # This graph is always and only used for the original question
2727
log_messages=[],

backend/onyx/agents/agent_search/deep_search/main/edges.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ def route_initial_tool_choice(
3030
LangGraph edge to route to agent search.
3131
"""
3232
agent_config = cast(GraphConfig, config["metadata"]["config"])
33-
if state.tool_choice is not None:
34-
if (
35-
agent_config.behavior.use_agentic_search
36-
and agent_config.tooling.search_tool is not None
37-
and state.tool_choice.tool.name == agent_config.tooling.search_tool.name
38-
):
39-
return "start_agent_search"
40-
else:
41-
return "call_tool"
42-
else:
33+
if state.tool_choice is None:
4334
return "logging_node"
4435

36+
if (
37+
agent_config.behavior.use_agentic_search
38+
and agent_config.tooling.search_tool is not None
39+
and state.tool_choice.tool.name == agent_config.tooling.search_tool.name
40+
):
41+
return "start_agent_search"
42+
else:
43+
return "call_tool"
44+
4545

4646
def parallelize_initial_sub_question_answering(
4747
state: MainState,

0 commit comments

Comments
 (0)