Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fe72933
Revise Azure deployment workflow with validations
v-vfarias Nov 3, 2025
75288ba
Change resource type from AI Foundry to Cognitive Services
v-vfarias Nov 3, 2025
703480b
Update Azure resource type to Microsoft.AI/Foundry
v-vfarias Nov 3, 2025
46d9266
Change Azure AI Foundry resource creation method
v-vfarias Nov 3, 2025
3b7c02f
Refactor deployment workflow for GPT-4o model
v-vfarias Nov 3, 2025
41e43fe
Merge branch 'MicrosoftLearning:main' into main
v-vfarias Jan 21, 2026
0242c0a
Merge branch 'MicrosoftLearning:main' into main
v-vfarias Jan 21, 2026
394d1e7
Update to a supported model
v-vfarias Feb 9, 2026
b63469d
Refactor .env loading logic and improve error handling
v-vfarias Feb 12, 2026
b61e3f6
Refactor .env loading logic and improve error handling
v-vfarias Feb 12, 2026
90ac6de
Fix deployment location string for AI model in Bicep file
v-vfarias Feb 13, 2026
a67bc74
Add interactive test script for Trail Guide Agent
v-vfarias Feb 16, 2026
ab84c46
Updated path finder
v-vfarias Feb 16, 2026
88810da
Merge branch 'main' of https://github.com/v-vfarias/mslearn-genaiops
v-vfarias Feb 16, 2026
79fa0aa
Enhance agent ID resolution logic and improve error handling in inter…
v-vfarias Feb 16, 2026
4bbce1d
Merge branch 'main' of https://github.com/v-vfarias/mslearn-genaiops
v-vfarias Feb 16, 2026
b9727ad
Update requirements.txt to pin package versions for stability
v-vfarias Feb 16, 2026
840aa11
Update requirements.txt for minimum version constraints
v-vfarias Feb 16, 2026
a27dfa2
Refactor interactive test script for Trail Guide Agent: update agent …
v-vfarias Feb 16, 2026
b2eff8f
Merge branch 'main' of https://github.com/v-vfarias/mslearn-genaiops
v-vfarias Feb 16, 2026
45cd0d0
Update requirements.txt for Azure AI Projects SDK version and refacto…
victorbarretofarias Feb 16, 2026
d6c3b5e
Update requirements.txt for Azure AI Projects SDK version and refacto…
victorbarretofarias Feb 16, 2026
5561ebe
Refactor main.bicep: remove AI project module and associated outputs …
victorbarretofarias Feb 16, 2026
94d3022
Add AI Project module and OpenAI connection resource for enhanced dep…
victorbarretofarias Feb 16, 2026
3f87f26
Add OpenAI connection resource to ensure automatic wiring to Inferenc…
victorbarretofarias Feb 16, 2026
da2faa3
Refactor interact_with_agent: simplify OpenAI client connection by re…
victorbarretofarias Feb 16, 2026
58821f2
Refactor Bicep parameters and outputs for AI project
v-vfarias Feb 16, 2026
42ce1f7
Enhance agent interaction with connection checks
v-vfarias Feb 16, 2026
1fb8af2
Refactor interact_with_agent to simple_chat
v-vfarias Feb 16, 2026
7eac261
Refactor interact_with_agent function to improve chat session handlin…
v-vfarias Feb 16, 2026
4967a63
Refactor interact_with_agent to use AgentsClient for improved agent i…
v-vfarias Feb 16, 2026
ca29baa
Refactor interact_with_agent to use AIProjectClient for improved agen…
v-vfarias Feb 18, 2026
ace283e
Refactor interact_with_agent to utilize OpenAI client for conversatio…
v-vfarias Feb 18, 2026
b017024
Refactor interact_with_agent to enhance conversation handling and res…
v-vfarias Feb 18, 2026
75f230e
Update aiProjectDeploymentsJson to include gpt4o-mini-deploy model co…
v-vfarias Feb 18, 2026
4fff3aa
Update AI deployments to use gpt-4.1 model configuration
v-vfarias Feb 18, 2026
f2f214e
Enhance AI deployment configuration with model format and SKU capacity
v-vfarias Feb 18, 2026
eb01fe3
Update AI deployment configuration to use gpt4o-mini model and adjust…
v-vfarias Feb 18, 2026
ebb6d7b
Update AI deployment configuration to use gpt-4.1 model and adjust de…
v-vfarias Feb 20, 2026
c33fdf0
Remove aiProjectDeploymentsJson parameter from main.parameters.json
v-vfarias Feb 20, 2026
441b1da
Update AI deployment configurations for gpt-4.1 model and adjust depl…
v-vfarias Feb 20, 2026
ac90074
Delete .github/workflows/setup-and-deploy.yml
v-vfarias Feb 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions docs/01-infrastructure-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ You'll use the Azure Developer CLI to deploy all required Azure resources using

