Create a Python Tool
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
- Go to sre.azure.com and select your agent
- Click Builder in the left navigation
- Expand Builder and click Agent Canvas
- Click Create → Tool → Python tool
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.
- 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"
}
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.
- Click the Test playground tab
- Enter test values:
total_uptime_minutes: 43185total_downtime_minutes: 15target_sla_percent: 99.9
- Click Test
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
- On the Agent Canvas, click the tool node to open the info panel
- Click the edit (pencil) icon in the panel header
- The edit dialog opens — modify the description, code, or parameters
- Click Save
Delete
- Click the tool node to open the info panel
- Click the ⋯ (more actions) menu in the panel header
- Select Delete tool
- 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
| Issue | Solution |
|---|---|
| Test button is disabled | Ensure valid Python code with a main() function and all parameter fields filled in |
| Code doesn't match your intent | Refine the description and click Generate again — be specific about parameter names, calculation logic, and output format |
| Test returns an error | Check the error message — common issues are division by zero, wrong parameter types, or unavailable imports |
Related
| Resource | What you'll learn |
|---|---|
| Python Tools capability | Full reference for Python tools |
| Create a Kusto Tool | Query Azure Data Explorer |
| Tools overview | All tool types available |