Skip to content
Open
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
14 changes: 13 additions & 1 deletion src/open_deep_research/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,19 @@ class Configuration(BaseModel):
}
}
)

custom_tools: Optional[List[Any]] = Field(
default=None
)
custom_tools_prompt: Optional[str] = Field(
default=None,
optional=True,
metadata={
"x_oap_ui_config": {
"type": "text",
"description": "Any additional instructions to pass along to the Agent regarding the custom tools that are available to it."
}
}
)

@classmethod
def from_runnable_config(
Expand Down
1 change: 1 addition & 0 deletions src/open_deep_research/deep_researcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ async def researcher(state: ResearcherState, config: RunnableConfig) -> Command[

# Prepare system prompt with MCP context if available
researcher_prompt = research_system_prompt.format(
custom_tools_prompt=configurable.custom_tools_prompt or "",
mcp_prompt=configurable.mcp_prompt or "",
date=get_today_str()
)
Expand Down
1 change: 1 addition & 0 deletions src/open_deep_research/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
You have access to two main tools:
1. **tavily_search**: For conducting web searches to gather information
2. **think_tool**: For reflection and strategic planning during research
{custom_tools_prompt}
{mcp_prompt}

**CRITICAL: Use think_tool after each search to reflect on results and plan next steps. Do not call think_tool with the tavily_search or any other tools. It should be to reflect on the results of the search.**
Expand Down
37 changes: 37 additions & 0 deletions src/open_deep_research/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,38 @@ def _find_mcp_error_in_exception_chain(exc: BaseException) -> McpError | None:
tool.coroutine = authentication_wrapper
return tool

def load_custom_tools(config: RunnableConfig, existing_tool_names: set[str]) -> List[BaseTool]:
"""Load custom Python functions as tools"""
configurable = Configuration.from_runnable_config(config)
if not configurable.custom_tools:
return []

tools = []
for tool_func in configurable.custom_tools:
# Check if tool already exists
tool_name = getattr(tool_func, 'name', str(tool_func))
if tool_name in existing_tool_names:
warnings.warn(f"Tool {tool_name} already exists, skipping")
continue

# Ensure it's a proper LangChain tool
if isinstance(tool_func, BaseTool):
tools.append(tool_func)
elif callable(tool_func):
# If it's a callable but not a BaseTool, wrap it
try:
# If it's already decorated with @tool, it should be a BaseTool
if hasattr(tool_func, 'name') and hasattr(tool_func, 'description'):
tools.append(tool_func)
else:
warnings.warn(f"Tool {tool_name} is not properly decorated with @tool decorator, skipping")
except Exception as e:
warnings.warn(f"Error processing custom tool {tool_name}: {e}")
else:
warnings.warn(f"Invalid tool type for {tool_name}, must be callable or BaseTool")

return tools

async def load_mcp_tools(
config: RunnableConfig,
existing_tool_names: set[str],
Expand Down Expand Up @@ -590,6 +622,11 @@ async def get_all_tools(config: RunnableConfig):
for tool in tools
}

# Add custom tools
custom_tools = load_custom_tools(config, existing_tool_names)
tools.extend(custom_tools)
existing_tool_names.update({tool.name for tool in custom_tools if hasattr(tool, "name")})

# Add MCP tools if configured
mcp_tools = await load_mcp_tools(config, existing_tool_names)
tools.extend(mcp_tools)
Expand Down