Sign in with your Azure credentials when prompted. This authentication is needed for the Python SDK and other Azure operations in subsequent labs.

> ⚠️ **Important **
> In some environments, the VS Code integrated terminal may crash or close during the interactive login flow.
> If this happens, authenticate using explicit credentials instead:
> ```powershell
> az login --username <your-username> --password <your-password>
> ```

1. Provision resources:

```powershell
Expand Down Expand Up @@ -96,6 +103,16 @@ You'll use the Azure Developer CLI to deploy all required Azure resources using
```powershell
azd env get-values > .env
```

> ⚠️ **Important – File Encoding**
>
> After generating the `.env` file, make sure it is saved using **UTF-8** encoding.
>
> In editors like **VS Code**, check the encoding indicator in the bottom-right corner.
> If it shows **UTF-16 LE** (or any encoding other than UTF-8), click it, choose **Save with Encoding**, and select **UTF-8**.
>
> Using the wrong encoding may cause environment variables to be read incorrectly


This creates a `.env` file in your project root with all the provisioned resource information:
- Resource names and IDs
Expand Down Expand Up @@ -182,15 +199,17 @@ Interact with your deployed agent from the terminal to verify it's working corre
1. When prompted, ask the agent a question about hiking, for example:

```
You: I want to go hiking this weekend near Seattle. Any suggestions?
I want to go hiking this weekend near Seattle. Any suggestions?
```

1. The agent will respond with trail recommendations. Continue the conversation or type `exit` to quit.

```
Agent: I'd recommend checking out Rattlesnake Ledge Trail...

