You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: templates/components/agents/python/deep_research/app/workflows/agents.py
+33-8
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,10 @@ class AnalysisDecision(BaseModel):
16
16
description="Whether to continue research, write a report, or cancel the research after several retries"
17
17
)
18
18
research_questions: Optional[List[str]] =Field(
19
-
description="Questions to research if continuing research. Maximum 3 questions. Set to null or empty if writing a report.",
19
+
description="""
20
+
If the decision is to research, provide a list of questions to research that related to the user request.
21
+
Maximum 3 questions. Set to null or empty if writing a report or cancel the research.
22
+
""",
20
23
default_factory=list,
21
24
)
22
25
cancel_reason: Optional[str] =Field(
@@ -29,32 +32,53 @@ async def plan_research(
29
32
memory: SimpleComposableMemory,
30
33
context_nodes: List[Node],
31
34
user_request: str,
35
+
total_questions: int,
32
36
) ->AnalysisDecision:
33
-
analyze_prompt=PromptTemplate(
34
-
"""
37
+
analyze_prompt="""
35
38
You are a professor who is guiding a researcher to research a specific request/problem.
36
39
Your task is to decide on a research plan for the researcher.
40
+
37
41
The possible actions are:
38
42
+ Provide a list of questions for the researcher to investigate, with the purpose of clarifying the request.
39
43
+ Write a report if the researcher has already gathered enough research on the topic and can resolve the initial request.
40
44
+ Cancel the research if most of the answers from researchers indicate there is insufficient information to research the request. Do not attempt more than 3 research iterations or too many questions.
45
+
41
46
The workflow should be:
42
47
+ Always begin by providing some initial questions for the researcher to investigate.
43
48
+ Analyze the provided answers against the initial topic/request. If the answers are insufficient to resolve the initial request, provide additional questions for the researcher to investigate.
44
49
+ If the answers are sufficient to resolve the initial request, instruct the researcher to write a report.
45
-
<User request>
46
-
{user_request}
47
-
</User request>
48
50
51
+
Here are the context:
49
52
<Collected information>
50
53
{context_str}
51
54
</Collected information>
52
55
53
56
<Conversation context>
54
57
{conversation_context}
55
58
</Conversation context>
59
+
60
+
{enhanced_prompt}
61
+
62
+
Now, provide your decision in the required format for this user request:
63
+
<User request>
64
+
{user_request}
65
+
</User request>
56
66
"""
57
-
)
67
+
# Manually craft the prompt to avoid LLM hallucination
68
+
enhanced_prompt=""
69
+
iftotal_questions==0:
70
+
# Avoid writing a report without any research context
71
+
enhanced_prompt="""
72
+
73
+
The student has no questions to research. Let start by asking some questions.
74
+
"""
75
+
eliftotal_questions>6:
76
+
# Avoid asking too many questions (when the data is not ready for writing a report)
77
+
enhanced_prompt=f"""
78
+
79
+
The student has researched {total_questions} questions. Should cancel the research if the context is not enough to write a report.
0 commit comments