Skip to content

Commit 00deb44

Browse files
committed
added azure openai agent features
1 parent 1963da5 commit 00deb44

2 files changed

Lines changed: 277 additions & 0 deletions

File tree

agent-framework/user-guide/agents/agent-types/azure-openai-chat-completion-agent.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,84 @@ async def main():
233233
asyncio.run(main())
234234
```
235235

236+
### Web Search
237+
238+
Access real-time information using the hosted web search tool:
239+
240+
```python
241+
import asyncio
242+
from agent_framework import ChatAgent, HostedWebSearchTool
243+
from agent_framework.azure import AzureOpenAIChatClient
244+
from azure.identity import AzureCliCredential
245+
246+
async def main():
247+
async with ChatAgent(
248+
chat_client=AzureOpenAIChatClient(credential=AzureCliCredential()),
249+
instructions="You are a helpful assistant that can search the web for current information.",
250+
tools=HostedWebSearchTool(
251+
description="Search the web for current information"
252+
)
253+
) as agent:
254+
result = await agent.run("What are the latest developments in artificial intelligence?")
255+
print(result.text)
256+
257+
asyncio.run(main())
258+
```
259+
260+
### MCP (Model Context Protocol) Tools
261+
262+
Connect to external services and APIs using MCP tools:
263+
264+
```python
265+
import asyncio
266+
from agent_framework import ChatAgent, HostedMCPTool
267+
from agent_framework.azure import AzureOpenAIChatClient
268+
from azure.identity import AzureCliCredential
269+
270+
async def main():
271+
async with ChatAgent(
272+
chat_client=AzureOpenAIChatClient(credential=AzureCliCredential()),
273+
instructions="You are a helpful assistant that can search Microsoft documentation.",
274+
tools=HostedMCPTool(
275+
name="Microsoft Learn MCP",
276+
url="https://learn.microsoft.com/api/mcp",
277+
approval_mode="never_require" # Auto-approve for documentation searches
278+
)
279+
) as agent:
280+
result = await agent.run("How do I create an Azure storage account using Azure CLI?")
281+
print(result.text)
282+
283+
asyncio.run(main())
284+
```
285+
286+
### Using Threads for Context Management
287+
288+
Maintain conversation context across multiple interactions:
289+
290+
```python
291+
import asyncio
292+
from agent_framework.azure import AzureOpenAIChatClient
293+
from azure.identity import AzureCliCredential
294+
295+
async def main():
296+
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
297+
instructions="You are a helpful programming assistant."
298+
)
299+
300+
# Create a new thread for conversation context
301+
thread = agent.get_new_thread()
302+
303+
# First interaction
304+
result1 = await agent.run("I'm working on a Python web application.", thread=thread, store=True)
305+
print(f"Assistant: {result1.text}")
306+
307+
# Second interaction - context is preserved
308+
result2 = await agent.run("What framework should I use?", thread=thread, store=True)
309+
print(f"Assistant: {result2.text}")
310+
311+
asyncio.run(main())
312+
```
313+
236314
### Streaming Responses
237315

238316
Get responses as they are generated using streaming:

agent-framework/user-guide/agents/agent-types/azure-openai-responses-agent.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,63 @@ asyncio.run(main())
159159

160160
## Agent Features
161161

162+
### Reasoning Models
163+
164+
Azure OpenAI Responses agents support advanced reasoning models like o1 for complex problem-solving:
165+
166+
```python
167+
import asyncio
168+
from agent_framework.azure import AzureOpenAIResponsesClient
169+
from azure.identity import AzureCliCredential
170+
171+
async def main():
172+
agent = AzureOpenAIResponsesClient(
173+
deployment_name="o1-preview", # Use reasoning model
174+
credential=AzureCliCredential()
175+
).create_agent(
176+
instructions="You are a helpful assistant that excels at complex reasoning.",
177+
name="ReasoningAgent"
178+
)
179+
180+
result = await agent.run("Solve this logic puzzle: If A > B, B > C, and C > D, and we know D = 5, B = 10, what can we determine about A?")
181+
print(result.text)
182+
183+
asyncio.run(main())
184+
```
185+
186+
### Structured Output
187+
188+
Get structured responses from Azure OpenAI Responses agents:
189+
190+
```python
191+
import asyncio
192+
from typing import Annotated
193+
from agent_framework.azure import AzureOpenAIResponsesClient
194+
from azure.identity import AzureCliCredential
195+
from pydantic import BaseModel, Field
196+
197+
class WeatherForecast(BaseModel):
198+
location: Annotated[str, Field(description="The location")]
199+
temperature: Annotated[int, Field(description="Temperature in Celsius")]
200+
condition: Annotated[str, Field(description="Weather condition")]
201+
humidity: Annotated[int, Field(description="Humidity percentage")]
202+
203+
async def main():
204+
agent = AzureOpenAIResponsesClient(credential=AzureCliCredential()).create_agent(
205+
instructions="You are a weather assistant that provides structured forecasts.",
206+
response_format=WeatherForecast
207+
)
208+
209+
result = await agent.run("What's the weather like in Paris today?")
210+
weather_data = result.structured_output
211+
print(f"Location: {weather_data.location}")
212+
print(f"Temperature: {weather_data.temperature}°C")
213+
print(f"Condition: {weather_data.condition}")
214+
print(f"Humidity: {weather_data.humidity}%")
215+
216+
asyncio.run(main())
217+
```
218+
162219
### Function Tools
163220

164221
You can provide custom function tools to Azure OpenAI Responses agents:
@@ -210,6 +267,148 @@ async def main():
210267
asyncio.run(main())
211268
```
212269

