Skip to content

Commit bf9f8fa

Browse files
committed
Update to the new framework
1 parent 001b612 commit bf9f8fa

53 files changed

Lines changed: 3232 additions & 1939 deletions

Some content is hidden

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

docs/.vitepress/config.mts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,53 @@ export default defineConfig({
5959
provider: 'local'
6060
}
6161
}
62+
},
63+
pt: {
64+
label: 'Português',
65+
lang: 'pt',
66+
themeConfig: {
67+
sidebar: [
68+
{
69+
text: 'Bem-vindo',
70+
items: [
71+
{ text: 'Começar', link: '/pt/index' },
72+
{ text: 'Sobre o workshop', link: '/pt/about' },
73+
]
74+
},
75+
{
76+
text: 'Configuração',
77+
items: [
78+
{ text: 'Configuração do Ambiente de Desenvolvimento', link: '/pt/dev-environment' }
79+
]
80+
},
81+
{
82+
text: 'Workshop',
83+
items: [
84+
{ text: '1. Configurar Microsoft Foundry', link: '/pt/1_microsoft-foundry' },
85+
{ text: '2. Crie seu primeiro agente', link: '/pt/2_create-agent' },
86+
{ text: '3. Adicionar instruções', link: '/pt/3_add-instructions' },
87+
{ text: '4. Adicionar conhecimento', link: '/pt/4_add-knowledge' },
88+
{ text: '5. Adicionar ferramenta de estimativa', link: '/pt/5_add-tool' },
89+
{ text: '6. Integração MCP', link: '/pt/6_add-mcp' },
90+
]
91+
},
92+
{
93+
text: 'Recursos',
94+
items: [
95+
{ text: 'Servidor MCP de Pizza', link: '/pt/pizza-mcp' },
96+
{ text: 'Azure Classroom', link: '/pt/get-azure' }
97+
]
98+
},
99+
{ text: 'Licença', link: '/pt/license' },
100+
{ text: '✉️ Contato e Feedback', link: '/pt/contact-feedback' }
101+
],
102+
socialLinks: [
103+
{ icon: 'github', link: 'https://github.com/GlobalAICommunity/agentcon-pizza-workshop' }
104+
],
105+
search: {
106+
provider: 'local'
107+
}
108+
}
62109
}
63110
},
64111
themeConfig: {

docs/2_create-agent.md

Lines changed: 55 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Create Your First Agent
22

3-
In this chapter, well walk through the process of creating your very first AI agent using the **Microsoft Foundry Agent Service**.
4-
By the end, youll have a simple agent running locally that you can interact with in real time.
3+
In this chapter, we'll walk through the process of creating your very first AI agent using the **Foundry Agent Service**.
4+
By the end, you'll have a simple agent running locally that you can interact with in real time.
55

66
First switch back to the Github codespace environment you created earlier. Make sure the terminal pane is still opened on the **workshop** folder.
77

88

99
## Login to Azure
1010

11-
Before you can use the Microsoft Foundry Agent Service, you need to sign in to your Azure subscription.
11+
Before you can use the Foundry Agent Service, you need to sign in to your Azure subscription.
1212

1313
Run the following command and follow the on-screen instructions. Use credentials that have access to your Microsoft Foundry resource:
1414

@@ -23,37 +23,34 @@ az login --use-device-code
2323
Next, install the Python packages needed to work with Microsoft Foundry and manage environment variables:
2424

2525
```shell
26-
pip install azure-identity
27-
pip install azure-ai-projects
28-
pip install azure-ai-agents==1.2.0b5
29-
pip install jsonref
30-
pip install python-dotenv
26+
pip install openai azure-identity azure-ai-projects==2.0.0b1 jsonref python-dotenv
3127
```
3228

3329

3430
### Create a `.env` File
3531

36-
Well store secrets (such as your project connection string) in an environment file for security and flexibility.
32+
We'll store secrets (such as your project endpoint) in an environment file for security and flexibility.
3733

3834
1. **Create a file named `.env` in the root of your project directory.**
3935

40-
2. **Add the following line to the file:**
36+
2. **Add the following lines to the file:**
4137

4238
```env
43-
PROJECT_CONNECTION_STRING="https://<your-foundry-resource>.services.ai.azure.com/api/projects/<your-project-name>"
39+
PROJECT_ENDPOINT="https://<your-foundry-resource>.services.ai.azure.com/api/projects/<your-project-name>"
40+
MODEL_DEPLOYMENT_NAME="gpt-4o"
4441
```
4542
4643
Replace `https://<your-foundry-resource>.services.ai.azure.com/api/projects/<your-project-name>` with the actual values from your Microsoft Foundry project.
4744
4845
![](/public/foundry/foundry-project-string.png)
4946
5047
51-
3. **Where to find your connection string:**
48+
3. **Where to find your endpoint:**
5249
5350
- Go to the **Microsoft Foundry portal**
5451
- Navigate to your project
5552
- Click on **Overview**
56-
- The connection string will be displayed on the homepage of your project
53+
- The endpoint will be displayed on the homepage of your project
5754
5855
5956
@@ -65,7 +62,7 @@ Replace `https://<your-foundry-resource>.services.ai.azure.com/api/projects/<you
6562
6663
## Create a Basic Agent
6764
68-
Well now create a basic Python script that defines and runs an agent.
65+
We'll now create a basic Python script that defines and runs an agent.
6966
7067
- Start by creating a new file called: **`agent.py`** in the **workshop** folder
7168
@@ -77,126 +74,89 @@ These imports bring in the Azure SDK, environment handling, and helper classes:
7774
7875
```python
7976
import os
80-
from azure.ai.projects import AIProjectClient
81-
from azure.identity import DefaultAzureCredential
82-
from azure.ai.agents.models import MessageRole, FilePurpose, FunctionTool, FileSearchTool, ToolSet
8377
from dotenv import load_dotenv
78+
from azure.identity import DefaultAzureCredential
79+
from azure.ai.projects import AIProjectClient
80+
from azure.ai.projects.models import PromptAgentDefinition
8481
```
8582

8683
### Load the `.env` File
8784

8885
Load environment variables into your script by adding this line to `agent.py`:
8986

9087
```python
91-
load_dotenv(override=True)
88+
load_dotenv()
9289
```
9390

9491

9592

96-
### Create an `AIProjectClient` Instance
93+
### Create the Project Client
9794

98-
This client connects your script to the Microsoft Foundry service using the connection string and your Azure credentials.
95+
This client connects your script to the Microsoft Foundry service using the endpoint and your Azure credentials.
9996

10097
```python
10198
project_client = AIProjectClient(
102-
endpoint=os.environ["PROJECT_CONNECTION_STRING"],
103-
credential=DefaultAzureCredential()
99+
endpoint=os.environ["PROJECT_ENDPOINT"],
100+
credential=DefaultAzureCredential(),
104101
)
102+
openai_client = project_client.get_openai_client()
105103
```
106104

107105

108106

109107
### Create the Agent
110108

111-
Now, lets create the agent itself. In this case, it will use the **GPT-4o** model.
109+
Now, let's create the agent itself. We'll use `create_version` to create a Foundry Agent with a `PromptAgentDefinition`.
112110

113111
```python
114-
agent = project_client.agents.create_agent(
115-
model="gpt-4o",
116-
name="my-agent"
112+
agent = project_client.agents.create_version(
113+
agent_name="hello-world-agent",
114+
definition=PromptAgentDefinition(
115+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
116+
),
117117
)
118-
print(f"Created agent, ID: {agent.id}")
118+
print(f"Agent created (id: {agent.id}, name: {agent.name}, version: {agent.version})")
119119
```
120120

121121

122122

123-
### Create a Thread
123+
### Create a Conversation
124124

125-
Agents interact within threads. A thread is like a conversation container that stores all messages exchanged between the user and the agent.
125+
Agents interact within conversations. A conversation is like a container that stores all messages exchanged between the user and the agent.
126126

127127
```python
128-
thread = project_client.agents.threads.create()
129-
print(f"Created thread, ID: {thread.id}")
128+
conversation = openai_client.conversations.create()
129+
print(f"Created conversation (id: {conversation.id})")
130130
```
131131

132132

133133

134-
### Add a Message
134+
### Chat with the Agent
135135

136-
This loop lets you send messages to the agent. Type into the terminal, and the message will be added to the thread.
136+
This loop lets you send messages to the agent. Type into the terminal, and the message will be sent to the agent.
137137

138138
```python
139-
try:
140-
while True:
141-
142-
# Get the user input
143-
user_input = input("You: ")
144-
145-
# Break out of the loop
146-
if user_input.lower() in ["exit", "quit"]:
147-
break
148-
149-
# Add a message to the thread
150-
message = project_client.agents.messages.create(
151-
thread_id=thread.id,
152-
role=MessageRole.USER,
153-
content=user_input
139+
while True:
140+
# Get the user input
141+
user_input = input("You: ")
142+
143+
if user_input.lower() in ["exit", "quit"]:
144+
print("Exiting the chat.")
145+
break
146+
147+
# Get the agent response
148+
response = openai_client.responses.create(
149+
conversation=conversation.id,
150+
input=user_input,
151+
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
154152
)
155-
```
156153

157-
158-
159-
### Create and Process an Agent Run
160-
161-
The agent processes the conversation thread and generates a response.
162-
163-
```python
164-
run = project_client.agents.runs.create_and_process(
165-
thread_id=thread.id,
166-
agent_id=agent.id
167-
)
154+
# Print the agent response
155+
print(f"Assistant: {response.output_text}")
168156
```
169157

170158

171159

172-
### Fetch All Messages from the Thread
173-
174-
This retrieves all messages from the thread and prints the agent’s most recent response.
175-
176-
```python
177-
messages = project_client.agents.messages.list(thread_id=thread.id)
178-
first_message = next(iter(messages), None)
179-
if first_message:
180-
print(next((item["text"]["value"] for item in first_message.content if item.get("type") == "text"), ""))
181-
```
182-
183-
184-
185-
### Delete the Agent When Done
186-
187-
Once you’re finished, clean up by deleting the agent:
188-
189-
```python
190-
finally:
191-
# Clean up the agent when done
192-
project_client.agents.delete_agent(agent.id)
193-
print("Deleted agent")
194-
```
195-
196-
Add this code to delete the agent outside of the while True-loop. Otherwise the agent will be deleted immediately after your first interaction.
197-
198-
199-
200160
## Run the Agent
201161

202162
Finally, run the Python script:
@@ -211,17 +171,17 @@ You can now chat with your agent directly in the terminal. Type `exit` or `quit`
211171

212172
If you get an error (the principal `*****-****-***-****-*****`) does **not have permission** to create assistants in your Microsoft Foundry project. Specifically, it's missing the **`Microsoft.CognitiveServices/accounts/AIServices/agents/write`** data action.
213173

214-
Heres how to fix it:
174+
Here's how to fix it:
215175

216176
1. **Go to the Azure Portal**: [https://portal.azure.com](https://portal.azure.com)
217177

218178
2. **Navigate to your Microsoft Foundry resource**:
219179
- You can find it by searching for the name of your Foundry resource (e.g., `my-foundry-name`).
220180

221-
3. **Open the Access Control (IAM) panel**:
181+
3. **Open the "Access Control (IAM)" panel**:
222182
- In the left-hand menu of the resource, click **Access Control (IAM)**.
223183

224-
4. **Click Add role assignment**:
184+
4. **Click "Add role assignment"**:
225185
- Choose **Add → Add role assignment**
226186
- Select a role that includes the required data action:
227187
- Recommended: **Cognitive Services Contributor** or a **custom role** that includes `Microsoft.CognitiveServices/accounts/AIServices/agents/write`
@@ -241,15 +201,14 @@ Here’s how to fix it:
241201
In this chapter, you have:
242202

243203
- Logged in to Azure
244-
- Retrieved a connection string
204+
- Retrieved a project endpoint
245205
- Separated secrets from code using `.env`
246-
- Created a basic agent with the Microsoft Foundry Agent Service
247-
- Started a conversation with a **GPT-4o** model
248-
- Cleaned up by deleting the agent when done
206+
- Created a basic agent with the Foundry Agent Service
207+
- Started a conversation with the agent
249208

250209

251210
## Final code sample
252211

253212
```python
254213
<!--@include: ./codesamples/agent_2.py-->
255-
```
214+
```

0 commit comments

Comments
 (0)