How sabahat-shakeel/openai_sdk_agent_context_manager works
Project Type and Purpose
• This is an open-source Python SDK library (“OpenAI_sdk_agent_context_manager”) that provides context-management facilities for OpenAI Agents.
• It does not implement a full-stack or microservice architecture. Instead, it exposes classes and decorators you import into your application to manage local context during agent runs.
Main Components
a. User Application
• Your Python script or service that imports the SDK, defines a context dataclass, tools, and invokes the Runner.
b. SDK Core Library
• Agent class: encapsulates an LLM agent with a name and list of tools
• Runner class: orchestrates the agent run, invokes tools, and calls the LLM via the OpenAI SDK
• RunContextWrapper<T>: wraps your context object and is passed to tool functions and lifecycle hooks
• function_tool decorator: registers a Python function as a tool the agent can call
c. Local Context Object
• A user-defined dataclass or Pydantic model carrying state and dependencies (e.g. user info, logger, data fetchers)
• Wrapped at runtime in RunContextWrapper and passed to tools
d. External LLM Service
• The OpenAI API endpoint called by the Runner when the agent needs to generate or extend responses
Relationships and Data Flows
• The User Application defines:
• A context instance (e.g. UserInfo)
• Tool functions annotated with @function_tool
• An Agent configured with tools
• Calls Runner.run(agent, input, context)
• Runner.run:
• Instantiates RunContextWrapper around the context object
• Sends the initial prompt + tool metadata to the LLM via OpenAI SDK
• Receives LLM response (tool calls or final output)
• Dispatches to local tool functions, passing them RunContextWrapper
• Aggregates tool outputs into the next prompt or final output
• RunContextWrapper: provides .context for reading/writing user context during tool execution
• Context never travels to the LLM—only the tool outputs and agent messages do
Architectural Patterns and Design Principles
• Inversion of Control / Dependency Injection: user-provided context and tools are injected into the agent runtime
• Decorator Pattern: @function_tool to register arbitrary functions as agent tools
• Single Responsibility:
• Agent – holds config & tools
• Runner – manages execution flow
• RunContextWrapper – encapsulates local context
• Extensibility points:
• Users can define any context type T
• Users can register any async functions as tools