Agent Builder - Working with Lists

A FileSearch node returns a list of results. An agent can’t work with a List and suggests I Transform the list but I can’t find any good examples of how to use Transform. Any good examples of how to do this ?

1 Like

Have you found an answer to this yet? I also need it because I need to grab the string inside my list

Hey @Dlaytonj2,


You’re correct that FileSearch returns a list of result objects, and the agent cannot directly operate on a list. This is exactly what the Transform tool is designed for. According to the OpenAI documentation, Transform lets you take any structured output (arrays, lists, dicts) and reshape it into something the agent can consume — usually a single string or a simplified JSON object.


Here’s a minimal example showing how to transform your FileSearch list:


tools=[

  {"type": "file_search", "file_search": {}},

  {

    "type": "transform",

    "transform": {

      "input_schema": {

        "properties": {

          "results": { "type": "array" }

        },

        "required": ["results"]

      }

    }

  }

]



Then call the Transform tool like this:


transform_output = client.agents.tools.transform.run(

  input={"results": file_search_results},

  instructions="Combine all results[].text fields into one string separated by newlines."

)



The output will be a single aggregated string that your agent can reason over.


You can also use Transform to extract only the top result, restructure the JSON, or merge multiple chunks — the instructions define the transformation. Hope this helps. Thank you!

1 Like