270+
### File Search
271+
272+
Enable document search capabilities using the hosted file search tool:
273+
274+
```python
275+
import asyncio
276+
from agent_framework import ChatAgent, HostedFileSearchTool, HostedVectorStoreContent
277+
from agent_framework.azure import AzureOpenAIResponsesClient
278+
from azure.identity import AzureCliCredential
279+
280+
async def main():
281+
# Create a vector store content reference
282+
vector_store = HostedVectorStoreContent(vector_store_id="vs_123")
283+
284+
async with ChatAgent(
285+
chat_client=AzureOpenAIResponsesClient(credential=AzureCliCredential()),
286+
instructions="You are a helpful assistant that can search through files.",
287+
tools=HostedFileSearchTool(
288+
inputs=vector_store,
289+
max_results=10
290+
)
291+
) as agent:
292+
result = await agent.run("Find information about quarterly reports")
293+
print(result.text)
294+
295+
asyncio.run(main())
296+
```
297+
298+
### Web Search
299+
300+
Access real-time information using the hosted web search tool:
301+
302+
```python
303+
import asyncio
304+
from agent_framework import ChatAgent, HostedWebSearchTool
305+
from agent_framework.azure import AzureOpenAIResponsesClient
306+
from azure.identity import AzureCliCredential
307+
308+
async def main():
309+
async with ChatAgent(
310+
chat_client=AzureOpenAIResponsesClient(credential=AzureCliCredential()),
311+
instructions="You are a helpful assistant that can search the web for current information.",
312+
tools=HostedWebSearchTool(
313+
description="Search the web for current information"
314+
)
315+
) as agent:
316+
result = await agent.run("What are the latest developments in artificial intelligence?")
317+
print(result.text)
318+
319+
asyncio.run(main())
320+
```
321+
322+
### Image Analysis and Generation
323+
324+
Azure OpenAI Responses agents support multimodal interactions including image analysis:
325+
326+
```python
327+
import asyncio
328+
from agent_framework import ChatMessage, TextContent, UriContent
329+
from agent_framework.azure import AzureOpenAIResponsesClient
330+
from azure.identity import AzureCliCredential
331+
332+
async def main():
333+
agent = AzureOpenAIResponsesClient(
334+
deployment_name="gpt-4o", # Use vision-capable model
335+
credential=AzureCliCredential()
336+
).create_agent(
337+
instructions="You are a helpful assistant that can analyze images."
338+
)
339+
340+
# Create a message with both text and image content
341+
message = ChatMessage(
342+
role="user",
343+
contents=[
344+
TextContent(text="What do you see in this image?"),
345+
UriContent(
346+
uri="https://example.com/image.jpg",
347+
media_type="image/jpeg"
348+
)
349+
]
350+
)
351+
352+
result = await agent.run(message)
353+
print(result.text)
354+
355+
asyncio.run(main())
356+
```
357+
358+
### MCP (Model Context Protocol) Tools
359+
360+
Connect to external services and APIs using MCP tools:
361+
362+
```python
363+
import asyncio
364+
from agent_framework import ChatAgent, HostedMCPTool
365+
from agent_framework.azure import AzureOpenAIResponsesClient
366+
from azure.identity import AzureCliCredential
367+
368+
async def main():
369+
async with ChatAgent(
370+
chat_client=AzureOpenAIResponsesClient(credential=AzureCliCredential()),
371+
instructions="You are a helpful assistant that can search Microsoft documentation.",
372+
tools=HostedMCPTool(
373+
name="Microsoft Learn MCP",
374+
url="https://learn.microsoft.com/api/mcp",
375+
approval_mode="never_require" # Auto-approve for documentation searches
376+
)
377+
) as agent:
378+
result = await agent.run("How do I create an Azure storage account using Azure CLI?")
379+
print(result.text)
380+
381+
asyncio.run(main())
382+
```
383+
384+
### Using Threads for Context Management
385+
386+
Maintain conversation context across multiple interactions:
387+
388+
```python
389+
import asyncio
390+
from agent_framework.azure import AzureOpenAIResponsesClient
391+
from azure.identity import AzureCliCredential
392+
393+
async def main():
394+
agent = AzureOpenAIResponsesClient(credential=AzureCliCredential()).create_agent(
395+
instructions="You are a helpful programming assistant."
396+
)
397+
398+
# Create a new thread for conversation context
399+
thread = agent.get_new_thread()
400+
401+
# First interaction
402+
result1 = await agent.run("I'm working on a Python web application.", thread=thread, store=True)
403+
print(f"Assistant: {result1.text}")
404+
405+
# Second interaction - context is preserved
406+
result2 = await agent.run("What framework should I use?", thread=thread, store=True)
407+
print(f"Assistant: {result2.text}")
408+
409+
asyncio.run(main())
410+
```
411+
213412
### Streaming Responses
214413

215414
Get responses as they are generated using streaming:

0 commit comments

Comments
 (0)