Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions apex/services/deep_research/deep_research_langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@


class DeepResearchLangchain(DeepResearchBase):
_FINAL_ANSWER_INST = (
"You are a senior interdisciplinary researcher with expertise across "
"science, technology, humanities, and social sciences.\n"
"Provide report only in plain text using natural language.\n"
"Write your response in the form of a well-structured research report with sections:\n"
"Executive Summary, Key Findings, Evidence, Limitations, Conclusion.\n"
"Use inline numeric citations like [1], [2] that refer to Sources.\n"
"At the end, include a 'Sources' section listing the numbered citations.\n\n"
)

def __init__(
self,
key: str,
Expand Down Expand Up @@ -142,6 +152,7 @@ async def invoke(
reasoning_traces: list[dict[str, Any]] = []

question = messages[-1]["content"]
question = self._FINAL_ANSWER_INST + question

# Seed notes with any provided documents
notes: list[str] = []
Expand Down Expand Up @@ -297,14 +308,7 @@ async def invoke(
final_prompt = PromptTemplate(
input_variables=["question", "notes", "sources"],
template=(
"You are a senior interdisciplinary researcher with expertise across "
"science, technology, humanities, and social sciences.\n"
"Provide report only in plain text using natural language.\n"
"Write your response in the form of a well-structured research report with sections:\n"
"Executive Summary, Key Findings, Evidence, Limitations, Conclusion.\n"
"Use inline numeric citations like [1], [2] that refer to Sources.\n"
"At the end, include a 'Sources' section listing the numbered citations.\n\n"
"Do NOT use JSON, or any other structured data format.\n"
self._FINAL_ANSWER_INST + "Do NOT use JSON, or any other structured data format.\n"
"Question:\n{question}\n\n"
"Notes:\n{notes}\n\n"
"Sources:\n{sources}\n\n"
Expand Down
6 changes: 1 addition & 5 deletions apex/validator/generate_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ async def generate_reference(
}
user_message: dict[str, str] = {
"role": "user",
"content": (
f"Research Question: {query}\n\n"
"Please think through the answer carefully, annotate each step with citations like [1], [2], etc., "
'and conclude with a "Sources:" list mapping each [n] to its source URL or title.'
),
"content": query,
}

response, tool_history, reasoning_traces = await llm.invoke([system_message, user_message])
Expand Down