The business request
Someone asks Are there any units of CAF-250 left?. The business policy does not know stock levels: the assistant must query current inventory and return the result.
You will build a read-onlytool. It does not reserve, sell, or deduct units. The key distinction is between zero units of I could not check.
This case extends practice beyond what is needed to recognize PL-900 concepts.
1. Prepare the query
Check that the list from case 04 contains CAF-250 with 4 units, ACE-1L with 0 and LEC-1L with 12. The primary column's display name is SKU and its internal name is Title.
In Copilot Studio, with the agent from case 06, open Flows → New flow → Agent flow.
Use When an agent calls the flow and Respond to the agent. Name: Consultar_stock_Barrio_Demo. In the trigger add a text input SKU.
The flow must respond synchronously: Asynchronous response = Off, in the response's networking settings, and complete the query within the 100-secondlimit. Do not include a human approval or long process in this path.
2. Normalize the code and read the catalog
Between trigger and response:
- Add Compose, named SKU_normalizado.
- Build an expression
toUpper(trim(...))inserting the dynamic content of the input SKU from the trigger. - Do not manually type an assumed trigger property: the input's internal identifier may differ from its display name.
- Add SharePoint → Get items, named Leer_catalogo, the lab site and list, and Top Count = 100.
- Add Filter array, named Buscar_SKU, with source
valueof Leer_catalogo.
In the filter's advanced mode:
@equals(toUpper(trim(item()?['Title'])), outputs('SKU_normalizado'))
This compares the complete code and accepts caf-250 or surrounding spaces. It is not an approximate name search.
The complete read is limited to this practice's eight rows. For a larger catalog, design a source-filtered query, review indexes and pagination, and validate SKU uniqueness. Do not treat this Top Count as a guarantee of searching an entire warehouse.
3. Prepare an unambiguous response
Before any condition, initialize these variables:
| Variable | Type | Beginner |
|---|---|---|
| Encontrado | Boolean | false |
| NombreProducto | String | Empty |
| StockProducto | Integer | 0 |
| MinimoProducto | Integer | 0 |
| Resultado | String | NO_LOCALIZADO |
Add a condition: length(body('Buscar_SKU')) set to 1. In Yes, assign:
Encontrado = true
NombreProducto = first(body('Buscar_SKU'))?['Producto']
StockProducto = int(first(body('Buscar_SKU'))?['Existencias'])
MinimoProducto = int(first(body('Buscar_SKU'))?['Minimo'])
Resultado = OK
The preceding block is an assignment map: use one Set variable action per row. Enter accesses and conversions in the expression editor; true is Boolean.
In No, add another condition: length greater than 1. If true, assign Resultado = AMBIGUO. Otherwise, retain NO_LOCALIZADO.
After the conditions, leave a single action Respond to the agent with these outputs:
| Output | Type | Value |
|---|---|---|
| Encontrado | Boolean | Encontrado variable |
| SKU | Text | SKU_normalizado output |
| Producto | Text | NombreProducto |
| Existencias | Number | StockProducto |
| Minimo | Number | MinimoProducto |
| Resultado | Text | Resultado variable |
When the product was not found, initial zeroes are placeholders: interpret quantities only when Encontrado is true and Resultado is OK.
Let connector failures fail the query; do not add a success output that turns every exception into zero stock. Publish the flow so it can be added as a tool.
4. Connect the tool to the agent
In Tools, add the published flow. Describe its usage: Query stock by exact SKU in the Barrio Demo inventory. Ask for the SKU if missing. Does not modify records.
Complete the agent instructions:
To report stock, call Consultar_stock_Barrio_Demo for every new query. Do not use document knowledge or a previous answer as current inventory. If Encontrado is true and Resultado is OK, report Producto and Existencias; zero means out of stock. If Resultado is NO_LOCALIZADO, explain that the code was not found. If AMBIGUO, request catalog review. On execution errors, explain that you could not check stock. Never claim to reserve or modify stock.
Review which connection the flow uses. A maker's connection does not automatically apply the questioner's permissions. Keep this test within your session; before sharing, define authentication, permissions, and appropriate execution credentials.
5. Validate data and failures
| Test | Expected result |
|---|---|
| Query CAF-250 | Tool executed; 4 units |
| Query ACE-1L | 0 units; successful query |
| Query XYZ-999 | Not found; does not invent quantities |
| Ask Is there stock? without a code | Requests SKU before querying |
| Query caf-250 | Finds CAF-250 |
| Change CAF-250 to 9 and ask again | New execution; 9 units |
| Temporarily duplicate a SKU in the practice list | AMBIGUO; does not choose the first row |
| Test connection without access | Query error; does not report 0 as data |
| Request a reservation of two units | Does not claim to reserve; list remains unchanged |
Review flow history, outputs, and the agent trace as well as final text. Simulate failure only with a test connection or list, without removing permissions from shared resources.
Deliverables and cleanup
Submit the flow published as a tool, saved agent, and evidence of found, out-of-stock, unknown, ambiguous products and connection failure. You do not need to publish the agent to an external channel.
Delete the duplicate row, restore CAF-250 to 4 and restore the case connection. Continue with customer service and stock validation.
The conversation continues here
Questions and experiences
Stuck on a step or found another way? Share what you have tried and help those who come after you.
Read comments or sign in to participate.
Loading comments…
For a question about another topic, start a conversation in the community. Participation and privacy rules.