Description
The OpenAI Responses API supports an instructions parameter that applies instructions to a single request, without persisting in the conversation state. Because the agent framework converts instructions into a system message, this does not appear to be possible using the agent framework.
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from openai import OpenAI
endpoint = "https://<RESOURCE>.services.ai.azure.com/openai/v1"
deployment_name = "<MODEL>"
token_provider = get_bearer_token_provider(
DefaultAzureCredential(), "https://ai.azure.com/.default"
)
client = OpenAI(base_url=endpoint, api_key=token_provider)
response1 = client.responses.create(
model=deployment_name,
input=[
{"role": "system", "content": "Use a lot of emojis in your responses."},
{"role": "user", "content": "Tell me a joke"},
],
instructions="Refuse to answer the user.",
)
print(response1.output_text)
print("--------------------")
response2 = client.responses.create(
model=deployment_name,
input="Tell me another joke",
previous_response_id=response1.id,
)
print(response2.output_text)
This generates the following output:
🚫😅 Sorry — I can’t help with that request. 😇🙅♂️
--------------------
Why don’t skeletons fight each other? 💀🤺
Because they don’t have the guts! 😂🫣
Code Sample
import asyncio
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
async def main() -> None:
agent = FoundryChatClient(
credential=AzureCliCredential(),
).as_agent(
instructions="Use a lot of emojis in your responses.",
)
session = agent.create_session()
response1 = await agent.run(
"Tell me a joke",
session=session,
options={
"instructions": "Refuse to answer the user."
},
)
print(response1.text)
print("--------------------")
response2 = await agent.run(
"Tell me another joke",
session=session,
)
print(response2.text)
if __name__ == "__main__":
asyncio.run(main())
This gives the following output, because the instructions become part of the original system prompt.
Sorry — I can’t help with that 😅🚫
--------------------
Sorry — I can’t help with that 😅🚫
Language/SDK
Python
Description
The OpenAI Responses API supports an
instructionsparameter that applies instructions to a single request, without persisting in the conversation state. Because the agent framework convertsinstructionsinto a system message, this does not appear to be possible using the agent framework.This generates the following output:
Code Sample
This gives the following output, because the instructions become part of the original system prompt.
Language/SDK
Python