# Useful but Little-Known Features of OpenAI Agent SDK
๐ Want to manage and version your prompts on the platform instead of hardcoding them?
With Prompt Templates, you can reference prompts created on the OpenAI platform from the SDK, injecting variables dynamically.
๐ Title: Prompt Templates
๐ URL:
๐งฉ Overview
Instead of `instructions`, you can use the `prompt` parameter to reference prompt templates created and managed on the OpenAI platform. For static usage, pass a dict like `{"id": "pmpt_123", "version": "1", "variables": {...}}`. For dynamic usage, pass an async function that returns a prompt dict at runtime, enabling context-dependent variable injection.
๐ How to use it
```python
from agents import Agent, RunContextWrapper
# Static template reference
agent_static = Agent(
name="support",
prompt={
"id": "pmpt_abc123",
"version": "1",
"variables": {
"company_name": "Acme Corp",
"support_level": "premium",
},
},
)
# Dynamic template reference
async def dynamic_prompt(
context: RunContextWrapper[UserContext],
agent: Agent,
) -> dict:
user = context.context
return {
"id": "pmpt_abc123",
"version": "2",
"variables": {
"company_name":
"support_level": user.plan,
"language": user.language,
},
}
agent_dynamic = Agent(
name="dynamic-support",
prompt=dynamic_prompt,
)
```
๐ Building it into production
ใปManage prompts on the platform for updates and rollbacks without code deployment
ใปUse version pinning for stable behavior while gradually rolling out new versions
ใปInject user-attribute-based variables with dynamic templates
ใปShare and reuse prompts across teams for quality standardization
๐ก Use cases
๐ Prompt version management and staged rollouts
๐ข Cross-organization prompt sharing and standardization
๐ Prompt updates without code deployment
๐ค Dynamic variable injection based on user attributes
โ ๏ธ Watch out
`prompt` and `instructions` are mutually exclusive; specifying both causes an error. If the referenced prompt doesn't exist on the platform, you'll also get an error. Verify prompt IDs and versions before deployment, and watch for variable name typos.
โจ With Prompt Templates, move prompt management from "inside the code" to "the platform dashboard."
#
OpenAIAgentSDK# #
AIAgent#