Skip to content

Commit a3497f3

Browse files
joachim-danswerOrbital-Web
authored andcommitted
improvements
1 parent 4a58651 commit a3497f3

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

backend/onyx/agents/agent_search/dr/nodes/dr_a1_orchestrator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from onyx.agents.agent_search.shared_graph_utils.utils import (
2121
get_langgraph_node_log_string,
2222
)
23+
from onyx.agents.agent_search.shared_graph_utils.utils import write_custom_event
24+
from onyx.chat.models import AgentAnswerPiece
2325
from onyx.kg.utils.extraction_utils import get_entity_types_str
2426
from onyx.kg.utils.extraction_utils import get_relationship_types_str
2527
from onyx.prompts.dr_prompts import FAST_DR_DECISION_PROMPT
@@ -146,6 +148,17 @@ def orchestrator(
146148
except Exception as e:
147149
logger.error(f"Error in plan generation: {e}")
148150
raise e
151+
152+
write_custom_event(
153+
"basic_response",
154+
AgentAnswerPiece(
155+
answer_piece=f"\n\nHIGH_LEVEL PLAN: {plan_information.plan}\n\n\n",
156+
level=0,
157+
level_question_num=0,
158+
answer_type="agent_level_answer",
159+
),
160+
writer,
161+
)
149162
else:
150163
plan_information = state.plan_of_record[-1]
151164

backend/onyx/agents/agent_search/dr/nodes/dr_a2_closer.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
from datetime import datetime
22

3-
from langchain_core.messages import HumanMessage
43
from langchain_core.runnables import RunnableConfig
54
from langgraph.types import StreamWriter
65

76
from onyx.agents.agent_search.dr.states import FinalUpdate
87
from onyx.agents.agent_search.dr.states import MainState
98
from onyx.agents.agent_search.dr.utils import aggregate_context
9+
from onyx.agents.agent_search.shared_graph_utils.llm import get_answer_from_llm
1010
from onyx.agents.agent_search.shared_graph_utils.utils import (
1111
get_langgraph_node_log_string,
1212
)
1313
from onyx.agents.agent_search.shared_graph_utils.utils import write_custom_event
1414
from onyx.chat.models import AgentAnswerPiece
1515
from onyx.prompts.dr_prompts import FINAL_ANSWER_PROMPT
1616
from onyx.utils.logger import setup_logger
17-
from onyx.utils.threadpool_concurrency import run_with_timeout
1817

1918
logger = setup_logger()
2019

@@ -39,27 +38,13 @@ def closer(
3938
"---base_question---", base_question
4039
).replace("---iteration_responses_string---", iteration_responses_string)
4140

42-
msg = [
43-
HumanMessage(
44-
content=final_answer_prompt,
45-
)
46-
]
47-
48-
primary_llm = config["metadata"]["config"].tooling.primary_llm
49-
50-
try:
51-
llm_response = run_with_timeout(
52-
25,
53-
primary_llm.invoke,
54-
prompt=msg,
55-
timeout_override=45,
56-
max_tokens=1500,
57-
)
58-
59-
final_answer = str(llm_response.content).replace("```json\n", "")
60-
61-
except Exception as e:
62-
raise ValueError(f"Error in closer: {e}")
41+
final_answer = get_answer_from_llm(
42+
llm=config["metadata"]["config"].tooling.primary_llm,
43+
prompt=final_answer_prompt,
44+
timeout=60,
45+
max_tokens=1500,
46+
timeout_override=60,
47+
)
6348

6449
logger.debug(final_answer)
6550

backend/onyx/agents/agent_search/dr/nodes/dr_i1_search.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,33 @@ def search(
155155
write_custom_event(
156156
"basic_response",
157157
AgentAnswerPiece(
158-
answer_piece=f"\n\nSUB-QUESTION: {search_query}\n\nANSWER: {search_answer}\n\n",
158+
answer_piece=f"\n\nSUB-QUESTION (SEARCH): {search_query}\n\n-> answered!\n\n",
159159
level=0,
160160
level_question_num=0,
161161
answer_type="agent_level_answer",
162162
),
163163
writer,
164164
)
165165

166+
# handle citations
167+
166168
citation_numbers = get_cited_document_numbers(search_answer)
169+
citation_number_replacement_dict = {
170+
original_index: start_1_based_index + 1
171+
for start_1_based_index, original_index in enumerate(citation_numbers)
172+
}
167173

168174
cited_documents: list[InferenceSection] = []
169175

170176
for citation_number in citation_numbers:
171177
cited_documents.append(retrieved_docs[citation_number - 1])
172178

179+
# change citations from search answer
180+
for original_index, replacement_index in citation_number_replacement_dict.items():
181+
search_answer = search_answer.replace(
182+
f"[{original_index}]", f"[{replacement_index}]"
183+
)
184+
173185
return AnswerUpdate(
174186
answers=[search_answer],
175187
iteration_responses=[

backend/onyx/prompts/dr_prompts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@
491491
- note that the sub-answers to the sub-questions are designed to be high-level, mostly \
492492
focussing on providing the citations and providing some answer facts. But the \
493493
main content should be in the cited documents for each sub-question.
494+
- make sure that a the text from a document that you use is NOT TAKEN OUT OF CONTEXT!
495+
- do not make anything up! Only use the information provided in the documents, or, \
496+
if no documents are provided for a sub-answer, in the actual sub-answer.
494497
- Provide a thoughtful answer that is concise and to the point, but that is detailed.
495498
- Please cite your sources inline in format [2], [4], etc! The numbers of the documents \
496499
are provided above.

0 commit comments

Comments
 (0)