From 0a6d87067dc228349107d6b42550cf50da92350d Mon Sep 17 00:00:00 2001 From: Debanjum Date: Mon, 11 Aug 2025 22:04:43 -0700 Subject: [PATCH] Fix to have researcher let the coder tool write code Previously the researcher was passing the whole code to execute in its queries to the tool AI instead of asking it to write the code and limiting its query to a natural language request (with required data). The division of responsibility should help researcher just worry about constructing a request with all the required details instead of also worrying about writing correct code. --- src/khoj/processor/conversation/utils.py | 2 +- src/khoj/routers/research.py | 8 +++++--- src/khoj/utils/helpers.py | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index 63cf2bf5..82a0baab 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -331,7 +331,7 @@ def construct_tool_chat_history( ConversationCommand.ReadWebpage: ( lambda iteration: list(iteration.onlineContext.keys()) if iteration.onlineContext else [] ), - ConversationCommand.RunCode: ( + ConversationCommand.PythonCoder: ( lambda iteration: list(iteration.codeContext.keys()) if iteration.codeContext else [] ), } diff --git a/src/khoj/routers/research.py b/src/khoj/routers/research.py index fc36f9d0..dbb1da75 100644 --- a/src/khoj/routers/research.py +++ b/src/khoj/routers/research.py @@ -100,7 +100,7 @@ async def apick_next_tool( ConversationCommand.Notes.value: [tool.value for tool in document_research_tools], ConversationCommand.Webpage.value: [ConversationCommand.ReadWebpage.value], ConversationCommand.Online.value: [ConversationCommand.SearchWeb.value], - ConversationCommand.Code.value: [ConversationCommand.RunCode.value], + ConversationCommand.Code.value: [ConversationCommand.PythonCoder.value], ConversationCommand.Operator.value: [ConversationCommand.OperateComputer.value], } for input_tool, research_tools in input_tools_to_research_tools.items(): @@ -412,11 +412,13 @@ async def research( this_iteration.warning = f"Error reading webpages: {e}" logger.error(this_iteration.warning, exc_info=True) - elif this_iteration.query.name == ConversationCommand.RunCode: + elif this_iteration.query.name == ConversationCommand.PythonCoder: try: async for result in run_code( **this_iteration.query.args, - conversation_history=construct_tool_chat_history(previous_iterations, ConversationCommand.RunCode), + conversation_history=construct_tool_chat_history( + previous_iterations, ConversationCommand.PythonCoder + ), context="", location_data=location, user=user, diff --git a/src/khoj/utils/helpers.py b/src/khoj/utils/helpers.py index a9f0c7f6..339dbb67 100644 --- a/src/khoj/utils/helpers.py +++ b/src/khoj/utils/helpers.py @@ -427,7 +427,7 @@ class ConversationCommand(str, Enum): SemanticSearchFiles = "semantic_search_files" SearchWeb = "search_web" ReadWebpage = "read_webpage" - RunCode = "run_code" + PythonCoder = "run_code" OperateComputer = "operate_computer" @@ -503,15 +503,15 @@ tools_for_research_llm = { "required": ["urls", "query"], }, ), - ConversationCommand.RunCode: ToolDefinition( - name="run_code", - description=e2b_tool_description if is_e2b_code_sandbox_enabled() else terrarium_tool_description, + ConversationCommand.PythonCoder: ToolDefinition( + name="python_coder", + description="Ask them " + e2b_tool_description if is_e2b_code_sandbox_enabled() else terrarium_tool_description, schema={ "type": "object", "properties": { "query": { "type": "string", - "description": "Detailed query and all input data required to generate, execute code in the sandbox.", + "description": "Detailed query and all input data required for the Python Coder to generate, execute code in the sandbox.", }, }, "required": ["query"],