Skip to content

Commit 5a43ea7

Browse files
committed
Revert "Add Agent to ToolContext"
This reverts commit 3fc7b09.
1 parent 3fc7b09 commit 5a43ea7

3 files changed

Lines changed: 3 additions & 62 deletions

File tree

src/agents/tool_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def __init__(
5656
tool_call_id: str | object = _MISSING,
5757
tool_arguments: str | object = _MISSING,
5858
tool_call: ResponseFunctionToolCall | None = None,
59-
*,
6059
agent: AgentBase[Any] | None = None,
60+
*,
6161
turn_input: list[TResponseInputItem] | None = None,
6262
_approvals: dict[str, _ApprovalRecord] | None = None,
6363
tool_input: Any | None = None,

tests/test_source_compat_constructors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ def test_tool_context_v070_positional_constructor_still_works() -> None:
8686
assert context.agent is None
8787

8888

89-
def test_tool_context_supports_agent_keyword_argument() -> None:
89+
def test_tool_context_supports_appended_agent_positional_argument() -> None:
9090
usage = Usage()
9191
agent = Agent(name="agent")
92-
context = ToolContext(None, usage, "tool_name", "call_id", '{"x":1}', None, agent=agent)
92+
context = ToolContext(None, usage, "tool_name", "call_id", '{"x":1}', None, agent)
9393

9494
assert context.usage is usage
9595
assert context.tool_name == "tool_name"

tests/test_tool_context.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -44,62 +44,3 @@ def test_tool_context_from_agent_context_populates_fields() -> None:
4444
assert tool_ctx.tool_call_id == "call-123"
4545
assert tool_ctx.tool_arguments == '{"a": 1}'
4646
assert tool_ctx.agent is agent
47-
48-
49-
def test_tool_context_agent_none_by_default() -> None:
50-
tool_call = ResponseFunctionToolCall(
51-
type="function_call",
52-
name="test_tool",
53-
call_id="call-1",
54-
arguments="{}",
55-
)
56-
ctx = make_context_wrapper()
57-
58-
tool_ctx = ToolContext.from_agent_context(ctx, tool_call_id="call-1", tool_call=tool_call)
59-
60-
assert tool_ctx.agent is None
61-
62-
63-
def test_tool_context_constructor_accepts_agent_keyword() -> None:
64-
agent = Agent(name="direct-agent")
65-
tool_ctx: ToolContext[dict[str, object]] = ToolContext(
66-
context={},
67-
tool_name="my_tool",
68-
tool_call_id="call-2",
69-
tool_arguments="{}",
70-
agent=agent,
71-
)
72-
73-
assert tool_ctx.agent is agent
74-
75-
76-
def test_tool_context_from_tool_context_inherits_agent() -> None:
77-
original_call = ResponseFunctionToolCall(
78-
type="function_call",
79-
name="test_tool",
80-
call_id="call-3",
81-
arguments="{}",
82-
)
83-
derived_call = ResponseFunctionToolCall(
84-
type="function_call",
85-
name="test_tool",
86-
call_id="call-4",
87-
arguments="{}",
88-
)
89-
agent = Agent(name="origin-agent")
90-
parent_context: ToolContext[dict[str, object]] = ToolContext(
91-
context={},
92-
tool_name="test_tool",
93-
tool_call_id="call-3",
94-
tool_arguments="{}",
95-
tool_call=original_call,
96-
agent=agent,
97-
)
98-
99-
derived_context = ToolContext.from_agent_context(
100-
parent_context,
101-
tool_call_id="call-4",
102-
tool_call=derived_call,
103-
)
104-
105-
assert derived_context.agent is agent

0 commit comments

Comments
 (0)