Skip to content

Commit 980fe42

Browse files
authored
Beta4 release of azure-ai-projects SDK (Azure#38873)
1 parent ab0ed5e commit 980fe42

File tree

79 files changed

+1590
-597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1590
-597
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,8 @@
13281328
{
13291329
"filename": "sdk/ai/azure-ai-projects/**",
13301330
"words": [
1331+
"ENTRAID",
1332+
"entraid",
13311333
"aiservices",
13321334
"OTEL",
13331335
"GENAI",

sdk/ai/azure-ai-projects/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Release History
22

3+
## 1.0.0b4 (2024-12-20)
4+
5+
### Bugs Fixed
6+
7+
* Fix for Agent streaming issue (see [GitHub issue 38918](https://github.com/Azure/azure-sdk-for-python/issues/38918))
8+
* Fix for Agent async function `send_email_async` is not called (see [GitHub issue 38898](https://github.com/Azure/azure-sdk-for-python/issues/38898))
9+
* Fix for Agent streaming with event handler fails with "AttributeError: 'MyEventHandler' object has no attribute 'buffer'" (see [GitHub issue 38897](https://github.com/Azure/azure-sdk-for-python/issues/38897))
10+
11+
### Features Added
12+
13+
* Add optional input argument `connection_name` to methods `.inference.get_chat_completions_client`,
14+
`.inference.get_embeddings_client` and `.inference.get_azure_openai_client`.
15+
316
## 1.0.0b3 (2024-12-13)
417

518
### Features Added
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# FunctionTool Specifications
2+
3+
FunctionTool is the utility allowing developers to provide functions within their code and invoke during streaming or running.
4+
5+
## Example of Function
6+
7+
Here is an example of a function:
8+
```python
9+
def fetch_weather(location: str) -> str:
10+
"""
11+
Fetches the weather information for the specified location.
12+
13+
:param location (str): The location to fetch weather for.
14+
:return: Weather information as a JSON string.
15+
:rtype: str
16+
"""
17+
# In a real-world scenario, you'd integrate with a weather API.
18+
mock_weather_data = {"New York": "Sunny, 25°C", "London": "Cloudy, 18°C", "Tokyo": "Rainy, 22°C"}
19+
weather = mock_weather_data.get(location, "Weather data not available for this location.")
20+
weather_json = json.dumps({"weather": weather})
21+
return weather_json
22+
```
23+
24+
Here is an example to attach this function definition to create_agent
25+
26+
```python
27+
functions = FunctionTool({fetch_weather})
28+
29+
agent = project_client.agents.create_agent(
30+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
31+
name="my-assistant",
32+
instructions="You are a helpful assistant",
33+
tools=functions.definitions,
34+
)
35+
```
36+
37+
To verify that the SDK parsed the docstring properly, you can print the definition:
38+
39+
```python
40+
[print(json.dumps(tool.as_dict(), indent=4)) for tool in functions.definitions]
41+
```
42+
43+
Alternatively user can check the tools property in newly created agent:
44+
45+
```python
46+
[print(json.dumps(tool.as_dict(), indent=4)) for tool in agent.tools if tool.type == "function"]
47+
```
48+
49+
The terminal will display the definition as below:
50+
51+
```json
52+
[
53+
{
54+
"type": "function",
55+
"function": {
56+
"name": "fetch_weather",
57+
"description": "Fetches the weather information for the specified location.",
58+
"parameters": {
59+
"type": "object",
60+
"properties": {
61+
"location": {
62+
"type": "string",
63+
"description": "The location to fetch weather for."
64+
}
65+
},
66+
"required": [
67+
"location"
68+
]
69+
}
70+
}
71+
}
72+
]
73+
```
74+
75+
## Requirements for FunctionTool
76+
77+
To ensure `FunctionTool` operates correctly and generates accurate function definitions that agents can reliably call, adhere to the following standards:
78+
79+
1. **Type Annotations**
80+
- All function parameters and return types should be explicitly type-annotated using Python's type hinting.
81+
82+
2. **Structured Docstrings**
83+
- Utilize a consistent docstring format similar to the example above (see also related agent samples in this repository).
84+
- Include clear descriptions for each function and parameter.
85+
86+
3. **Supported Types**
87+
88+
`FunctionTool` maps common Python types to their JSON Schema equivalents, ensuring accurate representation without complex type details:
89+
90+
- **Strings and Numbers**
91+
- `str``string`
92+
- `int``integer`
93+
- `float``number`
94+
- `bool``boolean`
95+
96+
- **Collections**
97+
- `list``array`
98+
- `dict``object`
99+
100+
- **Nullable Types**
101+
- `Optional[type]` includes `null`

sdk/ai/azure-ai-projects/README.md

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Here is an example of how to create an Agent:
253253

254254
```python
255255
agent = project_client.agents.create_agent(
256-
model="gpt-4o",
256+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
257257
name="my-assistant",
258258
instructions="You are helpful assistant",
259259
)
@@ -275,7 +275,10 @@ toolset.add(functions)
275275
toolset.add(code_interpreter)
276276

277277
agent = project_client.agents.create_agent(
278-
model="gpt-4-1106-preview", name="my-assistant", instructions="You are a helpful assistant", toolset=toolset
278+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
279+
name="my-assistant",
280+
instructions="You are a helpful assistant",
281+
toolset=toolset,
279282
)
280283
```
281284

@@ -291,7 +294,7 @@ file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
291294

292295
# Notices that FileSearchTool as tool and tool_resources must be added or the assistant unable to search the file
293296
agent = project_client.agents.create_agent(
294-
model="gpt-4-1106-preview",
297+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
295298
name="my-assistant",
296299
instructions="You are helpful assistant",
297300
tools=file_search_tool.definitions,
@@ -320,7 +323,7 @@ print(f"Created vector store, vector store ID: {vector_store.id}")
320323
file_search = FileSearchTool(vector_store_ids=[vector_store.id])
321324

322325
agent = project_client.agents.create_agent(
323-
model="gpt-4-1106-preview",
326+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
324327
name="my-assistant",
325328
instructions="Hello, you are helpful assistant and can search information from uploaded files",
326329
tools=file_search.definitions,
@@ -350,7 +353,7 @@ file_search_tool = FileSearchTool(vector_store_ids=[vector_store.id])
350353

351354
# Notices that FileSearchTool as tool and tool_resources must be added or the assistant unable to search the file
352355
agent = project_client.agents.create_agent(
353-
model="gpt-4-1106-preview",
356+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
354357
name="my-assistant",
355358
instructions="You are helpful assistant",
356359
tools=file_search_tool.definitions,
@@ -360,7 +363,7 @@ agent = project_client.agents.create_agent(
360363

361364
<!-- END SNIPPET -->
362365

363-
We also can attach files to the existing vector vector store. In the code snippet below, we first create an empty vector store and add file to it.
366+
We also can attach files to the existing vector store. In the code snippet below, we first create an empty vector store and add file to it.
364367

365368
<!-- SNIPPET:sample_agents_vector_store_batch_enterprise_file_search.attach_files_to_store -->
366369

@@ -398,7 +401,7 @@ code_interpreter = CodeInterpreterTool(file_ids=[file.id])
398401

399402
# Create agent with code interpreter tool and tools_resources
400403
agent = project_client.agents.create_agent(
401-
model="gpt-4-1106-preview",
404+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
402405
name="my-assistant",
403406
instructions="You are helpful assistant",
404407
tools=code_interpreter.definitions,
@@ -428,7 +431,7 @@ bing = BingGroundingTool(connection_id=conn_id)
428431
# Create agent with the bing tool and process assistant run
429432
with project_client:
430433
agent = project_client.agents.create_agent(
431-
model="gpt-4-1106-preview",
434+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
432435
name="my-assistant",
433436
instructions="You are a helpful assistant",
434437
tools=bing.definitions,
@@ -462,7 +465,7 @@ ai_search = AzureAISearchTool(index_connection_id=conn_id, index_name="myindexna
462465
# Create agent with AI search tool and process assistant run
463466
with project_client:
464467
agent = project_client.agents.create_agent(
465-
model="gpt-4o-mini",
468+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
466469
name="my-assistant",
467470
instructions="You are a helpful assistant",
468471
tools=ai_search.definitions,
@@ -482,6 +485,8 @@ You can enhance your Agents by defining callback functions as function tools. Th
482485

483486
For more details about calling functions by code, refer to [`sample_agents_stream_eventhandler_with_functions.py`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_functions.py) and [`sample_agents_functions.py`](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions.py).
484487

488+
For more details about requirements and specification of functions, refer to [Function Tool Specifications](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/FunctionTool.md)
489+
485490
Here is an example to use [user functions](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/user_functions.py) in `toolset`:
486491
<!-- SNIPPET:sample_agents_stream_eventhandler_with_toolset.create_agent_with_function_tool -->
487492

@@ -491,7 +496,10 @@ toolset = ToolSet()
491496
toolset.add(functions)
492497

493498
agent = project_client.agents.create_agent(
494-
model="gpt-4-1106-preview", name="my-assistant", instructions="You are a helpful assistant", toolset=toolset
499+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
500+
name="my-assistant",
501+
instructions="You are a helpful assistant",
502+
toolset=toolset,
495503
)
496504
```
497505

@@ -512,7 +520,7 @@ toolset = AsyncToolSet()
512520
toolset.add(functions)
513521

514522
agent = await project_client.agents.create_agent(
515-
model="gpt-4-1106-preview",
523+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
516524
name="my-assistant",
517525
instructions="You are a helpful assistant",
518526
toolset=toolset,
@@ -583,7 +591,10 @@ openapi = OpenApiTool(
583591
# Create agent with OpenApi tool and process assistant run
584592
with project_client:
585593
agent = project_client.agents.create_agent(
586-
model="gpt-4o-mini", name="my-assistant", instructions="You are a helpful assistant", tools=openapi.definitions
594+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
595+
name="my-assistant",
596+
instructions="You are a helpful assistant",
597+
tools=openapi.definitions,
587598
)
588599
```
589600

@@ -618,7 +629,7 @@ print(f"Created vector store, vector store ID: {vector_store.id}")
618629
file_search = FileSearchTool(vector_store_ids=[vector_store.id])
619630

620631
agent = project_client.agents.create_agent(
621-
model="gpt-4-1106-preview",
632+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
622633
name="my-assistant",
623634
instructions="Hello, you are helpful assistant and can search information from uploaded files",
624635
tools=file_search.definitions,
@@ -661,7 +672,7 @@ message = project_client.agents.create_message(
661672

662673
#### Create Message with Code Interpreter Attachment
663674

664-
To attach a file to a message for data analysis, you use `MessageAttachment` and `CodeInterpreterTool`. You must pass `CodeInterpreterTool` as `tools` or `toolset` in `create_agent` call or the file attachment cannot be opened for code interpreter.
675+
To attach a file to a message for data analysis, use `MessageAttachment` and `CodeInterpreterTool` classes. You must pass `CodeInterpreterTool` as `tools` or `toolset` in `create_agent` call or the file attachment cannot be opened for code interpreter.
665676

666677
Here is an example to pass `CodeInterpreterTool` as tool:
667678

@@ -671,7 +682,7 @@ Here is an example to pass `CodeInterpreterTool` as tool:
671682
# Notice that CodeInterpreter must be enabled in the agent creation,
672683
# otherwise the agent will not be able to see the file attachment for code interpretation
673684
agent = project_client.agents.create_agent(
674-
model="gpt-4-1106-preview",
685+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
675686
name="my-assistant",
676687
instructions="You are helpful assistant",
677688
tools=CodeInterpreterTool().definitions,
@@ -695,6 +706,23 @@ message = project_client.agents.create_message(
695706

696707
<!-- END SNIPPET -->
697708

709+
Azure blob storage can be used as a message attachment. In this case, use `VectorStoreDataSource` as a data source:
710+
711+
<!-- SNIPPET:sample_agents_code_interpreter_attachment_enterprise_search.upload_file_and_create_message_with_code_interpreter -->
712+
713+
```python
714+
# We will upload the local file to Azure and will use it for vector store creation.
715+
_, asset_uri = project_client.upload_file("./product_info_1.md")
716+
ds = VectorStoreDataSource(asset_identifier=asset_uri, asset_type=VectorStoreDataSourceAssetType.URI_ASSET)
717+
718+
# Create a message with the attachment
719+
attachment = MessageAttachment(data_source=ds, tools=code_interpreter.definitions)
720+
message = project_client.agents.create_message(
721+
thread_id=thread.id, role="user", content="What does the attachment say?", attachments=[attachment]
722+
)
723+
```
724+
725+
<!-- END SNIPPET -->
698726

699727
#### Create Run, Run_and_Process, or Stream
700728

sdk/ai/azure-ai-projects/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ai/azure-ai-projects",
5-
"Tag": "python/ai/azure-ai-projects_12144a7ce2"
5+
"Tag": "python/ai/azure-ai-projects_e85eaccb70"
66
}

sdk/ai/azure-ai-projects/azure/ai/projects/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
VERSION = "1.0.0b3"
9+
VERSION = "1.0.0b4"

0 commit comments

Comments
 (0)