Skip to content

Python: [Bug]: Auto function calling removes null arguments #5934

@cecheta

Description

@cecheta

Description

When using auto function calling, any null arguments that the model generates are removed before the function is invoked. If the parameter is required, then the function will fail to be invoked.

Code Sample

import asyncio
from random import randint
from typing import Annotated, Literal

from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
from pydantic import Field


def get_weather(
    location: Annotated[str, Field(description="The location to get the weather for.")],
    unit: Annotated[
        Literal["C", "F"] | None,
        Field(
            description="The unit for temperature. Only set this if the user specified a unit in their query, "
            "otherwise set it to null."
        ),
    ],
) -> str:
    """Get the weather for a given location."""
    conditions = ["sunny", "cloudy", "rainy", "stormy"]
    return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°{unit or 'C'}."


async def main() -> None:
    client = FoundryChatClient(
        credential=AzureCliCredential(),
    )

    agent = Agent(
        client=client,
        name="WeatherAgent",
        instructions="You are a helpful weather agent. Use the get_weather tool to answer questions.",
        tools=[get_weather],
    )

    result = await agent.run("What's the weather like in Seattle?")
    print(f"Agent: {result}")


if __name__ == "__main__":
    asyncio.run(main())

Error Messages / Stack Traces

The model generates the following function call:

{"location":"Seattle","unit":null}

If you then inspect the function call result, you get the following:

[{"call_id": "call_6WcSppkJ2mMxLYpHPptu0l40", "type": "function_call_output", "output": "Error: Argument parsing failed."}]

Package Versions

agent-framework-core: 1.4.0

Python Version

Python 3.13.6

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions