Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/agents/tool_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _assert_must_pass_tool_arguments() -> str:
_MISSING = object()


@dataclass
@dataclass(eq=False)
class ToolContext(RunContextWrapper[TContext]):
"""The context of a tool call."""

Expand Down
17 changes: 17 additions & 0 deletions tests/test_tool_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
from tests.utils.hitl import make_context_wrapper


def test_tool_context_is_hashable_like_run_context_wrapper() -> None:
# RunContextWrapper is declared with @dataclass(eq=False) so instances remain
# hashable by identity. ToolContext inherits from it and must preserve that
# contract; a bare @dataclass on the subclass would set __hash__ = None.
parent: RunContextWrapper[dict[str, object]] = RunContextWrapper(context={})
child: ToolContext[dict[str, object]] = ToolContext(
context={},
tool_name="t",
tool_call_id="call-hash",
tool_arguments="{}",
)

assert hash(parent) == hash(parent)
assert hash(child) == hash(child)
assert {child: "value"}[child] == "value"


def test_tool_context_requires_fields() -> None:
ctx: RunContextWrapper[dict[str, object]] = RunContextWrapper(context={})
with pytest.raises(ValueError):
Expand Down