Skip to content

Commit cb67e0a

Browse files
Merge pull request #27 from Azure-Samples/agent-quest-fixes
added complete agent mode quest and action
2 parents 2c3dedc + 417c4fa commit cb67e0a

File tree

2 files changed

+74
-62
lines changed

2 files changed

+74
-62
lines changed

.github/steps/6-build-agent.md

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ If you used a different region, please [create a new Azure AI Foundry project](h
4949

5050
You'll be prompted to save the agent's configuration file. Assign the name `my-agent.agent.yaml` and save the file in the agents folder you created earlier. Once saved, the yaml file and the Agent Designer will open for you to configure your agent.
5151

52+
**Security Note 🔐**
53+
54+
Add the `my-agent.agent.yaml` file to your `.gitignore` file to prevent it from being committed to your repository. This file will contain sensitive information such as your subscription ID and agent ID, which should not be shared publicly.
55+
5256
On the Agent Designer,
53-
- Give your agent a name. i.e `my-agent`
57+
- Give your agent a name. i.e `my-agent` _that will have been auto-populated for you._
5458
- Enter a foundation model for your agent from your model list. This model will power the agent's core reasoning and language capabilities. _Example. gpt-4o_
5559
- System instructions for your agent. This tells the agent how it should behave. Enter the following:
5660

@@ -76,9 +80,9 @@ If you used a different region, please [create a new Azure AI Foundry project](h
7680
responses.
7781
tools: [] # We'll add tools later
7882
````
79-
3. **Deploy Agent**
83+
3. **Create Agent**
8084
81-
Click on the **Deploy to Azure AI Foundry** button in the Agent Designer to deploy your agent to Azure AI Foundry Once created, the agent will pop up in the AI Foundry extension under the "Agents" section.
85+
Click on the **Create Agent on Azure AI Foundry** button in the Agent Designer to create and deploy your agent to Azure AI Foundry. Once created, the agent will pop up in the AI Foundry extension under the "Agents" section.
8286
8387
![Deploy to Azure AI Foundry Button](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/deploy-to-ai-foundry.png?raw=true)
8488
@@ -131,55 +135,59 @@ Tools calling is a powerful feature that allows your agent to perform specific t
131135
132136
6. Once connected, click **close**
133137
134-
### Prepare the Bing Grounding tool YAML
138+
### Add bing tool to your Agent
139+
With your `my-agent.agent.yaml` file open, click on the Foundry icon at the top right corner to open the Agent Designer.
135140
136-
Back on Visual Studio Code, create a tool configuration .yaml file called `bing.yaml` in the same directory as your agent configuration file (the agent folder). Paste in the following into the `bing.yaml` file:
141+
![Open Agent Designer](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/open-agent-designer.png?raw=true)
137142
138-
```yaml
139-
type: bing_grounding
140-
id: bing_search
141-
options:
142-
tool_connections:
143-
- /subscriptions/<subscription_ID>/resourceGroups/<resource_group_name>/providers/Microsoft.MachineLearningServices/workspaces/<project_name>/connections/<bing_grounding_connection_name>
144-
```
143+
On the `yaml` file, scroll down to the `tools` section and delete the empty array `[]`, then: -
144+
145+
- Click **Enter** followed by **-** to invoke the YAML IntelliSense that will help you add a new tool configuration easily.
145146
146-
Replace the placeholders in the connection string under the tool_connections section with your information:
147+
![Open Agent Designer](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/new-tool-intellisense.png?raw=true)
147148
148-
- `subscription_ID` = Your Azure Subscription ID
149-
- `resource_group_name` = Your Resource Group name
150-
- `project_name` = Your Project name on AI Foundry
151-
- `bing_grounding_connection_name` = The connection name **NOT** the bing resource name
149+
- Select the `Agent Tool - Bing Grounding` tool from the list of available built-in tools, and this will add the configuration for the Bing Search API tool to your agent configuration file.
152150
153-
Save the `bing.yaml` file.
151+
- To add the connection to the Bing resource you created earlier, type the **/** character after the **-** under **tool_connections**, and start typing `subscriptions`, and you'll see the IntelliSense kick in with your own subscription details. Select to complete the connection selection.
154152
155-
On the Agent Designer, click on the + icon next to the "Tools" section. This will prompt you to select a yaml file for the tool. Select the `bing.yaml` file you created earlier. Click on **Update Agent on Azure AI Foundry** to update your agent with the new tool to Azure AI Foundry.
153+
![Subscription aware intelliSense](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/sub-intellisense.png?raw=true)
156154
157-
![Add bing tool via extension](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/update-tool.png?raw=true)
155+
If the intelliSense fails, paste in the following
156+
157+
`/subscriptions/<subscription_ID>/resourceGroups/<resource_group_name>/providers/Microsoft.MachineLearningServices/workspaces/<project_name>/connections/<bing_grounding_connection_name>`
158+
159+
and replace the placeholders with your information:
160+
- `subscription_ID` = Your Azure Subscription ID
161+
- `resource_group_name` = Your Resource Group name
162+
- `project_name` = Your Project name on AI Foundry
163+
- `bing_grounding_connection_name` = The connection name **NOT** the bing resource name
158164
159-
Now that we have added the Bing Search API tool to our agent, we can test it in the Playground. Open the "Agent Playground" and send the agent a message like _"What's the weather in Nairobi right now?"_ The agent should use the Bing Search API tool to fetch the current weather information and respond with a friendly message.
165+
- A Bing Grounding connection should appear under the **Tool** section on the Agent Designer. Click on **Update Agent on Azure AI Foundry** to update your agent with the new tool configuration.
166+
167+
Now that you've added the Bing Grounding to your agent, you can test it in the Playground. Open the "Agent Playground" and send the agent a message like _"What's the weather in Nairobi right now?"_ The agent should use the Bing Search API tool to fetch the current weather information and respond with a friendly message.
160168
161169
![Weather with Bing](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/weather-with-bing.png?raw=true)
162170
163171
164-
<!-- ## Step 4️⃣: Agent playground to Code
172+
## Step 4️⃣: Agent playground to Code
165173
166-
The Agent Playground is a great way to test your agent's capabilities, but it's not the only way to interact with it. In this step, we will update our application to use the agent we just created. This will allow us to use the agent in our application and make it more useful.
174+
The Agent Playground is a great way to test your agent's capabilities, but it's not the only way to interact with it. In this step, you will update our application to use the agent you just created.
167175
168176
### Get Agent code
169177
Open the **Agent Playground** on the [AI Foundry portal](https://ai.azure.com/) and click on **View Code**. This will show you the code that is used to interact with the agent.
170178
171179
![View code](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/view-code.png?raw=true)
172180
173-
Switch to the **JavaScript** tab, copy and paste the code into a new file called `agent.js` in the `packages/webapi` directory of your project. The code will already have the necessary setup for the agent, and will retrieve and display the current thread.
181+
Switch to the **JavaScript** tab, copy and paste the code into a new file called `agent.js` in the `packages/webapi` directory of your project. The code will already have the necessary setup for the agent, including your hard-coded connection string and agent ID.
174182
175183
Run the code using `node agent.js` and you should see the output in the terminal.
176184
177-
To send a message to the agent, you can update the `client.agents.createMessage` method to include the message you want to send. For example, you can replace the content with "When is the current weather in Cairo?" and run the code again. You should see the agent's response in the terminal.
185+
To send a message to the agent, you can update the `client.agents.createMessage` method to include the message you want to send. For example, you can replace the content with "Give me a summary of this year's Keynote at Microsoft Build" and run the code again. You should see the agent's response in the terminal.
178186
179187
````javascript
180188
const message = await client.agents.createMessage(thread.id, {
181189
role: "user",
182-
content: "When is the current weather in Cairo?",
190+
content: "Give me a summary of this year's Keynote at Microsoft Build",
183191
});
184192
console.log(`Created message, message ID: ${message.id}`);
185193
````
@@ -211,7 +219,7 @@ export class AgentService {
211219
new DefaultAzureCredential()
212220
);
213221
214-
// The agent ID from your agent.yaml file
222+
// You can get the agent ID from your my-agent.agent.yaml file or the sample code
215223
this.agentId = "<YOUR_AGENT_ID>";
216224
}
217225
@@ -308,8 +316,12 @@ if (mode === "agent") {
308316
}
309317
```
310318

319+
Restart your server.
320+
311321
### Update Chat UI
312322

323+
_You'll first update the UI, then implement the logic later. So don't worry if the changes don't work immediately._
324+
313325
First, modify the ChatInterface class in `webapp/src/components/chat.js` Add a new property for mode (basic vs agent)
314326

315327
```javascript
@@ -325,13 +337,13 @@ this.chatMode = "basic"; // Set default mode to basic
325337
In the render method, between the `Clear Chat button` and the `RAG-toggle component`, add a model-selector component.
326338

327339
```javascript
328-
<div class="mode-selector">
329-
<label>Mode:</label>
330-
<select @change=${this._handleModeChange}>
331-
<option value="basic" ?selected=${this.chatMode === 'basic'}>Basic AI</option>
332-
<option value="agent" ?selected=${this.chatMode === 'agent'}>Agent</option>
333-
</select>
334-
</div>
340+
<div class="mode-selector">
341+
<label>Mode:</label>
342+
<select @change=${this._handleModeChange}>
343+
<option value="basic" ?selected=${this.chatMode === 'basic'}>Basic AI</option>
344+
<option value="agent" ?selected=${this.chatMode === 'agent'}>Agent</option>
345+
</select>
346+
</div>
335347
```
336348
337349
![Switch modes](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/switch-modes.png?raw=true)
@@ -340,34 +352,34 @@ Update the `RAG toggle` to be disabled when the mode is set to "agent".
340352
341353
342354
```javascript
343-
<label class="rag-toggle ${this.chatMode === 'agent' ? 'disabled' : ''}">
344-
<input type="checkbox"
345-
?checked=${this.ragEnabled}
346-
@change=${this._toggleRag}
347-
?disabled=${this.chatMode === 'agent'}>
348-
Use Employee Handbook
355+
<label class="rag-toggle ${this.chatMode === 'agent' ? 'disabled' : ''}">
356+
<input type="checkbox"
357+
?checked=${this.ragEnabled}
358+
@change=${this._toggleRag}
359+
?disabled=${this.chatMode === 'agent'}>
360+
Use Employee Handbook
349361
</label>
350362
```
351363
352364
![Disable RAG toggle in Agent mode](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/disable-rag-toggle.png?raw=true)
353365
354-
Let's make the placeholder text conditional based on the selected mode
366+
Let's make the placeholder text conditional based on the selected mode, by updating the _chat-input_ component in the render method:
355367
356368
```javascript
357-
<input
358-
type="text"
359-
placeholder=${this.chatMode === 'basic' ?
360-
"Ask about company policies, benefits, etc..." :
361-
"Ask Agent"}
362-
.value=${this.inputMessage}
363-
@input=${this._handleInput}
364-
@keyup=${this._handleKeyUp}
365-
/>
369+
<input
370+
type="text"
371+
placeholder=${this.chatMode === 'basic' ?
372+
"Ask about company policies, benefits, etc..." :
373+
"Ask Agent"}
374+
.value=${this.inputMessage}
375+
@input=${this._handleInput}
376+
@keyup=${this._handleKeyUp}
377+
/>
366378
```
367379
368380
![Agent mode placeholder text](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/ask-agent.png?raw=true)
369381
370-
and the message sender display to show 'Agent' instead of 'AI' when the mode is set to 'agent':
382+
and the message sender display to show **Agent** instead of **AI** when the mode is set to 'agent'. Update the _chat-message_ component
371383
372384
```javascript
373385
<span class="message-sender">${message.role === 'user' ? 'You' : (this.chatMode === 'agent' ? 'Agent' : 'AI')}</span>
@@ -463,24 +475,25 @@ On the app, select the **Agent** mode from the dropdown. Type a message in the i
463475
464476
If you ask the agent a question that requires real-time information, such as _"What's the current weather in Spain?"_, the agent should ground its response using the Bing Search API and provide you with the latest information.
465477
466-
![Weather in Spain in Agent mode](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/weather-in-spain.png?raw=true) -->
478+
![Weather in Spain in Agent mode](https://github.com/Azure-Samples/JS-AI-Build-a-thon/blob/assets/jsai-buildathon-assets/weather-in-spain.png?raw=true)
467479
468480
469-
## ✅ Activity: Push your updated code to the repository - TBD
481+
## ✅ Activity: Push your updated code to the repository
470482
471483
### Quest Checklist
472484
473485
To complete this quest and **AUTOMATICALLY UPDATE** your progress, you MUST push your code to the repository as described below.
474486
475487
**Checklist**
476488
477-
- [ ] Have a `agent` folder in the packages directory
489+
- [ ] Ensure your agent configuration file is added to `.gitignore` to prevent it from being committed. DON'T PUSH IT TO THE REPOSITORY.
490+
- [ ] Have an `agentService.js` file in the `packages/webapi` directory
478491
479492
1. In the terminal, run the following commands to add, commit, and push your changes to the repository:
480493
481494
```bash
482495
git add .
483-
git commit -m "Added agent"
496+
git commit -m "Added agent mode"
484497
git push
485498
```
486499
2. After pushing your changes, **WAIT ABOUT 15 SECONDS FOR GITHUB ACTIONS TO UPDATE YOUR README**.
@@ -494,6 +507,5 @@ To complete this quest and **AUTOMATICALLY UPDATE** your progress, you MUST push
494507
Here are some additional resources to help you learn more about building AI agents and extending their capabilities with tools:
495508
- [Azure AI Agents JavaScript examples](https://github.com/Azure-Samples/azure-ai-agents-javascript)
496509
- [Your First AI Agent in JS with Azure AI Agent Service](https://www.youtube.com/live/RNphlRKvmJQ?si=I3rUp-LmnvS008ym)
497-
- [Build Apps and Agents with Visual Studio Code and Azure blog](https://devblogs.microsoft.com/blog/build-apps-and-agents-with-visual-studio-code-and-azure)
498-
- [📹 DEMFP781: From Prompt to Product: Build an AI Agent That Generates UI](https://build.microsoft.com/en-US/sessions/DEMFP781?source=sessions)
499-
- [Build with the AI Foundry JavaScript SDK](https://learn.microsoft.com/en-us/azure/ai-foundry/how-to/develop/sdk-overview?pivots=programming-language-javascript)
510+
- [Create a new Agent - JS/TS](https://learn.microsoft.com/en-us/azure/ai-services/agents/quickstart?pivots=programming-language-javascript)
511+
- [📹 DEMFP781: From Prompt to Product: Build an AI Agent That Generates UI](https://build.microsoft.com/en-US/sessions/DEMFP781?source=sessions)

.github/workflows/6-build-agent.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
paths:
7-
- "packages/**"
7+
- "packages/webapi/agentService.js"
88
branches:
99
- main
1010

@@ -25,7 +25,7 @@ jobs:
2525
current_step: ${{ steps.get_step.outputs.current_step }}
2626

2727
on_agent_directory:
28-
name: On addition of agent directory
28+
name: On addition of an agentService module
2929
needs: get_current_step
3030

3131
if: >-
@@ -41,10 +41,10 @@ jobs:
4141
with:
4242
fetch-depth: 0 # Let's get all the branches
4343

44-
- name: Check agent directory exists
44+
- name: Check agentService.js file exists
4545
id: check_agent
4646
run: |
47-
if [ -d "packages/agent" ]; then
47+
if [ -f "packages/webapi/agentService.js" ]; then
4848
echo "agent_exists=true" >> $GITHUB_OUTPUT
4949
else
5050
echo "agent_exists=false" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)