Skip to content

Python: [Bug]: Flat function mappings bypass progressive tool name checks #9108

Description

@BlueRaddish

Description

Flat Responses-style function definitions are accepted as tools, but their names are not recognized by the shared _get_tool_name helper. FunctionInvocationContext.remove_tools("lookup") leaves the flat definition in the live list, and adding a separate flat definition with the same name does not raise the documented duplicate-name error. Nested Chat Completions-style definitions work.

Reproduction Steps

from agent_framework import FunctionInvocationContext
from agent_framework._tools import FunctionTool

lookup = {"type": "function", "name": "lookup", "parameters": {"type": "object"}}
tools = [lookup]
context = FunctionInvocationContext(
    function=FunctionTool(name="loader", description="Load tools", func=lambda: None),
    arguments={},
    tools=tools,
)
context.remove_tools("lookup")
assert tools == []  # fails: lookup remains available

Expected behavior

Flat function mappings should participate in name-based removal and duplicate checks, while non-function built-in tool definitions remain unaffected.

Actual behavior

_get_tool_name only inspects the nested function key. No model, hosted service, or approval flow is needed to reproduce the list-management behavior.

Environment

Current main at 1aca61d; Ubuntu WSL, Python 3.13.16, editable core package. Three focused behavioral regressions fail on the original helper. A local one-line prototype recognizing the flat function shape passes those regressions and all 218 tests in tests/core/test_middleware.py and tests/core/test_tools.py. Ruff and formatting checks pass; this is not full function-loop validation.

Additional context

Fresh issue/open-PR searches found no overlapping report or fix. Since the helper lives in _tools.py and is shared by progressive tool exposure, I am reporting this for core-team confirmation of scope and the required validation before opening a code PR. I can contribute the focused regressions and prototype if this direction is appropriate.

AI assistance: OpenAI Codex reproduced the bug and prepared this report.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentmiddlewareUsage: [Issues, PRs], Target: middleware related featurespythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions