You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've been receiving many feature requests to add more arguments to the agent/run hooks. The examples are:
turn_input to on_agent_start
arguments to on_tool_start/on_tool_end
and perhaps other data would be needed in the future. However, the current design of the lifecyle hooks does not allow us to quickly add those because changing the method signature could be a breaking change to existing app that rely on the hooks feature.
To get rid of this restriction, we may want to consider accepting both the current set of the arguments and a new unified dict (or similar) object that contains all possible argument data.
@seratch if useful, i can help on this one by implementing a backward-compatible hook extension approach that avoids further positional signature changes using an extensible payload.
let me know if this aligns with what you had in mind or if there’s another direction planned. happy to take this on if no one else is working on it.
@seratch I have one question about the motivation for adding an extensible data payload.
The hook parameter context: RunContextWrapper[TContext] already seems extensible. For example, on_tool_start receives a ToolContext (and it already includes tool arguments), which is a subclass of RunContextWrapper. If we need to pass more information to tool hooks, we could add new attributes to ToolContext without changing the on_tool_start signature. That would avoid compatibility issues with existing hook implementations.
More broadly, for different scenarios we can introduce different RunContextWrapper subclasses. For instance, the ComputerAction and LocalShellAction hooks currently receive a RunContextWrapper and therefore lack some action-specific data. But we could define something like ComputerActionContext / LocalShellActionContext inheriting from RunContextWrapper and attach the additional fields there. The hook parameter type stays the same, while the runtime object provides richer context.
Given this, do we still need a separate extensible data payload?
Reacted by ishaan, Sergey Filimonov and Jao Garcia
Activity
ruskaruma commentedon Dec 16, 2025
@seratch if useful, i can help on this one by implementing a backward-compatible hook extension approach that avoids further positional signature changes using an extensible payload.
let me know if this aligns with what you had in mind or if there’s another direction planned. happy to take this on if no one else is working on it.
feat: Add extensible data payload to lifecycle hooks (openai#2180)
test: Add tests for extensible data payload in hooks (openai#2180)
fix: Use Optional for Python 3.9 compatibility (openai#2180)
ihower commentedon Dec 20, 2025
@seratch I have one question about the motivation for adding an extensible data payload.
The hook parameter context:
RunContextWrapper[TContext]already seems extensible. For example,on_tool_startreceives aToolContext(and it already includes tool arguments), which is a subclass ofRunContextWrapper. If we need to pass more information to tool hooks, we could add new attributes toToolContextwithout changing theon_tool_startsignature. That would avoid compatibility issues with existing hook implementations.More broadly, for different scenarios we can introduce different
RunContextWrappersubclasses. For instance, theComputerActionandLocalShellActionhooks currently receive aRunContextWrapperand therefore lack some action-specific data. But we could define something likeComputerActionContext/LocalShellActionContextinheriting fromRunContextWrapperand attach the additional fields there. The hook parameter type stays the same, while the runtime object provides richer context.Given this, do we still need a separate extensible data payload?
seratch commentedon Dec 22, 2025
@ihower Thanks for the idea. I agree that this is a safe and robust enhancement for covering more scenarios!
seratch commentedon Jan 29, 2026
The missing turn_input was resolved by #2213; Regarding the tool arguments, we'll continue encouraging to cast the context data this way:
https://github.com/openai/openai-agents-python/blob/v0.7.0/examples/basic/lifecycle_example.py#L77-L99