diff --git a/backend/onyx/db/slack_channel_config.py b/backend/onyx/db/slack_channel_config.py index a3b84533e6a..523909f22b9 100644 --- a/backend/onyx/db/slack_channel_config.py +++ b/backend/onyx/db/slack_channel_config.py @@ -15,6 +15,7 @@ from onyx.db.persona import mark_persona_as_deleted from onyx.db.persona import upsert_persona from onyx.db.prompts import get_default_prompt +from onyx.tools.built_in_tools import get_search_tool from onyx.utils.errors import EERequiredError from onyx.utils.variable_functionality import ( fetch_versioned_implementation_with_fallback, @@ -47,6 +48,10 @@ def create_slack_channel_persona( ) -> Persona: """NOTE: does not commit changes""" + search_tool = get_search_tool(db_session) + if search_tool is None: + raise ValueError("Search tool not found") + # create/update persona associated with the Slack channel persona_name = _build_persona_name(channel_name) default_prompt = get_default_prompt(db_session) @@ -60,6 +65,7 @@ def create_slack_channel_persona( llm_filter_extraction=enable_auto_filters, recency_bias=RecencyBiasSetting.AUTO, prompt_ids=[default_prompt.id], + tool_ids=[search_tool.id], document_set_ids=document_set_ids, llm_model_provider_override=None, llm_model_version_override=None, diff --git a/backend/onyx/tools/built_in_tools.py b/backend/onyx/tools/built_in_tools.py index dd67f5b16f7..31adab6c418 100644 --- a/backend/onyx/tools/built_in_tools.py +++ b/backend/onyx/tools/built_in_tools.py @@ -104,13 +104,10 @@ def load_builtin_tools(db_session: Session) -> None: logger.notice("All built-in tools are loaded/verified.") -def auto_add_search_tool_to_personas(db_session: Session) -> None: +def get_search_tool(db_session: Session) -> ToolDBModel | None: """ - Automatically adds the SearchTool to all Persona objects in the database that have - `num_chunks` either unset or set to a value that isn't 0. This is done to migrate - Persona objects that were created before the concept of Tools were added. + Retrieves for the SearchTool from the BUILT_IN_TOOLS list. """ - # Fetch the SearchTool from the database based on in_code_tool_id from BUILT_IN_TOOLS search_tool_id = next( ( tool["in_code_tool_id"] @@ -119,6 +116,7 @@ def auto_add_search_tool_to_personas(db_session: Session) -> None: ), None, ) + if not search_tool_id: raise RuntimeError("SearchTool not found in the BUILT_IN_TOOLS list.") @@ -126,6 +124,18 @@ def auto_add_search_tool_to_personas(db_session: Session) -> None: select(ToolDBModel).where(ToolDBModel.in_code_tool_id == search_tool_id) ).scalar_one_or_none() + return search_tool + + +def auto_add_search_tool_to_personas(db_session: Session) -> None: + """ + Automatically adds the SearchTool to all Persona objects in the database that have + `num_chunks` either unset or set to a value that isn't 0. This is done to migrate + Persona objects that were created before the concept of Tools were added. + """ + # Fetch the SearchTool from the database based on in_code_tool_id from BUILT_IN_TOOLS + search_tool = get_search_tool(db_session) + if not search_tool: raise RuntimeError("SearchTool not found in the database.")