Skip to content

Nested objects in function tool input are empty #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
built-by-as opened this issue Apr 21, 2025 · 4 comments
Closed

Nested objects in function tool input are empty #563

built-by-as opened this issue Apr 21, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@built-by-as
Copy link

built-by-as commented Apr 21, 2025

Please read this first

  • Have you read the docs?Agents SDK docs
  • Have you searched for related issues? Others may have faced similar issues.

Describe the bug

Nested arrays/objects of a Pydantic type are not passed to function tool arguments.

I have these classes:

class Exercise(BaseModel):
    ...

class Workout(BaseModel):
    exercises: List[Exercise]

class TrainingProgram(BaseModel):
    workouts: List[Workout]

function tool calls seem to always have the workouts list empty

Debug information

  • Agents SDK version: 0.0.11
  • Python version 3.10.13

Repro steps

I have a function tool defined as so:

@function_tool
async def create_training_program(wrapper: RunContextWrapper[ChatContext], training_program: TrainingProgram)

when one of my agents calls it, the workouts array is empty

create_training_program({
  "training_program": {
    "daysPerWeek": <populated correctly>,
    "workouts": [],
    "notes": <populated correctly>
  }
})

the weird thing is I ask the agent to create the training program, call the tool, and hand it off to another agent. The handoff also has the workouts array blank:

transfer_to_x_agent({
  "program": {
    "daysPerWeek": <populated correctly>,
    "workouts": [],
    "notes": <populated correctly>
  },
})

but the agent it hands off is able to correctly display the entire training program to the user. so the missing is data is somewhere, but just not in the function tool calls?

Expected behavior

I expected the workouts list on TrainingProgram to be populated

@built-by-as built-by-as added the bug Something isn't working label Apr 21, 2025
@rm-openai
Copy link
Collaborator

what model are you using?

@built-by-as
Copy link
Author

what model are you using?

GPT-4.1

@rm-openai
Copy link
Collaborator

So my best guess is that the model decides it's valid to pass an empty list. Can you try adding function and field descriptions, which will make it clear how to create input? e.g.

class Exercise(BaseModel):
  ""A single exercise, ..."
    ...

class Workout(BaseModel):
   """A workout, which includes a list of exercises"

    exercises: List[Exercise]
    """A list of exercises. Do NOT pass an empty list, pass all exercises known"
...

@function_tool
async def create_training_program(wrapper: RunContextWrapper[ChatContext], training_program: TrainingProgram)
   """Create a training program. You MUST pass a full training program with all parameters filled in"""

This is basically prompt engineering your tools and input. The descriptions are passed to the model, and hopefully it enables the model to do better.

@built-by-as
Copy link
Author

that worked, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants