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.
This commit is contained in:
Debanjum
2025-08-11 22:04:43 -07:00
parent 0186403891
commit 0a6d87067d
3 changed files with 11 additions and 9 deletions

View File

@@ -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 []
),
}

View File

@@ -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,

View File

@@ -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"],