Skip to content

KeyError: ~TContext while importing #891

Open
@handrew

Description

@handrew

This is a bit of a funky one.

On version 0.0.18 only (not 0.0.17 or before), I get the following trace when one of my FastAPI server files tries to import function_tool.

I cannot reproduce this on my local machine, so it is a bit odd

    from agents import function_tool
  File "/usr/local/lib/python3.11/site-packages/agents/__init__.py", line 8, in <module>
    from .agent import Agent, ToolsToFinalOutputFunction, ToolsToFinalOutputResult
  File "/usr/local/lib/python3.11/site-packages/agents/agent.py", line 18, in <module>
    from .mcp import MCPUtil
  File "/usr/local/lib/python3.11/site-packages/agents/mcp/__init__.py", line 14, in <module>
    from .util import MCPUtil
  File "/usr/local/lib/python3.11/site-packages/agents/mcp/util.py", line 11, in <module>
    from ..tool import FunctionTool, Tool
  File "/usr/local/lib/python3.11/site-packages/agents/tool.py", line 40, in <module>
    ToolFunctionWithToolContext[ToolParams],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 360, in inner
    return cached(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 1391, in __getitem__
    new_args = self._determine_new_args(args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 1440, in _determine_new_args
    new_arg = old_arg[tuple(subargs)]
              ~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 360, in inner
    return cached(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 1391, in __getitem__
    new_args = self._determine_new_args(args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 1439, in _determine_new_args
    subargs.append(new_arg_by_param[x])
                   ~~~~~~~~~~~~~~~~^^^
KeyError: ~TContext

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

    Issue actions