Repository navigation
Add AgentHookContext with turn_input for agent hooks - #2213
Conversation
|
@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? |
|
@ruskaruma Good question. The reason 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 |
|
Totally makes sense. Thank you so much for the explanation! |
Based on the idea discussed in #2180 (comment), this PR proposes a concrete implementation.
It adds
turn_inputto the agent hook context and resolved: openai/openai-agents-js#765The implementation introduces a new
AgentHookContext.It covers the following hooks:
on_startandon_endon_agent_startandon_agent_endThis change does not modify the hook parameter list, so it should not introduce breaking changes.
AgentHookContextis simply a subclass extension ofRunContextWrapper, similar to howToolContextworks for tool hooks.If this extensibility pattern is acceptable, we can further extend other hook contexts via
RunContextWrappersubclasses when needed, for exampleComputerActionContextandShellActionContext.