Skip to content

Add more arguments to agent/run hooks #2180

Closed

Description

@seratch

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.

see also: openai/openai-agents-js#765

Activity

  1. added this to the 0.7.x milestone on Dec 15, 2025
  2. self-assigned this
    on Dec 15, 2025
  3. added
    enhancement
    on Dec 15, 2025
  4. ruskaruma commented on Dec 16, 2025

    @ruskaruma
    Contributor

    @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.

  5. modified the milestones: 0.7.x, 0.8.x on Dec 19, 2025
  6. ihower commented on Dec 20, 2025

    @ihower
    Contributor

    @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?

  7. seratch commented on Dec 22, 2025

    @seratch
    MemberAuthor

    @ihower Thanks for the idea. I agree that this is a safe and robust enhancement for covering more scenarios!

  8. modified the milestones: 0.8.x, 0.7.x on Dec 22, 2025
  9. modified the milestones: 0.7.x, 0.6.x, 0.8.x, 0.9.x on Jan 17, 2026
  10. seratch commented on Jan 29, 2026

    @seratch
    MemberAuthor

    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

  11. modified the milestones: 0.9.x, 0.6.x on Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementfeature:core

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions