You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-foundry/agents/how-to/tools/function-calling.md
+76-88Lines changed: 76 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,15 +29,28 @@ Azure AI Agents supports function calling, which allows you to describe the stru
29
29
30
30
::: zone pivot="python"
31
31
32
+
## Example agent code
32
33
33
-
## Define a function for your agent to call
34
-
Start by defining a function for your agent to call. When you create a function for an agent to call, you describe its structure with any required parameters in a docstring.
34
+
> [!NOTE]
35
+
> You can find a streaming example on [GitHub](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_functions.py).
36
+
37
+
Use the following code sample to create an agent and call the function.
35
38
36
39
```python
40
+
import os, time
41
+
from azure.identity import DefaultAzureCredential
42
+
from azure.ai.projects import AIProjectClient
43
+
from azure.ai.agents.models import FunctionTool
37
44
import json
38
45
import datetime
39
46
from typing import Any, Callable, Set, Dict, List, Optional
40
47
48
+
49
+
# Start by defining a function for your agent to call.
50
+
# When you create a function for an agent to call, you describe its structure
51
+
# with any required parameters in a docstring.
52
+
53
+
41
54
deffetch_weather(location: str) -> str:
42
55
"""
43
56
Fetches the weather information for the specified location.
In the sample below we create a client and define a `toolset` which will be used to process the functions defined in `user_functions`.
61
-
62
-
`toolset`: When using the toolset parameter, you provide not only the function definitions and descriptions but also their implementations. The SDK will execute these functions within `create_and_run_process` or streaming. These functions will be invoked based on their definitions.
63
-
-->
64
-
65
-
> [!NOTE]
66
-
> You can find a streaming example on [GitHub](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-agents/samples/agents_streaming/sample_agents_stream_eventhandler_with_functions.py).
67
-
68
-
69
-
```python
70
-
import os, time
71
-
from azure.identity import DefaultAzureCredential
72
-
from azure.ai.projects import AIProjectClient
73
-
from azure.ai.agents.models import FunctionTool
74
68
75
69
# Retrieve the project endpoint from environment variables
> You can find a streaming example on [GitHub](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Agents.Persistent/samples/Sample8_PersistentAgents_FunctionsWithStreaming.md).
149
139
150
-
## Configure client and define functions
151
-
152
-
First, set up the configuration using `appsettings.json` and create a `PersistentAgentsClient`.
140
+
## Configure the client and define functions
153
141
154
142
```csharp
155
143
usingAzure;
@@ -158,24 +146,22 @@ using Azure.Identity;
158
146
usingMicrosoft.Extensions.Configuration;
159
147
usingSystem.Text.Json;
160
148
161
-
// Load configuration from appsettings.json file
149
+
//First, set up the configuration using `appsettings.json`, load it, and create a `PersistentAgentsClient`.
Define the local C# functions that your agent can call, along with their `FunctionToolDefinition` to describe their purpose and parameters to the agent.
162
+
//Define the local C# functions that your agent can call,
163
+
//along with their `FunctionToolDefinition` to describe their purpose and parameters to the agent.
176
164
177
-
```csharp
178
-
// Function to get the user's favorite city (hardcoded for example)
179
165
stringGetUserFavoriteCity() =>"Seattle, WA";
180
166
// Definition for the GetUserFavoriteCity function, describing its purpose to the agent
181
167
FunctionToolDefinitiongetUserFavoriteCityTool=new("getUserFavoriteCity", "Gets the user's favorite city.");
"You are a weather bot. Use the provided functions to help answer questions. Customize your responses to the user's preferences as much as possible and use friendly nicknames for cities whenever possible.",
0 commit comments