Skip to content

@function_tool bug? #794

Closed
Closed
@Yankzy

Description

@Yankzy

Am getting this error that can't debug:

from agents import Agent, AgentHooks, RunContextWrapper, Tool, function_tool
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
from pydantic import BaseModel
from trading.constants import trading_templates
from trading.alpaca_service import alpaca_service


class TextChatOutputType(BaseModel):
    """Represents a chat response from an agent."""
    response: str


# @function_tool
async def call_backend_method(method_name: str, kwargs: dict):
    return getattr(alpaca_service, method_name)(**kwargs)


template_agent = Agent(
    name="template_agent",
    instructions=prompt_with_handoff_instructions(
        f"""
        blah
        """
    ),
    model="gpt-4.1",
    tools=[],  # Add DB/API tools as needed
    hooks=RuntimeEvents,
)


orchestrator = Agent(
    name="alpaca_trading_assistant",
    instructions=prompt_with_handoff_instructions(
        """
        blah
        """
    ),
    model="gpt-4.1",
    tools=[
        template_agent.as_tool(
            tool_name="template_agent_tool",
            tool_description="Classify user intent and map to template and method",
        ),
        call_backend_method
    ],
    hooks=RuntimeEvents,
)

If I uncomment @function_tool, I get this error:

  File "/app/assistant-be_py/assistant/voice_utils.py", line 68, in <module>
    @function_tool
     ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/tool.py", line 414, in function_tool
    return _create_function_tool(func)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/tool.py", line 324, in _create_function_tool
    schema = function_schema(
             ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/function_schema.py", line 333, in function_schema
    json_schema = ensure_strict_json_schema(json_schema)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/strict_schema.py", line 26, in ensure_strict_json_schema
    return _ensure_strict_json_schema(schema, path=(), root=schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/strict_schema.py", line 72, in _ensure_strict_json_schema
    key: _ensure_strict_json_schema(prop_schema, path=(*path, "properties", key), root=root)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    @function_tool
     ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/tool.py", line 414, in function_tool
    return _create_function_tool(func)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/tool.py", line 324, in _create_function_tool
    schema = function_schema(
             ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/function_schema.py", line 333, in function_schema
    json_schema = ensure_strict_json_schema(json_schema)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/strict_schema.py", line 26, in ensure_strict_json_schema
    return _ensure_strict_json_schema(schema, path=(), root=schema)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/local/lib/python3.12/site-packages/agents/strict_schema.py", line 59, in _ensure_strict_json_schema
    raise UserError(
agents.exceptions.UserError: additionalProperties should not be set for object types. This could be because you're using an older version of Pydantic, or because you configured additional properties to be allowed. If you really need this, update the function or output tool to not use a strict schema.
openai.agents: Shutting down trace provider
openai.agents: Shutting down trace processor <agents.tracing.processors.BatchTraceProcessor object at 0x7f0858ce2bd0>
^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/strict_schema.py", line 72, in _ensure_strict_json_schema
    key: _ensure_strict_json_schema(prop_schema, path=(*path, "properties", key), root=root)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/agents/strict_schema.py", line 59, in _ensure_strict_json_schema
    raise UserError(
agents.exceptions.UserError: additionalProperties should not be set for object types. This could be because you're using an older version of Pydantic, or because you configured additional properties to be allowed. If you really need this, update the function or output tool to not use a strict schema.
openai.agents: Shutting down trace provider
openai.agents: Shutting down trace processor <agents.tracing.processors.BatchTraceProcessor object at 0x7f654aaf6ae0>

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Yankzy

        Issue actions

          @function_tool bug? · Issue #794 · openai/openai-agents-python