Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform
Hi staff01
Sorry for the delay in response and thank you for providing us the investigation time.
I am emphasizing on new Foundry code itself for simplicity.
-
Runs are replaced by Openai responses. But I don't know how to make a specific agent respond in a conversation, similar to how it did for threads.
Step :1 Agent creation with desired tools.
from azure.ai.projects.models import (
CodeInterpreterTool,
PromptAgentDefinition,
)
# Create the agent
agent = project.agents.create_version(
agent_name="my-agent",
definition=PromptAgentDefinition(
model="gpt-4.1",
instructions=(
"You politely help with math "
"questions. Use the Code "
"Interpreter tool when asked "
"to visualize numbers."
),
tools=[CodeInterpreterTool()],
),
)
Step 2: We create a conversation with User input then
# Create a conversation with initial message
conversation = openai.conversations.create(
items=[
{
"type": "message",
"role": "user",
"content": (
"Hi, Agent! Draw a graph "
"for a line with a rate "
"of change of 4 and "
"y-intercept of 9."
),
}
],
Step 3: We use conversation id, agent.name to generate the responses
# Send a response with the agent
response = openai.responses.create(
conversation=conversation.id,
extra_body={
"agent_reference": {
"name": agent.name,
"type": "agent_reference",
}
},
input=(
"Please address the user as "
"Jane Doe. The user has a "
"premium account"
),
)
Regarding below query
I can't find any reference on how to list messages in a conversation - it's like it doesn't exist.
Once response is Generated with conversation.id and user input. Use a for loop to print all items in the response.
# Send a response with the agent
response = openai.responses.create(
conversation=conversation.id,
extra_body={
"agent_reference": {
"name": agent.name,
"type": "agent_reference",
}
},
input=(
"Please address the user as "
"Jane Doe. The user has a "
"premium account"
),
)
# Print the response output
for item in response.output:
if item.type == "message":
for block in item.content:
print(block.text)
Hope it provides the needed clarity.
Thank you