Connecting to other LLMs

An adapter connects Search2o to an LLM. Six are bundled: three for every endpoint that speaks the OpenAI, Anthropic or Gemini protocol, and three for models you host with Ollama, vLLM or SGLang. An LLM with a protocol of its own needs an adapter class, written in Python and named on the Hooks page.

First, try a bundled adapter

A private deployment, a gateway, or a vendor with an OpenAI-compatible API does not need code: create an LLM profile under Profiles › LLM, choose the adapter that matches the protocol (openai, anthropic or gemini), and set the URL, the headers and the model. A model served by Ollama, vLLM or SGLang takes the ollama, vllm or sglang adapter. See LLM vendors.

The UI shows each adapter's description when a profile is created, and the description says which protocol the adapter speaks.

When you need an adapter of your own

An adapter turns the request Search2o builds, with the prompt, tools, model and limits, into the vendor's request body, and turns the vendor's response back into Search2o's form. Write one only when the vendor's protocol matches none of the bundled adapters.

BaseLlmAdapter, for most APIs

search2o.llm.basellmadapter.BaseLlmAdapter does the assembly and the control flow. It builds the request in a fixed order, merges the profile's additionalParams over the result, and reads the response in a fixed order. You supply the vendor-specific pieces, as these methods:

MethodWhat it does
namefrom LlmAdapterThe adapter's name, as it appears in a profile's adapter field.
descriptionfrom LlmAdapterOne line, shown in the UI when a profile is created.
set_modelPut the profile's model into the request parameters.
set_max_tokensPut the token ceiling into the request parameters.
set_toolsExpress the agent's tools in the vendor's schema.
set_system_promptPlace the system prompt where the vendor expects it, in the parameters or as a message.
set_messages_user_entryAppend one user message.
set_messages_assistant_response_content_outputAppend an earlier assistant answer.
set_messages_assistant_response_tool_callsAppend the assistant's earlier tool calls.
set_messages_tool_resultsAppend the results of those tool calls.
set_response_flagsRead success or failure from the response.
set_token_countsRead the token counts, which the cost report is computed from.
set_assistant_vendorRead the answer: either tool calls or content. A response with neither is an error.

BaseLlmAdapter goes through the prompt history and calls the four message methods in the order the exchange happened, so an adapter never sorts the history itself. get_error has a working implementation that reads the response's error field; override it when the vendor reports errors differently.

LlmAdapter, for anything else

search2o.llm.llmadapter.LlmAdapter is the bare interface, for a protocol so different that the assembly above does not help. An adapter that extends it implements all five methods: name, description, process_request (an LlmRequestModel in, the request body out), process_response (the response in, an LlmResponseModel out), and get_error.

The bundled adapters in search2o.llm are the reference implementations, and each is a short file: openaiadapter.py, anthropicadapter.py and geminiadapter.py. ollamaadapter.py, vllmadapter.py and sglangadapter.py extend the OpenAI adapter.

Registering an adapter

  1. Install the class, with a constructor that takes no arguments, in the Python environment of every agent server.
  2. On the Hooks page, under LLM adapters, add a line mypackage.myadapter.MyAdapter and save.
  3. Restart the agent servers. Each builds the class once at startup and then offers the adapter under Adapters when a new LLM profile is created. A class that cannot be imported or built is written to the agent server's log, and that agent server refuses to run agents until the line is fixed.