Task 03: Build the Agentic App
Introduction
Metropolis now moves beyond smart queries to a smart assistant. In this task, you’ll assemble an agentic app that reasons over the city’s legal-case database, uses semantic and graph signals to rank results, and even pulls in real-world weather evidence when relevant. The result is a guided, explainable workflow that helps staff answer complex questions faster and with better grounding.
Description
You’ll work in a Jupyter notebook to wire up a Semantic Kernel agent that can call purpose-built plugins, test its functionality, get weather data, and setup semantic memory.
Success criteria
- You ran the notebook and configured environment variables for Azure OpenAI and PostgreSQL.
- You created and registered the DatabaseSearchPlugin, SemanticRerankingPlugin, GraphDatabasePlugin, and WeatherPlugin.
- The agent answered a natural question, invoked the right functions (visible via printed logs), and returned grounded results.
- You demonstrated semantic + graph ranking (10 relevant cases returned) and retrieved historical rainfall for a specified date/location.
- You enabled semantic memory and verified prior prompts were recalled and used to improve a later response.
Learning resources
Key steps
01: Use the Python Jupyter Notebook
You’re going to take everything you’ve learned so far to build an Agentic App.
-
On the VM’s taskbar, open Visual Studio Code.
-
On the top menu bar, select File > Open Folder.
-
Go to
C:\LabFiles, select pg-sk-agents-lab, then select Select Folder.
-
In the EXPLORER pane, expand Code, then select lab.ipynb.

For the remainder of the lab, you’ll primarily work in this Python Jupyter Notebook.
Refer back to these instructions for 02: and 03:.
02: Environment Setup
-
In the EXPLORER pane, right-click any open space below the project files, then select New File.
-
Enter
.envfor the file name. -
In the new .env file, enter the following, which contains your previously used Endpoint, Key, and credential:
# Azure OpenAI Configuration AZURE_OPENAI_ENDPOINT=@lab.Variable(ENDPOINT) AZURE_OPENAI_KEY=@lab.Variable(API_KEY) AZURE_OPENAI_DEPLOYMENT=gpt-4o # Database Configuration AZURE_PG_HOST=@lab.Variable(PGHOST) AZURE_PG_NAME=cases AZURE_PG_USER=pgAdmin AZURE_PG_PASSWORD=passw0rd AZURE_PG_PORT=5432 AZURE_PG_SSLMODE=require
-
On the top menu bar, select File > Save.
-
Go back to the lab.ipynb notebook to run the code block.
03: Code Review Tasks
Before running the code block in the Jupyter Notebook, you’ll need to run a SQL script on the database.
-
In VS Code’s EXPLORER pane, expand Scripts, then select create_graph.sql.
-
On the top menu bar, select View > Command Palette.
-
Enter
PGSQL Connect, then select PGSQL: Connect. -
Select Create Connection Profile.
-
Enter the following details:
Item Value SERVER NAME @lab.Variable(PGHOST)AUTHENTICATION TYPE Password USER NAME pgAdminPASSWORD passw0rdDATABASE NAME cases -
Select Save & Connect.

-
In the upper-right corner of the create_graph.sql editor pane, select Execute PostgreSQL Query (the 2nd
).
-
In the connection profile dropdown menu, select your newly created connection.

This will build the graph database via the Apache AGE extension in your Azure PostgreSQL database using the loaded 377 legal cases.
-
On the top menu bar, select Terminal > New Terminal.
Since you’re using the Apache AGE PostgreSQL extension to provide Graph database capabilities, you’ll need to enable the extension on the database.
-
Enter the following to sign in to Azure CLI:
az login -
Select your lab credentials, then go back to the VS Code terminal.
-
Run the following PowerShell script:
.\Scripts\load_age.ps1This script runs three main commands and may take a few minutes to complete.

-
Once finished, go back to the lab.ipynb notebook to proceed with Part 3.7’s Review the code step.
-
After you’ve completed the notebook, proceed.
Conclusion
Congratulations on completing the lab!
Select Submit for completion.
Next Steps
We’ve curated additional resources to enhance your ongoing journey in building AI agents and AI-powered applications with Azure Database for PostgreSQL.
- A more detailed blog post about the legal case example of lab in the GraphRAG Solution for Azure Database for PostgreSQL check the code in the GitHub repository.
- Learn more about Graph data in Azure Database for PostgreSQL.
- Get familiar with the new PostgreSQL extension for Visual Studio Code.
- Learn more about Semantic Ranking with the Semantic Ranker Solution Accelerator and its associated GitHub repository.
- Finally, our more recent solutions accelerator Build your own advanced AI Copilot with Postgres teaches you how to extract data from statements of work (SOWs) and invoices in PDF files and use AI to validate them, more details in the GitHub repo.