# 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#