Skip to content

Add AgentHookContext with turn_input for agent hooks - #2213

Merged
seratch merged 1 commit into
openai:mainfrom
ihower:add-agent-hook-context
Dec 22, 2025
Merged

seratch merged 1 commit into
openai:mainfrom
ihower:add-agent-hook-context

Conversation

@ihower

@ihower ihower commented Dec 20, 2025 •

Copy link
Copy Markdown
Contributor

Based on the idea discussed in #2180 (comment), this PR proposes a concrete implementation.

It adds turn_input to the agent hook context and resolved: openai/openai-agents-js#765

The implementation introduces a new AgentHookContext.

It covers the following hooks:

  • AgentHooks: on_start and on_end
  • RunHooks: on_agent_start and on_agent_end

This change does not modify the hook parameter list, so it should not introduce breaking changes.

AgentHookContext is simply a subclass extension of RunContextWrapper, similar to how ToolContext works for tool hooks.

If this extensibility pattern is acceptable, we can further extend other hook contexts via RunContextWrapper subclasses when needed, for example ComputerActionContext and ShellActionContext.

@ruskaruma

Copy link
Copy Markdown
Contributor

@ihower, i have a question here.

while reading through this, i noticed that on_tool_start / on_tool_end still expose RunContextWrapper in the hook signature, even though function tools already receive a ToolContext instance at runtime (there’s a small cast() workaround in lifecycle_example.py).

with the RunContextWrapper subclass pattern introduced here for agent hooks, would it make sense to apply the same approach to tool hooks in a follow up, to keep things consistent and avoid casting?

@ihower

ihower commented Dec 20, 2025 •

Copy link
Copy Markdown
Contributor Author

@ruskaruma Good question. The reason on_tool_start / on_tool_end still expose RunContextWrapper in the hook signature, instead of switching to ToolContext, is that these hooks are also used by other hosted tools too, such as ComputerAction, LocalShellAction, ShellAction, and ApplyPatchAction.

For these hosted action tools, they still pass RunContextWrapper rather than ToolContext (which is specifically designed for local function tools).

That’s also why I mentioned the idea of introducing dedicated context types for these action tools as well, for example ComputerActionContext or ShellActionContext. This is something I have in mind for a follow-up.

@ruskaruma

Copy link
Copy Markdown
Contributor

Totally makes sense. Thank you so much for the explanation!

@seratch seratch added enhancement New feature or request feature:core labels Dec 22, 2025
@seratch seratch added this to the 0.7.x milestone Dec 22, 2025
@seratch
seratch merged commit 659f706 into openai:main Dec 22, 2025
@seratch seratch modified the milestones: 0.7.x, 0.6.x Jan 6, 2026
@seratch seratch mentioned this pull request Jan 6, 2026
rm-openai pushed a commit that referenced this pull request Jan 6, 2026
This release will include:
- #2260
- #2227
- #2225
- #2235
- #2226
- #2213
- #2243
- #2229
- #2158
- #2214
- #2238

full diff:
v0.6.4...main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants