Skip to main content

Create a Python Tool

What you'll build

An SLA compliance calculator tool — describe what you need, generate code with AI, test it, and deploy. Learn more → Python Tools. Time: ~10 minutes.

Prerequisites

  • Access to an SRE Agent with Builder permissions

Step 1: Open the Python tool dialog

  1. Go to sre.azure.com and select your agent
  2. Click Builder in the left navigation
  3. Expand Builder and click Agent Canvas
  4. Click CreateToolPython tool
Create menu showing Tool and Python tool options

The Python tool dialog opens with three tabs: Code, Test playground, and Identity.


Step 2: Describe what the tool should do

In the description field, write what you want the tool to do in plain English. Be specific about inputs, outputs, and logic.

Enter this description:

Calculate SLA compliance percentage from total uptime minutes and downtime 
minutes. Return whether the SLA meets a target threshold (default 99.9%).
Include the calculated percentage and a status message.
Python tool dialog with description entered
Writing good descriptions
  • Specify input parameters and their types
  • Describe the calculation or logic
  • State what the output should include
  • Mention default values if applicable

Step 3: Generate the code

Click Generate.

The AI analyzes your description and creates a Python function with:

  • Typed parameters matching your inputs
  • Docstring explaining the logic
  • Error handling for edge cases
  • JSON-serializable return value

Generated code:

def main(total_uptime_minutes: int, total_downtime_minutes: int, 
target_sla_percent: float = 99.9) -> dict:
"""Calculate SLA compliance from uptime and downtime minutes.

Computes SLA as (uptime / (uptime + downtime)) * 100.
Returns the SLA percentage, whether it meets the target,
and a status message.
"""
total_minutes = total_uptime_minutes + total_downtime_minutes

if total_minutes == 0:
sla_percent = 100.0
else:
sla_percent = (total_uptime_minutes / total_minutes) * 100

meets_target = sla_percent >= target_sla_percent

return {
"sla_percent": round(sla_percent, 4),
"target_sla_percent": target_sla_percent,
"meets_target": meets_target,
"status": "Meets SLA" if meets_target else "Below SLA"
}
Code tab showing generated Python function

Checkpoint: The Code tab shows a main() function with typed parameters. The tool name is auto-generated from your description.


Step 4: Test with real inputs

Before creating the tool, test it with actual values.

  1. Click the Test playground tab
  2. Enter test values:
    • total_uptime_minutes: 43185
    • total_downtime_minutes: 15
    • target_sla_percent: 99.9
  3. Click Test
Test playground showing successful execution

Expected result:

{
"sla_percent": 99.9653,
"target_sla_percent": 99.9,
"meets_target": true,
"status": "Meets SLA"
}

Checkpoint: The test shows a green success indicator and the JSON output matches expected values.


Step 5: Create the tool

Once testing passes, click Create tool.

Your tool is now available. The agent can call it automatically when a task matches the tool's description.


Try it out

In a new chat thread, ask your agent:

What's my SLA for last month? We had 43185 minutes of uptime and 15 minutes of downtime.

The agent recognizes this matches your tool and calls it to calculate the result.


Edit or delete a tool

Edit

  1. On the Agent Canvas, click the tool node to open the info panel
  2. Click the edit (pencil) icon in the panel header
  3. The edit dialog opens — modify the description, code, or parameters
  4. Click Save

Delete

  1. Click the tool node to open the info panel
  2. Click the (more actions) menu in the panel header
  3. Select Delete tool
  4. Confirm the deletion in the dialog

What you learned

  • How to describe tool functionality in plain English
  • How to generate Python code using AI
  • How to test with real inputs before deploying
  • How to save the tool for your agent to use

Troubleshooting

IssueSolution
Test button is disabledEnsure valid Python code with a main() function and all parameter fields filled in
Code doesn't match your intentRefine the description and click Generate again — be specific about parameter names, calculation logic, and output format
Test returns an errorCheck the error message — common issues are division by zero, wrong parameter types, or unavailable imports
ResourceWhat you'll learn
Python Tools capabilityFull reference for Python tools
Create a Kusto ToolQuery Azure Data Explorer
Tools overviewAll tool types available
Was this page helpful?