Skip to content

Clarification on the need for RunContextWrapper[UserContext] and Agent[UserContext] #219

Open
@qudratullah0708

Description

@qudratullah0708

I noticed that Agent[UserContext] uses generics, but in the current implementation, it always works with UserContext.

Questions for clarification:

Are there existing or planned use cases where the agent works with other types of contexts (e.g., AdminContext, CustomerContext)?
If UserContext is the only expected type, would it make sense to simplify this by removing generics?
If generics are needed for extensibility, could we add documentation/comments to clarify this?

https://github.com/openai/openai-agents-python/blob/main/docs/agents.md

Understanding the reasoning behind this design could help contributors navigate and extend the codebase more easily. Looking forward to your thoughts!

class UserContext:
def init(self, name, role):
self.name = name
self.role = role # Example: "admin" or "guest"

Now, instead of RunContextWrapper, we can just pass the user directly:

class Agent:
def init(self, name, instructions):
self.name = name
self.instructions = instructions # This will be a function

Dynamic instructions function

def dynamic_instructions(user: UserContext, agent: Agent):
return f"The user's name is {user.name}. They are a {user.role}. Assist them accordingly."

Creating a user

user = UserContext(name="Alice", role="admin")

Creating an agent and assigning the dynamic function

agent = Agent(name="Support Agent", instructions=dynamic_instructions)

Getting dynamic instructions

instructions_text = dynamic_instructions(user, agent)
print(instructions_text)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion about using the SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions