How to avoid max turn exceed error from openai agent SDK

I wrote an agent to retrieve relevant chunks from a proprietary knowledge base through an API that returns semantic chunks. I created a tool for this agent, where the tool accepts a user query and returns the relevant semantic chunks. In the instructions, I specified that the agent should retrieve the relevant chunks and pass the query as part of the instruction.

However, my agent is going into an infinite loop while trying to retrieve the data and eventually throws a max turn error after some time.”

i gave structured output in output_type

class DataChunk(BaseModel):
id: int
url: str
title: str
content:str
contentType:str
publishedDate:str

class SourceList(BaseModel):
items: List[DataChunk] = Field(
…,
description=“A list of dictionaries, where each dictionary contains information about a source here only relevant chunks for related to provided query.”
)

Are you using an OpenAI AI model’s native function calling feature?

I don’t know where you came up with “output_type”.

You can follow this example for “functions”, of specifying parameters the AI shall emit with a TypedDict object:

Then, are you using gpt-5-mini or nano? Serious problems of looping without return.