• Resolved Geleosan

    (@geleosan)


    Hi. Can simpleTextQuery() or mwai_ai_query enable the web search tool for a request, and with which $params or query property?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    Hi @geleosan,

    Yes, both can! 😊 Web search is a built-in tool, and you enable it by adding web_search to the tools of the query.

    With simpleTextQuery, pass it in the params:

    $mwai->simpleTextQuery( $message, [ 'tools' => [ 'web_search' ] ] );

    With the mwai_ai_query filter, set it on the query itself, merged with the existing tools so you keep whatever the chatbot already enabled:

    $query->set_tools( array_merge( $query->tools, [ 'web_search' ] ) );

    It works with OpenAI (native OpenAI environment, through the Responses API), Anthropic, Google and OpenRouter. On an OpenAI-compatible custom environment it is dropped, and AI Engine writes a line in the PHP error log explaining why.

    Have a nice day!

    Thread Starter Geleosan

    (@geleosan)

    Cool! Thank you.

    Can the web_search tool in simpleTextQuery take options like max_uses and allowed_domains (as in Anthropic’s web search tool definition)? Searches are costing me about $1 per run and I’d like to cap them.

    Plugin Author Jordy Meow

    (@tigroumeow)

    Hi again @geleosan,

    Not through simpleTextQuery itself, but I just added a filter for exactly this! 😊 It is called mwai_anthropic_body, it lets you change the request right before it goes to Anthropic, and it will be in the next release (this Thursday). With it, you can tune the web search tool like this:

    add_filter( 'mwai_anthropic_body', function( $body, $query ) {
      foreach ( $body['tools'] ?? [] as $i => $tool ) {
        if ( ( $tool['name'] ?? '' ) === 'web_search' ) {
          $body['tools'][$i]['max_uses'] = 2;
          $body['tools'][$i]['allowed_domains'] = [ 'example.com' ];
        }
      }
      return $body;
    }, 10, 2 );

    AI Engine already caps it at 5 searches by default. The searches themselves are cheap (about one cent each); what makes a run cost $1 is that every page found is read by the model as input tokens. So max_uses is the right lever, and a smaller model like Haiku will divide the bill too.

    Have a nice day!
    Jordy.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.