research.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. import logging
  2. import os
  3. import subprocess
  4. import sys
  5. import tempfile
  6. from copy import copy
  7. from typing import Any, Callable, Optional
  8. from core.base import AppConfig
  9. from core.base.abstractions import GenerationConfig, Message, SearchSettings
  10. from core.base.providers import DatabaseProvider
  11. from core.providers import (
  12. AnthropicCompletionProvider,
  13. LiteLLMCompletionProvider,
  14. OpenAICompletionProvider,
  15. R2RCompletionProvider,
  16. )
  17. from core.utils import extract_citations
  18. from shared.abstractions.tool import Tool
  19. from ..base.agent.agent import RAGAgentConfig # type: ignore
  20. # Import the RAG agents we'll leverage
  21. from .rag import ( # type: ignore
  22. R2RRAGAgent,
  23. R2RStreamingRAGAgent,
  24. R2RXMLToolsRAGAgent,
  25. R2RXMLToolsStreamingRAGAgent,
  26. RAGAgentMixin,
  27. )
  28. logger = logging.getLogger(__name__)
  29. class ResearchAgentMixin(RAGAgentMixin):
  30. """
  31. A mixin that extends RAGAgentMixin to add research capabilities to any R2R agent.
  32. This mixin provides all RAG capabilities plus additional research tools:
  33. - A RAG tool for knowledge retrieval (which leverages the underlying RAG capabilities)
  34. - A Python execution tool for code execution and computation
  35. - A reasoning tool for complex problem solving
  36. - A critique tool for analyzing conversation history
  37. """
  38. def __init__(
  39. self,
  40. *args,
  41. app_config: AppConfig,
  42. search_settings: SearchSettings,
  43. knowledge_search_method: Callable,
  44. content_method: Callable,
  45. file_search_method: Callable,
  46. max_tool_context_length=10_000,
  47. **kwargs,
  48. ):
  49. # Store the app configuration needed for research tools
  50. self.app_config = app_config
  51. # Call the parent RAGAgentMixin's __init__ with explicitly passed parameters
  52. super().__init__(
  53. *args,
  54. search_settings=search_settings,
  55. knowledge_search_method=knowledge_search_method,
  56. content_method=content_method,
  57. file_search_method=file_search_method,
  58. max_tool_context_length=max_tool_context_length,
  59. **kwargs,
  60. )
  61. # Register our research-specific tools
  62. self._register_research_tools()
  63. def _register_research_tools(self):
  64. """
  65. Register research-specific tools to the agent.
  66. This is called by the mixin's __init__ after the parent class initialization.
  67. """
  68. # Add our research tools to whatever tools are already registered
  69. research_tools = []
  70. for tool_name in set(self.config.research_tools):
  71. if tool_name == "rag":
  72. research_tools.append(self.rag_tool())
  73. elif tool_name == "reasoning":
  74. research_tools.append(self.reasoning_tool())
  75. elif tool_name == "critique":
  76. research_tools.append(self.critique_tool())
  77. elif tool_name == "python_executor":
  78. research_tools.append(self.python_execution_tool())
  79. else:
  80. logger.warning(f"Unknown research tool: {tool_name}")
  81. raise ValueError(f"Unknown research tool: {tool_name}")
  82. logger.debug(f"Registered research tools: {research_tools}")
  83. self.tools = research_tools
  84. def rag_tool(self) -> Tool:
  85. """Tool that provides access to the RAG agent's search capabilities."""
  86. return Tool(
  87. name="rag",
  88. description=(
  89. "Search for information using RAG (Retrieval-Augmented Generation). "
  90. "This tool searches across relevant sources and returns comprehensive information. "
  91. "Use this tool when you need to find specific information on any topic. Be sure to pose your query as a comprehensive query."
  92. ),
  93. results_function=self._rag,
  94. llm_format_function=self._format_search_results,
  95. parameters={
  96. "type": "object",
  97. "properties": {
  98. "query": {
  99. "type": "string",
  100. "description": "The search query to find information.",
  101. }
  102. },
  103. "required": ["query"],
  104. },
  105. context=self,
  106. )
  107. def reasoning_tool(self) -> Tool:
  108. """Tool that provides access to a strong reasoning model."""
  109. return Tool(
  110. name="reasoning",
  111. description=(
  112. "A dedicated reasoning system that excels at solving complex problems through step-by-step analysis. "
  113. "This tool connects to a separate AI system optimized for deep analytical thinking.\n\n"
  114. "USAGE GUIDELINES:\n"
  115. "1. Formulate your request as a complete, standalone question to a reasoning expert.\n"
  116. "2. Clearly state the problem/question at the beginning.\n"
  117. "3. Provide all relevant context, data, and constraints.\n\n"
  118. "IMPORTANT: This system has no memory of previous interactions or context from your conversation.\n\n"
  119. "STRENGTHS: Mathematical reasoning, logical analysis, evaluating complex scenarios, "
  120. "solving multi-step problems, and identifying potential errors in reasoning."
  121. ),
  122. results_function=self._reason,
  123. llm_format_function=self._format_search_results,
  124. parameters={
  125. "type": "object",
  126. "properties": {
  127. "query": {
  128. "type": "string",
  129. "description": "A complete, standalone question with all necessary context, appropriate for a dedicated reasoning system.",
  130. }
  131. },
  132. "required": ["query"],
  133. },
  134. )
  135. def critique_tool(self) -> Tool:
  136. """Tool that provides critical analysis of the reasoning done so far in the conversation."""
  137. return Tool(
  138. name="critique",
  139. description=(
  140. "Analyzes the conversation history to identify potential flaws, biases, and alternative "
  141. "approaches to the reasoning presented so far.\n\n"
  142. "Use this tool to get a second opinion on your reasoning, find overlooked considerations, "
  143. "identify biases or fallacies, explore alternative hypotheses, and improve the robustness "
  144. "of your conclusions."
  145. ),
  146. results_function=self._critique,
  147. llm_format_function=self._format_search_results,
  148. parameters={
  149. "type": "object",
  150. "properties": {
  151. "query": {
  152. "type": "string",
  153. "description": "A specific aspect of the reasoning you want critiqued, or leave empty for a general critique.",
  154. },
  155. "focus_areas": {
  156. "type": "array",
  157. "items": {"type": "string"},
  158. "description": "Optional specific areas to focus the critique (e.g., ['logical fallacies', 'methodology'])",
  159. },
  160. },
  161. "required": ["query"],
  162. },
  163. )
  164. def python_execution_tool(self) -> Tool:
  165. """Tool that provides Python code execution capabilities."""
  166. return Tool(
  167. name="python_executor",
  168. description=(
  169. "Executes Python code and returns the results, output, and any errors. "
  170. "Use this tool for complex calculations, statistical operations, or algorithmic implementations.\n\n"
  171. "The execution environment includes common libraries such as numpy, pandas, sympy, scipy, statsmodels, biopython, etc.\n\n"
  172. "USAGE:\n"
  173. "1. Send complete, executable Python code as a string.\n"
  174. "2. Use print statements for output you want to see.\n"
  175. "3. Assign to the 'result' variable for values you want to return.\n"
  176. "4. Do not use input() or plotting (matplotlib). Output is text-based."
  177. ),
  178. results_function=self._execute_python_with_process_timeout,
  179. llm_format_function=self._format_python_results,
  180. parameters={
  181. "type": "object",
  182. "properties": {
  183. "code": {
  184. "type": "string",
  185. "description": "Python code to execute.",
  186. }
  187. },
  188. "required": ["code"],
  189. },
  190. )
  191. async def _rag(
  192. self,
  193. query: str,
  194. *args,
  195. **kwargs,
  196. ) -> dict[str, Any]:
  197. """Execute a search using an internal RAG agent."""
  198. # Create a copy of the current configuration for the RAG agent
  199. config_copy = copy(self.config)
  200. config_copy.max_iterations = 10 # Could be configurable
  201. # Always include critical web search tools
  202. default_tools = ["web_search", "web_scrape"]
  203. # Get the configured RAG tools from the original config
  204. configured_tools = set(self.config.rag_tools or default_tools)
  205. # Combine default tools with all configured tools, ensuring no duplicates
  206. config_copy.rag_tools = list(
  207. set(default_tools + list(configured_tools))
  208. )
  209. logger.debug(f"Using RAG tools: {config_copy.rag_tools}")
  210. # Create a generation config for the RAG agent
  211. generation_config = GenerationConfig(
  212. model=self.app_config.quality_llm,
  213. max_tokens_to_sample=16000,
  214. )
  215. # Create a new RAG agent - we'll use the non-streaming variant for consistent results
  216. rag_agent = R2RRAGAgent(
  217. database_provider=self.database_provider,
  218. llm_provider=self.llm_provider,
  219. config=config_copy,
  220. search_settings=self.search_settings,
  221. rag_generation_config=generation_config,
  222. knowledge_search_method=self.knowledge_search_method,
  223. content_method=self.content_method,
  224. file_search_method=self.file_search_method,
  225. max_tool_context_length=self.max_tool_context_length,
  226. )
  227. # Run the RAG agent with the query
  228. user_message = Message(role="user", content=query)
  229. response = await rag_agent.arun(messages=[user_message])
  230. # Get the content from the response
  231. structured_content = response[-1].get("structured_content")
  232. if structured_content:
  233. possible_text = structured_content[-1].get("text")
  234. content = response[-1].get("content") or possible_text
  235. else:
  236. content = response[-1].get("content")
  237. # Extract citations and transfer search results from RAG agent to research agent
  238. short_ids = extract_citations(content)
  239. if short_ids:
  240. logger.info(f"Found citations in RAG response: {short_ids}")
  241. for short_id in short_ids:
  242. result = rag_agent.search_results_collector.find_by_short_id(
  243. short_id
  244. )
  245. if result:
  246. self.search_results_collector.add_result(result)
  247. # Log confirmation for successful transfer
  248. logger.info(
  249. "Transferred search results from RAG agent to research agent for citations"
  250. )
  251. return content
  252. async def _reason(
  253. self,
  254. query: str,
  255. *args,
  256. **kwargs,
  257. ) -> dict[str, Any]:
  258. """Execute a reasoning query using a specialized reasoning LLM."""
  259. msg_list = await self.conversation.get_messages()
  260. # Create a specialized generation config for reasoning
  261. gen_cfg = self.get_generation_config(msg_list[-1], stream=False)
  262. gen_cfg.model = self.app_config.reasoning_llm
  263. gen_cfg.top_p = None
  264. gen_cfg.temperature = 0.1
  265. gen_cfg.max_tokens_to_sample = 64000
  266. gen_cfg.stream = False
  267. gen_cfg.tools = None
  268. gen_cfg.functions = None
  269. gen_cfg.reasoning_effort = "high"
  270. gen_cfg.add_generation_kwargs = None
  271. # Call the LLM with the reasoning request
  272. response = await self.llm_provider.aget_completion(
  273. [{"role": "user", "content": query}], gen_cfg
  274. )
  275. return response.choices[0].message.content
  276. async def _critique(
  277. self,
  278. query: str,
  279. focus_areas: Optional[list] = None,
  280. *args,
  281. **kwargs,
  282. ) -> dict[str, Any]:
  283. """Critique the conversation history."""
  284. msg_list = await self.conversation.get_messages()
  285. if not focus_areas:
  286. focus_areas = []
  287. # Build the critique prompt
  288. critique_prompt = (
  289. "You are a critical reasoning expert. Your task is to analyze the following conversation "
  290. "and critique the reasoning. Look for:\n"
  291. "1. Logical fallacies or inconsistencies\n"
  292. "2. Cognitive biases\n"
  293. "3. Overlooked questions or considerations\n"
  294. "4. Alternative approaches\n"
  295. "5. Improvements in rigor\n\n"
  296. )
  297. if focus_areas:
  298. critique_prompt += f"Focus areas: {', '.join(focus_areas)}\n\n"
  299. if query.strip():
  300. critique_prompt += f"Specific question: {query}\n\n"
  301. critique_prompt += (
  302. "Structure your critique:\n"
  303. "1. Summary\n"
  304. "2. Key strengths\n"
  305. "3. Potential issues\n"
  306. "4. Alternatives\n"
  307. "5. Recommendations\n\n"
  308. )
  309. # Add the conversation history to the prompt
  310. conversation_text = "\n--- CONVERSATION HISTORY ---\n\n"
  311. for msg in msg_list:
  312. role = msg.get("role", "")
  313. content = msg.get("content", "")
  314. if content and role in ["user", "assistant", "system"]:
  315. conversation_text += f"{role.upper()}: {content}\n\n"
  316. final_prompt = critique_prompt + conversation_text
  317. # Use the reasoning tool to process the critique
  318. return await self._reason(final_prompt, *args, **kwargs)
  319. async def _execute_python_with_process_timeout(
  320. self, code: str, timeout: int = 10, *args, **kwargs
  321. ) -> dict[str, Any]:
  322. """
  323. Executes Python code in a separate subprocess with a timeout.
  324. This provides isolation and prevents re-importing the current agent module.
  325. Parameters:
  326. code (str): Python code to execute.
  327. timeout (int): Timeout in seconds (default: 10).
  328. Returns:
  329. dict[str, Any]: Dictionary containing stdout, stderr, return code, etc.
  330. """
  331. # Write user code to a temporary file
  332. with tempfile.NamedTemporaryFile(
  333. mode="w", suffix=".py", delete=False
  334. ) as tmp_file:
  335. tmp_file.write(code)
  336. script_path = tmp_file.name
  337. try:
  338. # Run the script in a fresh subprocess
  339. result = subprocess.run(
  340. [sys.executable, script_path],
  341. capture_output=True,
  342. text=True,
  343. timeout=timeout,
  344. )
  345. return {
  346. "result": None, # We'll parse from stdout if needed
  347. "stdout": result.stdout,
  348. "stderr": result.stderr,
  349. "error": (
  350. None
  351. if result.returncode == 0
  352. else {
  353. "type": "SubprocessError",
  354. "message": f"Process exited with code {result.returncode}",
  355. "traceback": "",
  356. }
  357. ),
  358. "locals": {}, # No direct local var capture in a separate process
  359. "success": (result.returncode == 0),
  360. "timed_out": False,
  361. "timeout": timeout,
  362. }
  363. except subprocess.TimeoutExpired as e:
  364. return {
  365. "result": None,
  366. "stdout": e.output or "",
  367. "stderr": e.stderr or "",
  368. "error": {
  369. "type": "TimeoutError",
  370. "message": f"Execution exceeded {timeout} second limit.",
  371. "traceback": "",
  372. },
  373. "locals": {},
  374. "success": False,
  375. "timed_out": True,
  376. "timeout": timeout,
  377. }
  378. finally:
  379. # Clean up the temp file
  380. if os.path.exists(script_path):
  381. os.remove(script_path)
  382. def _format_python_results(self, results: dict[str, Any]) -> str:
  383. """Format Python execution results for display."""
  384. output = []
  385. # Timeout notification
  386. if results.get("timed_out", False):
  387. output.append(
  388. f"⚠️ **Execution Timeout**: Code exceeded the {results.get('timeout', 10)} second limit."
  389. )
  390. output.append("")
  391. # Stdout
  392. if results.get("stdout"):
  393. output.append("## Output:")
  394. output.append("```")
  395. output.append(results["stdout"].rstrip())
  396. output.append("```")
  397. output.append("")
  398. # If there's a 'result' variable to display
  399. if results.get("result") is not None:
  400. output.append("## Result:")
  401. output.append("```")
  402. output.append(str(results["result"]))
  403. output.append("```")
  404. output.append("")
  405. # Error info
  406. if not results.get("success", True):
  407. output.append("## Error:")
  408. output.append("```")
  409. stderr_out = results.get("stderr", "").rstrip()
  410. if stderr_out:
  411. output.append(stderr_out)
  412. err_obj = results.get("error")
  413. if err_obj and err_obj.get("message"):
  414. output.append(err_obj["message"])
  415. output.append("```")
  416. # Return formatted output
  417. return (
  418. "\n".join(output)
  419. if output
  420. else "Code executed with no output or result."
  421. )
  422. def _format_search_results(self, results) -> str:
  423. """Simple pass-through formatting for RAG search results."""
  424. return results
  425. class R2RResearchAgent(ResearchAgentMixin, R2RRAGAgent):
  426. """
  427. A non-streaming research agent that uses the standard R2R agent as its base.
  428. This agent combines research capabilities with the non-streaming RAG agent,
  429. providing tools for deep research through tool-based interaction.
  430. """
  431. def __init__(
  432. self,
  433. app_config: AppConfig,
  434. database_provider: DatabaseProvider,
  435. llm_provider: (
  436. AnthropicCompletionProvider
  437. | LiteLLMCompletionProvider
  438. | OpenAICompletionProvider
  439. | R2RCompletionProvider
  440. ),
  441. config: RAGAgentConfig,
  442. search_settings: SearchSettings,
  443. rag_generation_config: GenerationConfig,
  444. knowledge_search_method: Callable,
  445. content_method: Callable,
  446. file_search_method: Callable,
  447. max_tool_context_length: int = 20_000,
  448. ):
  449. # Set a higher max iterations for research tasks
  450. config.max_iterations = config.max_iterations or 15
  451. # Initialize the RAG agent first
  452. R2RRAGAgent.__init__(
  453. self,
  454. database_provider=database_provider,
  455. llm_provider=llm_provider,
  456. config=config,
  457. search_settings=search_settings,
  458. rag_generation_config=rag_generation_config,
  459. knowledge_search_method=knowledge_search_method,
  460. content_method=content_method,
  461. file_search_method=file_search_method,
  462. max_tool_context_length=max_tool_context_length,
  463. )
  464. # Then initialize the ResearchAgentMixin
  465. ResearchAgentMixin.__init__(
  466. self,
  467. app_config=app_config,
  468. database_provider=database_provider,
  469. llm_provider=llm_provider,
  470. config=config,
  471. search_settings=search_settings,
  472. rag_generation_config=rag_generation_config,
  473. max_tool_context_length=max_tool_context_length,
  474. knowledge_search_method=knowledge_search_method,
  475. file_search_method=file_search_method,
  476. content_method=content_method,
  477. )
  478. class R2RStreamingResearchAgent(ResearchAgentMixin, R2RStreamingRAGAgent):
  479. """
  480. A streaming research agent that uses the streaming RAG agent as its base.
  481. This agent combines research capabilities with streaming text generation,
  482. providing real-time responses while still offering research tools.
  483. """
  484. def __init__(
  485. self,
  486. app_config: AppConfig,
  487. database_provider: DatabaseProvider,
  488. llm_provider: (
  489. AnthropicCompletionProvider
  490. | LiteLLMCompletionProvider
  491. | OpenAICompletionProvider
  492. | R2RCompletionProvider
  493. ),
  494. config: RAGAgentConfig,
  495. search_settings: SearchSettings,
  496. rag_generation_config: GenerationConfig,
  497. knowledge_search_method: Callable,
  498. content_method: Callable,
  499. file_search_method: Callable,
  500. max_tool_context_length: int = 10_000,
  501. ):
  502. # Force streaming on
  503. config.stream = True
  504. config.max_iterations = config.max_iterations or 15
  505. # Initialize the streaming RAG agent first
  506. R2RStreamingRAGAgent.__init__(
  507. self,
  508. database_provider=database_provider,
  509. llm_provider=llm_provider,
  510. config=config,
  511. search_settings=search_settings,
  512. rag_generation_config=rag_generation_config,
  513. knowledge_search_method=knowledge_search_method,
  514. content_method=content_method,
  515. file_search_method=file_search_method,
  516. max_tool_context_length=max_tool_context_length,
  517. )
  518. # Then initialize the ResearchAgentMixin
  519. ResearchAgentMixin.__init__(
  520. self,
  521. app_config=app_config,
  522. database_provider=database_provider,
  523. llm_provider=llm_provider,
  524. config=config,
  525. search_settings=search_settings,
  526. rag_generation_config=rag_generation_config,
  527. max_tool_context_length=max_tool_context_length,
  528. knowledge_search_method=knowledge_search_method,
  529. content_method=content_method,
  530. file_search_method=file_search_method,
  531. )
  532. class R2RXMLToolsResearchAgent(ResearchAgentMixin, R2RXMLToolsRAGAgent):
  533. """
  534. A non-streaming research agent that uses XML tool formatting.
  535. This agent combines research capabilities with the XML-based tool calling format,
  536. which might be more appropriate for certain LLM providers.
  537. """
  538. def __init__(
  539. self,
  540. app_config: AppConfig,
  541. database_provider: DatabaseProvider,
  542. llm_provider: (
  543. AnthropicCompletionProvider
  544. | LiteLLMCompletionProvider
  545. | OpenAICompletionProvider
  546. | R2RCompletionProvider
  547. ),
  548. config: RAGAgentConfig,
  549. search_settings: SearchSettings,
  550. rag_generation_config: GenerationConfig,
  551. knowledge_search_method: Callable,
  552. content_method: Callable,
  553. file_search_method: Callable,
  554. max_tool_context_length: int = 20_000,
  555. ):
  556. # Set higher max iterations
  557. config.max_iterations = config.max_iterations or 15
  558. # Initialize the XML Tools RAG agent first
  559. R2RXMLToolsRAGAgent.__init__(
  560. self,
  561. database_provider=database_provider,
  562. llm_provider=llm_provider,
  563. config=config,
  564. search_settings=search_settings,
  565. rag_generation_config=rag_generation_config,
  566. knowledge_search_method=knowledge_search_method,
  567. content_method=content_method,
  568. file_search_method=file_search_method,
  569. max_tool_context_length=max_tool_context_length,
  570. )
  571. # Then initialize the ResearchAgentMixin
  572. ResearchAgentMixin.__init__(
  573. self,
  574. app_config=app_config,
  575. search_settings=search_settings,
  576. knowledge_search_method=knowledge_search_method,
  577. content_method=content_method,
  578. file_search_method=file_search_method,
  579. max_tool_context_length=max_tool_context_length,
  580. )
  581. class R2RXMLToolsStreamingResearchAgent(
  582. ResearchAgentMixin, R2RXMLToolsStreamingRAGAgent
  583. ):
  584. """
  585. A streaming research agent that uses XML tool formatting.
  586. This agent combines research capabilities with streaming and XML-based tool calling,
  587. providing real-time responses in a format suitable for certain LLM providers.
  588. """
  589. def __init__(
  590. self,
  591. app_config: AppConfig,
  592. database_provider: DatabaseProvider,
  593. llm_provider: (
  594. AnthropicCompletionProvider
  595. | LiteLLMCompletionProvider
  596. | OpenAICompletionProvider
  597. | R2RCompletionProvider
  598. ),
  599. config: RAGAgentConfig,
  600. search_settings: SearchSettings,
  601. rag_generation_config: GenerationConfig,
  602. knowledge_search_method: Callable,
  603. content_method: Callable,
  604. file_search_method: Callable,
  605. max_tool_context_length: int = 10_000,
  606. ):
  607. # Force streaming on
  608. config.stream = True
  609. config.max_iterations = config.max_iterations or 15
  610. # Initialize the XML Tools Streaming RAG agent first
  611. R2RXMLToolsStreamingRAGAgent.__init__(
  612. self,
  613. database_provider=database_provider,
  614. llm_provider=llm_provider,
  615. config=config,
  616. search_settings=search_settings,
  617. rag_generation_config=rag_generation_config,
  618. knowledge_search_method=knowledge_search_method,
  619. content_method=content_method,
  620. file_search_method=file_search_method,
  621. max_tool_context_length=max_tool_context_length,
  622. )
  623. # Then initialize the ResearchAgentMixin
  624. ResearchAgentMixin.__init__(
  625. self,
  626. app_config=app_config,
  627. search_settings=search_settings,
  628. knowledge_search_method=knowledge_search_method,
  629. content_method=content_method,
  630. file_search_method=file_search_method,
  631. max_tool_context_length=max_tool_context_length,
  632. )