You: exit
```

```
exit
```

## Verify your deployment
Expand Down
29 changes: 14 additions & 15 deletions infra/core/ai/ai-project.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ resource aiAccount 'Microsoft.CognitiveServices/accounts@2025-06-01' = {

@batchSize(1)
resource seqDeployments 'deployments' = [
for dep in (deployments??[]): {
for dep in (deployments ?? []): {
name: dep.name
sku: dep.sku
properties: {
model: dep.model
}
sku: dep.sku
}
]

Expand Down Expand Up @@ -314,28 +314,27 @@ output dependentResources object = {
}
}

// Add simple confirmation outputs (so main.bicep can surface them)
output openAiDeploymentNames array = [for dep in (deployments ?? []): dep.name]

// Replace the deploymentsType definition with a concrete schema
type deploymentsType = {
@description('Specify the name of cognitive service account deployment.')
@description('Deployment name')
name: string

@description('Required. Properties of Cognitive Services account deployment model.')
@description('Model definition for the deployment')
model: {
@description('Required. The name of Cognitive Services account deployment model.')
name: string

@description('Required. The format of Cognitive Services account deployment model.')
@description('Model format, e.g. OpenAI')
format: string

@description('Required. The version of Cognitive Services account deployment model.')
version: string
@description('Model name, e.g. gpt-4.1')
name: string
@description('Optional model version')
version: string?
}

@description('The resource model definition representing SKU.')
@description('SKU for the deployment')
sku: {
@description('Required. The name of the resource model definition representing SKU.')
name: string

@description('The capacity of the resource model definition representing SKU.')
capacity: int
}
}[]?
Expand Down
30 changes: 29 additions & 1 deletion infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,33 @@ param aiFoundryResourceName string = ''
param aiFoundryProjectName string = 'ai-project-${environmentName}'

@description('List of model deployments')
param aiProjectDeploymentsJson string = '[]'
param aiProjectDeploymentsJson string = '''
[
{
"name": "gpt-4.1-mini",
"model": {
"format": "OpenAI",
"name": "gpt-4.1-mini"
},
"sku": {
"name": "GlobalStandard",
"capacity": 10
}
},
{
"name": "gpt-4.1",
"model": {
"format": "OpenAI",
"name": "gpt-4.1"
},
"sku": {
"name": "GlobalStandard",
"capacity": 10
}
}

]
'''

@description('List of connections')
param aiProjectConnectionsJson string = '[]'
Expand Down Expand Up @@ -166,3 +192,5 @@ output AZURE_AI_SEARCH_SERVICE_NAME string = aiProject.outputs.dependentResource
output AZURE_STORAGE_CONNECTION_NAME string = aiProject.outputs.dependentResources.storage.connectionName
output AZURE_STORAGE_ACCOUNT_NAME string = aiProject.outputs.dependentResources.storage.accountName

// OpenAI Deployments
output AZURE_OPENAI_DEPLOYMENT_NAMES array = aiProject.outputs.openAiDeploymentNames
3 changes: 0 additions & 3 deletions infra/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
"principalType": {
"value": "${AZURE_PRINCIPAL_TYPE}"
},
"aiProjectDeploymentsJson": {
"value": "${AI_PROJECT_DEPLOYMENTS=[]}"
},
"aiProjectConnectionsJson": {
"value": "${AI_PROJECT_CONNECTIONS=[]}"
},
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ markdown>=3.5.0
Jinja2>=3.1.0

# GitHub Actions and automation
pyyaml>=6.0.0

pyyaml>=6.0.0
2 changes: 1 addition & 1 deletion src/agents/trail_guide_agent/trail_guide_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from azure.ai.projects.models import PromptAgentDefinition

# Load environment variables from repository root
repo_root = Path(__file__).parent.parent.parent
repo_root = Path(__file__).parent.parent.parent.parent
env_file = repo_root / '.env'
load_dotenv(env_file)

Expand Down
46 changes: 23 additions & 23 deletions src/tests/interact_with_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def interact_with_agent():

# Get agent name from environment or use default
agent_name = os.getenv("AGENT_NAME", "trail-guide-v1")

openai_client = project_client.get_openai_client()

print(f"\n{'='*60}")
print(f"Trail Guide Agent - Interactive Chat")
Expand All @@ -33,8 +35,8 @@ def interact_with_agent():
print("\nType your questions or requests. Type 'exit' or 'quit' to end the session.\n")

# Create a thread for the conversation
thread = project_client.agents.create_thread()
print(f"Started conversation (Thread ID: {thread.id})\n")
conversation = openai_client.conversations.create()
print(f"Started conversation (Conversation ID: {conversation.id})\n")

try:
while True:
Expand All @@ -48,27 +50,25 @@ def interact_with_agent():
print("\nEnding session. Goodbye!")
break

# Send message to agent
project_client.agents.create_message(
thread_id=thread.id,
role="user",
content=user_input
# 1) Add the user message to the conversation as an item
openai_client.conversations.items.create(
conversation_id=conversation.id,
items=[{
"type": "message",
"role": "user",
"content": user_input
}]
)

# Run the agent
run = project_client.agents.create_and_process_run(
thread_id=thread.id,
agent_name=agent_name

# 2) Ask the agent to respond
response = openai_client.responses.create(
# NOTE: the sample uses `conversation=...` (not conversation_id)
conversation=conversation.id,
extra_body={"agent": {"name": agent_name, "type": "agent_reference"}},
input="", # sample keeps this empty because the message is already in the conversation items
)

# Get the assistant's response
messages = project_client.agents.list_messages(thread_id=thread.id)

# Find the latest assistant message
for message in messages:
if message.role == "assistant":
print(f"\nAgent: {message.content[0].text.value}\n")
break

print(f"Agent: {response.output_text}")

except KeyboardInterrupt:
print("\n\nSession interrupted. Goodbye!")
Expand All @@ -78,10 +78,10 @@ def interact_with_agent():
finally:
# Clean up thread
try:
project_client.agents.delete_thread(thread.id)
openai_client.conversations.delete(conversation.id)
print(f"Conversation thread cleaned up.")
except:
pass

if __name__ == "__main__":
interact_with_agent()
interact_with_agent()
Loading