30
30
from onyx .agents .agent_search .shared_graph_utils .utils import run_with_timeout
31
31
from onyx .agents .agent_search .shared_graph_utils .utils import write_custom_event
32
32
from onyx .agents .agent_search .utils import create_question_prompt
33
+ from onyx .configs .agent_configs import TF_DR_TIMEOUT_LONG
34
+ from onyx .configs .agent_configs import TF_DR_TIMEOUT_SHORT
33
35
from onyx .kg .utils .extraction_utils import get_entity_types_str
34
36
from onyx .kg .utils .extraction_utils import get_relationship_types_str
35
37
from onyx .prompts .dr_prompts import DEFAULLT_DECISION_PROMPT
@@ -170,11 +172,39 @@ def orchestrator(
170
172
reasoning_result = "(No reasoning result provided yet.)"
171
173
tool_calls_string = "(No tool calls provided yet.)"
172
174
173
- if research_type == ResearchType .THOUGHTFUL :
175
+ if research_type not in ResearchType :
176
+ raise ValueError (f"Invalid research type: { research_type } " )
177
+
178
+ if research_type in [ResearchType .THOUGHTFUL , ResearchType .FAST ]:
174
179
if iteration_nr == 1 :
175
- remaining_time_budget = DR_TIME_BUDGET_BY_TYPE [ResearchType .THOUGHTFUL ]
180
+ remaining_time_budget = DR_TIME_BUDGET_BY_TYPE [research_type ]
181
+
182
+ elif remaining_time_budget <= 0 :
183
+ return OrchestrationUpdate (
184
+ tools_used = [DRPath .CLOSER .value ],
185
+ current_step_nr = current_step_nr ,
186
+ query_list = [],
187
+ iteration_nr = iteration_nr ,
188
+ log_messages = [
189
+ get_langgraph_node_log_string (
190
+ graph_component = "main" ,
191
+ node_name = "orchestrator" ,
192
+ node_start_time = node_start_time ,
193
+ )
194
+ ],
195
+ plan_of_record = plan_of_record ,
196
+ remaining_time_budget = remaining_time_budget ,
197
+ iteration_instructions = [
198
+ IterationInstructions (
199
+ iteration_nr = iteration_nr ,
200
+ plan = None ,
201
+ reasoning = "Time to wrap up." ,
202
+ purpose = "" ,
203
+ )
204
+ ],
205
+ )
176
206
177
- elif iteration_nr > 1 :
207
+ elif iteration_nr > 1 and remaining_time_budget > 0 :
178
208
# for each iteration past the first one, we need to see whether we
179
209
# have enough information to answer the question.
180
210
# if we do, we can stop the iteration and return the answer.
@@ -200,7 +230,7 @@ def orchestrator(
200
230
reasoning_tokens : list [str ] = ["" ]
201
231
202
232
reasoning_tokens , _ , _ = run_with_timeout (
203
- 80 ,
233
+ TF_DR_TIMEOUT_LONG ,
204
234
lambda : stream_llm_answer (
205
235
llm = graph_config .tooling .primary_llm ,
206
236
prompt = create_question_prompt (
@@ -211,7 +241,7 @@ def orchestrator(
211
241
agent_answer_level = 0 ,
212
242
agent_answer_question_num = 0 ,
213
243
agent_answer_type = "agent_level_answer" ,
214
- timeout_override = 60 ,
244
+ timeout_override = TF_DR_TIMEOUT_LONG ,
215
245
answer_piece = StreamingType .REASONING_DELTA .value ,
216
246
ind = current_step_nr ,
217
247
# max_tokens=None,
@@ -297,7 +327,7 @@ def orchestrator(
297
327
decision_prompt ,
298
328
),
299
329
schema = OrchestratorDecisonsNoPlan ,
300
- timeout_override = 35 ,
330
+ timeout_override = TF_DR_TIMEOUT_SHORT ,
301
331
# max_tokens=2500,
302
332
)
303
333
next_step = orchestrator_action .next_step
@@ -320,7 +350,7 @@ def orchestrator(
320
350
reasoning_result = "Time to wrap up."
321
351
next_tool_name = DRPath .CLOSER .value
322
352
323
- else :
353
+ elif research_type == ResearchType . DEEP :
324
354
if iteration_nr == 1 and not plan_of_record :
325
355
# by default, we start a new iteration, but if there is a feedback request,
326
356
# we start a new iteration 0 again (set a bit later)
@@ -348,7 +378,7 @@ def orchestrator(
348
378
plan_generation_prompt ,
349
379
),
350
380
schema = OrchestrationPlan ,
351
- timeout_override = 25 ,
381
+ timeout_override = TF_DR_TIMEOUT_SHORT ,
352
382
# max_tokens=3000,
353
383
)
354
384
except Exception as e :
@@ -368,7 +398,7 @@ def orchestrator(
368
398
)
369
399
370
400
_ , _ , _ = run_with_timeout (
371
- 80 ,
401
+ TF_DR_TIMEOUT_LONG ,
372
402
lambda : stream_llm_answer (
373
403
llm = graph_config .tooling .primary_llm ,
374
404
prompt = repeat_plan_prompt ,
@@ -377,7 +407,7 @@ def orchestrator(
377
407
agent_answer_level = 0 ,
378
408
agent_answer_question_num = 0 ,
379
409
agent_answer_type = "agent_level_answer" ,
380
- timeout_override = 60 ,
410
+ timeout_override = TF_DR_TIMEOUT_LONG ,
381
411
answer_piece = StreamingType .REASONING_DELTA .value ,
382
412
ind = current_step_nr ,
383
413
),
@@ -426,7 +456,7 @@ def orchestrator(
426
456
decision_prompt ,
427
457
),
428
458
schema = OrchestratorDecisonsNoPlan ,
429
- timeout_override = 15 ,
459
+ timeout_override = TF_DR_TIMEOUT_LONG ,
430
460
# max_tokens=1500,
431
461
)
432
462
next_step = orchestrator_action .next_step
@@ -460,7 +490,7 @@ def orchestrator(
460
490
)
461
491
462
492
_ , _ , _ = run_with_timeout (
463
- 80 ,
493
+ TF_DR_TIMEOUT_LONG ,
464
494
lambda : stream_llm_answer (
465
495
llm = graph_config .tooling .primary_llm ,
466
496
prompt = repeat_reasoning_prompt ,
@@ -469,7 +499,7 @@ def orchestrator(
469
499
agent_answer_level = 0 ,
470
500
agent_answer_question_num = 0 ,
471
501
agent_answer_type = "agent_level_answer" ,
472
- timeout_override = 60 ,
502
+ timeout_override = TF_DR_TIMEOUT_LONG ,
473
503
answer_piece = StreamingType .REASONING_DELTA .value ,
474
504
ind = current_step_nr ,
475
505
# max_tokens=None,
@@ -484,6 +514,9 @@ def orchestrator(
484
514
485
515
current_step_nr += 1
486
516
517
+ else :
518
+ raise NotImplementedError (f"Research type { research_type } is not implemented." )
519
+
487
520
base_next_step_purpose_prompt = get_dr_prompt_orchestration_templates (
488
521
DRPromptPurpose .NEXT_STEP_PURPOSE ,
489
522
ResearchType .DEEP ,
@@ -498,48 +531,54 @@ def orchestrator(
498
531
)
499
532
500
533
purpose_tokens : list [str ] = ["" ]
534
+ purpose = ""
501
535
502
- try :
536
+ if research_type in [ ResearchType . THOUGHTFUL , ResearchType . DEEP ] :
503
537
504
- write_custom_event (
505
- current_step_nr ,
506
- ReasoningStart (),
507
- writer ,
508
- )
538
+ try :
509
539
510
- purpose_tokens , _ , _ = run_with_timeout (
511
- 80 ,
512
- lambda : stream_llm_answer (
513
- llm = graph_config .tooling .primary_llm ,
514
- prompt = create_question_prompt (
515
- decision_system_prompt ,
516
- orchestration_next_step_purpose_prompt ,
540
+ write_custom_event (
541
+ current_step_nr ,
542
+ ReasoningStart (),
543
+ writer ,
544
+ )
545
+
546
+ purpose_tokens , _ , _ = run_with_timeout (
547
+ TF_DR_TIMEOUT_LONG ,
548
+ lambda : stream_llm_answer (
549
+ llm = graph_config .tooling .primary_llm ,
550
+ prompt = create_question_prompt (
551
+ decision_system_prompt ,
552
+ orchestration_next_step_purpose_prompt ,
553
+ ),
554
+ event_name = "basic_response" ,
555
+ writer = writer ,
556
+ agent_answer_level = 0 ,
557
+ agent_answer_question_num = 0 ,
558
+ agent_answer_type = "agent_level_answer" ,
559
+ timeout_override = TF_DR_TIMEOUT_LONG ,
560
+ answer_piece = StreamingType .REASONING_DELTA .value ,
561
+ ind = current_step_nr ,
562
+ # max_tokens=None,
517
563
),
518
- event_name = "basic_response" ,
519
- writer = writer ,
520
- agent_answer_level = 0 ,
521
- agent_answer_question_num = 0 ,
522
- agent_answer_type = "agent_level_answer" ,
523
- timeout_override = 60 ,
524
- answer_piece = StreamingType .REASONING_DELTA .value ,
525
- ind = current_step_nr ,
526
- # max_tokens=None,
527
- ),
528
- )
564
+ )
529
565
530
- write_custom_event (
531
- current_step_nr ,
532
- SectionEnd (),
533
- writer ,
534
- )
566
+ write_custom_event (
567
+ current_step_nr ,
568
+ SectionEnd (),
569
+ writer ,
570
+ )
535
571
536
- current_step_nr += 1
572
+ current_step_nr += 1
573
+
574
+ except Exception as e :
575
+ logger .error ("Error in orchestration next step purpose." )
576
+ raise e
537
577
538
- except Exception as e :
539
- logger .error (f"Error in orchestration next step purpose: { e } " )
540
- raise e
578
+ purpose = cast (str , merge_content (* purpose_tokens ))
541
579
542
- purpose = cast (str , merge_content (* purpose_tokens ))
580
+ elif research_type == ResearchType .FAST :
581
+ purpose = f"Answering the question using the { next_tool_name } "
543
582
544
583
if not next_tool_name :
545
584
raise ValueError ("The next step has not been defined. This should not happen." )
0 commit comments