# Copyright (c) Microsoft. All rights reserved. import asyncio import os from agent_framework.azure import AzureOpenAIResponsesClient from azure.identity import AzureCliCredential """ Multi-Turn Conversations — Use AgentThread to maintain context This sample shows how to keep conversation history across multiple calls by reusing the same thread object. Environment variables: AZURE_AI_PROJECT_ENDPOINT — Your Azure AI Foundry project endpoint AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME — Model deployment name (e.g. gpt-4o) """ async def main() -> None: # credential = AzureCliCredential() client = AzureOpenAIResponsesClient( project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], deployment_name=os.environ["AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME"], credential=credential, ) agent = client.as_agent( name="ConversationAgent", instructions="You are a friendly assistant. Keep your answers brief.", ) # # # Create a thread to maintain conversation history thread = agent.get_new_thread() # First turn result = await agent.run("My name is Alice and I love hiking.", thread=thread) print(f"Agent: {result}\n") # Second turn — the agent should remember the user's name and hobby result = await agent.run("What do you remember about me?", thread=thread) print(f"Agent: {result}") # if __name__ == "__main__": asyncio.run(main())