openai api - File Search tool stops working when I enable custom function calling - Stack Overflow

admin2025-04-30  1

I'm building a chatbot using OpenAI's Assistant (beta) and want to combine:

File Search – so the assistant can retrieve information from my uploaded PDF/manual (stored in a vector store).

Function Calling – to enable custom actions (e.g., sending emails, generating reports, etc.).

When only the file search is enabled (e.g., by attaching a vector store with tool_resources["file_search"]), the assistant successfully retrieves relevant chunks from my PDF and incorporates them into its responses.

However, as soon as I define custom functions (via "type" => "function" in the tools array), the assistant ceases to call the file search tool.
It instead either tries to call a custom function or just responds with general answers, never referencing the PDF content.

Here’s a simplified example of how I’m creating the run:

$tools = [
    // If I include only ["type" => "file_search"] here, file search works perfectly
    ["type" => "file_search"], 
    // ... plus some "function" tools for custom actions ...
];

$threadRun = $client->threads()->runs()->create(
    $threadId,
    [
        'assistant_id' => $assistantKey,
        'tools' => $tools,
    ]
);

  • Without the custom function definitions, the assistant references the PDF just fine (the file search tool is invoked).

  • With the custom functions included, the assistant never seems to use the file search, even though the user queries match content in the PDF.
    I’ve tried forcing tool_choice => 'auto' and a few other approaches, but the assistant still won’t do file search once function calling is available.

Question: Has anyone managed to get both file search and custom function calling working simultaneously in OpenAI’s Assistant API (v2)? How can I configure or prompt the assistant so it can decide whether to do file retrieval or call a function, based on user requests?

Any insight or workarounds would be appreciated! If you’ve succeeded, please share how you set up the tools or if you had to implement your own “search” function instead of the built-in file search.

转载请注明原文地址:http://anycun.com/QandA/1746028451a91553.html