Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
):

with project_client.get_openai_client() as openai_client:
with project_client.get_openai_client(agent_name="MyAgent") as openai_client:
agent = project_client.agents.create_version(
agent_name="MyAgent",
definition=PromptAgentDefinition(
Expand All @@ -59,7 +59,6 @@

response = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")

Expand All @@ -71,7 +70,6 @@

response = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
async def main() -> None:
async with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

agent = await project_client.agents.create_version(
Expand All @@ -62,7 +62,6 @@ async def main() -> None:

response = await openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")

Expand All @@ -74,7 +73,6 @@ async def main() -> None:

response = await openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
# Creates prerequisite resources and yields (agent_name, conversation_id).
# Then automatically deletes the created agent version when this context manager exits.
create_and_retrieve_agent_and_conversation(project_client=project_client, model=model) as (
agent_name,
conversation_id,
),
project_client.get_openai_client() as openai_client,
project_client.get_openai_client(agent_name=agent_name) as openai_client,
):

# Retrieve latest version for the prerequisite agent.
Expand All @@ -68,6 +68,5 @@

response = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
async def main():
async with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
# Creates prerequisite resources and yields (agent_name, conversation_id).
# Then automatically deletes the created agent version when this context manager exits.
create_and_retrieve_agent_and_conversation_async(project_client=project_client, model=model) as (
agent_name,
conversation_id,
),
project_client.get_openai_client() as openai_client,
project_client.get_openai_client(agent_name=agent_name) as openai_client,
):

# Retrieve latest version for the prerequisite agent.
Expand All @@ -71,7 +71,6 @@ async def main():

response = await openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

agent = project_client.agents.create_version(
Expand All @@ -59,7 +59,6 @@

with openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
stream=True,
) as response_stream_events:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class CalendarEvent(BaseModel):

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

agent = project_client.agents.create_version(
Expand Down Expand Up @@ -87,7 +87,6 @@ class CalendarEvent(BaseModel):

response = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class CalendarEvent(BaseModel):
async def main() -> None:
async with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):
agent = await project_client.agents.create_version(
agent_name="MyAgent",
Expand Down Expand Up @@ -88,7 +88,6 @@ async def main() -> None:

response = await openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Response output: {response.output_text}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client() as openai_client,
project_client.get_openai_client(agent_name="student-teacher-workflow") as openai_client,
):
# Create Teacher Agent
teacher_agent = project_client.agents.create_version(
Expand Down Expand Up @@ -150,7 +150,6 @@

stream = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}},
input="1 + 1 = ?",
stream=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def main():
async with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client() as openai_client,
project_client.get_openai_client(agent_name="student-teacher-workflow-async") as openai_client,
):

teacher_agent = await project_client.agents.create_version(
Expand Down Expand Up @@ -152,7 +152,6 @@ async def main():

stream = await openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}},
input="1 + 1 = ?",
stream=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client() as openai_client,
project_client.get_openai_client(agent_name="student-teacher-workflow") as openai_client,
):
# Define MCP tool for accessing external resources (optional - can be removed for simpler demo)
# Note: MCP tools in workflows may require special handling depending on the use case
Expand Down Expand Up @@ -168,7 +168,6 @@

stream = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}},
input="Please summarize the Azure REST API specifications Readme",
stream=True,
)
Expand Down Expand Up @@ -233,7 +232,6 @@
response = openai_client.responses.create(
input=input_list,
previous_response_id=response.id,
extra_body={"agent_reference": {"name": workflow.name, "type": "agent_reference"}},
)
print(f"Agent response after approval: {response.output_text}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project_client,
AIProjectClient(
endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential, allow_preview=True
) as project_client,
):
# Enable Azure Monitor tracing
application_insights_connection_string = project_client.telemetry.get_application_insights_connection_string()
Expand All @@ -54,7 +56,7 @@
scenario = os.path.basename(__file__)

with tracer.start_as_current_span(scenario):
with project_client.get_openai_client() as openai_client:
with project_client.get_openai_client(agent_name="MyAgent") as openai_client:
agent_definition = PromptAgentDefinition(
model=os.environ["FOUNDRY_MODEL_NAME"],
instructions="You are a helpful assistant that answers general questions",
Expand All @@ -68,7 +70,6 @@

response = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "id": agent.id, "type": "agent_reference"}},
input="What is the size of France in square miles?",
)
print(f"Response output: {response.output_text}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o
with tracer.start_as_current_span(scenario):
with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(
endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], credential=credential, allow_preview=True
) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):
agent_definition = PromptAgentDefinition(
model=os.environ["FOUNDRY_MODEL_NAME"],
Expand All @@ -101,15 +103,13 @@ def display_conversation_item(item: Any) -> None: # pylint: disable=redefined-o
request = "Hello, tell me a joke."
response = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
input=request,
)
print(f"Answer: {response.output}")

response = openai_client.responses.create(
conversation=conversation.id,
input="Tell another one about computers.",
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)
print(f"Answer: {response.output}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

tool = AzureAISearchTool(
Expand Down Expand Up @@ -82,7 +82,6 @@
stream=True,
tool_choice="required",
input=user_input,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)

for event in stream_response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

tool = AzureFunctionTool(
Expand Down Expand Up @@ -92,7 +92,6 @@
response = openai_client.responses.create(
tool_choice="required",
input=user_input,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)

print(f"Response output: {response.output_text}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

tool = BingCustomSearchPreviewTool(
Expand Down Expand Up @@ -86,7 +86,6 @@
stream_response = openai_client.responses.create(
stream=True,
input=user_input,
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)

for event in stream_response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

tool = BingGroundingTool(
Expand All @@ -86,7 +86,6 @@
stream=True,
tool_choice="required",
input="What is today's date and whether in Seattle?",
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)

for event in stream_response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

tool = BrowserAutomationPreviewTool(
Expand Down Expand Up @@ -77,7 +77,6 @@
Enter the value 'MSFT', to get information about the Microsoft stock price.
At the top of the resulting page you will see a default chart of Microsoft stock price.
Click on 'YTD' at the top of that chart, and report the percent value that shows up just below it.""",
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
)

for event in stream_response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

with (
DefaultAzureCredential() as credential,
AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
project_client.get_openai_client() as openai_client,
AIProjectClient(endpoint=endpoint, credential=credential, allow_preview=True) as project_client,
project_client.get_openai_client(agent_name="MyAgent") as openai_client,
):

tool = CodeInterpreterTool()
Expand All @@ -61,7 +61,6 @@
response = openai_client.responses.create(
conversation=conversation.id,
input="Could you please generate a multiplication chart showing the products for 1-10 multiplied by 1-10 (a 10x10 times table)?",
extra_body={"agent_reference": {"name": agent.name, "type": "agent_reference"}},
tool_choice="required",
)
print(f"Response completed (id: {response.id})")
Expand Down
Loading
Loading