Skip to navigation

Calling LLMs and agents from custom functions in flows

Enterprise

In flows, Python custom functions can call an LLM through one of two clients on the CLIENTS object:

  • LLM client (CLIENTS.llm_client) — Sends a prompt to the model, with optional file data or a response schema, and returns the response. Your code reads the input files and parses, checks, and writes the response. The LLM client uses agent mode v1 capabilities, using the LLMs available in your environment and the app’s configured AI runtime.

  • Opt-in Agent client (CLIENTS.agent_client) — Lets custom functions in Map UDF and Reduce UDF steps use agent mode v2, which hands tasks to the SuperApp AI agent to answer questions about the step’s input files, extract structured records, and check the results. The agent client attaches the input files, validates extraction results against your schema, and writes them to the step output. You can choose the model and reasoning effort for each call.

Client comparison

The two clients have different methods and availability, and you can’t substitute one for the other.

LLM clientAgent client
AccessCLIENTS.llm_clientCLIENTS.agent_client
Supported stepsPre-flow UDF, Post-flow UDF, Apply classifier, Apply refiner, Map UDF, and Reduce UDFMap UDF and Reduce UDF
While the agent client is available in fewer steps, it can also handle more complex task sequences. Using the agent client can simplify your flow pattern, for example, using a reduce custom function with the agent client for both extraction and validation.
AvailabilityOrganizations with advanced view enabledOpt-in for organizations with advanced view enabled.
ModelThe tenant’s configured LLM provider and AI runtime modelsuperagent-pro by default. You can set model and reasoning_effort on each call. See Setting the model, reasoning effort, and timeout.
AI runtime support in advanced appsYes. The LLM client uses the app version’s AI runtime version.No. The agent client doesn’t follow the app’s AI runtime version. Unless you set model, it uses superagent-pro, which chooses a model for each task.
How you call itgenerate_content()Create a session with for_inputs(), then call generate(), extract(), validate(), or a related method.
Input filesYour code reads each file with CLIENTS.ibfile and passes its bytes with file_data and mime_type.The client attaches the step’s input files for you.
Structured outputPass response_schema. The platform doesn’t validate the response, so your code parses and checks it.Extraction results are validated against your schema. An invalid response gets one correction attempt before the call fails.
Step outputYour code builds and returns out_files.Validated extraction results are written to the step output, with page provenance.
Checking resultsNot built inBuilt in. See Checking extracted results.