Skip to main content

Azure AI Foundry dev workflow helpers

Project description

Azure AI Foundry Workflow Helpers

Utilities for exporting (downloading) and importing (creating/updating) Azure AI Foundry Agents along with dependency awareness, normalization, and consistent logging.

๐Ÿš€ Quick Start

1. Set Environment Variables

export AZURE_TENANT_ID='your-tenant-id-here'
export PROJECT_ENDPOINT='your-ai-foundry-endpoint-here'

Example:

export AZURE_TENANT_ID='aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
export PROJECT_ENDPOINT='https://your-resource.services.ai.azure.com/api/projects/your-project'

Note: You can also provide these values via CLI parameters (--azure-tenant-id and --project-endpoint) which will take precedence over environment variables.

2. Install the Package

For development (editable install):

pip install -e .

Or for production:

pip install .

This will install all required dependencies automatically.

3. Using the CLI (Recommended)

The CLI is available as a console script after installation.

aif-workflow-helper --download-all-agents --agents-dir agents

Common examples:

# Download all agents with optional prefix/suffix filtering
aif-workflow-helper --download-all-agents --prefix dev- --suffix -v1

# Download a single agent
aif-workflow-helper --download-agent my_agent

# Upload all agents from JSON definitions in a directory
aif-workflow-helper --upload-all-agents --agents-dir agents

# Upload a single agent definition file
aif-workflow-helper --upload-agent my_agent --agents-dir agents

# Get the agent ID for a specific agent by name
aif-workflow-helper --get-agent-id my_agent

# Download agents in different formats
aif-workflow-helper --download-all-agents --format json     # Default
aif-workflow-helper --download-all-agents --format yaml     # YAML format
aif-workflow-helper --download-all-agents --format md       # Markdown with frontmatter

# Upload agents from different formats
aif-workflow-helper --upload-all-agents --format yaml
aif-workflow-helper --upload-agent my_agent --format md

# Change log level
aif-workflow-helper --download-all-agents --log-level DEBUG

# Override environment variables with CLI parameters
aif-workflow-helper --download-all-agents \
  --azure-tenant-id "your-tenant-id" \
  --project-endpoint "https://your-endpoint.services.ai.azure.com/api/projects/your-project"

# Mix CLI parameters with environment variables (CLI takes precedence)
export AZURE_TENANT_ID="env-tenant-id"
aif-workflow-helper --download-all-agents --azure-tenant-id "cli-tenant-id"  # Uses CLI value

# Get agent ID and use in scripts
AGENT_ID=$(aif-workflow-helper --get-agent-id my_agent)
echo "Agent ID: $AGENT_ID"

4. Direct Library Usage

You can import and compose the underlying functions directly:

from aif_workflow_helper import (
    configure_logging,
    download_agents,
    download_agent,
    create_or_update_agents,
    create_or_update_agent,
    create_or_update_agent_from_file,
    create_or_update_agents_from_files,
)
from azure.ai.agents import AgentsClient
from azure.identity import DefaultAzureCredential

configure_logging()

client = AgentsClient(
    credential=DefaultAzureCredential(
        exclude_interactive_browser_credential=False,
        interactive_tenant_id="your-tenant-id"
    ),
    endpoint="your-endpoint"
)

# Bulk download
download_agents(client, file_path="./agents", prefix="", suffix="", format="json")

# Create/update from a directory (dependency ordered)
create_or_update_agents_from_files(path="./agents", agent_client=client, prefix="", suffix="", format="json")

๐Ÿ“ What the Tooling Does

  1. Downloads existing agents to normalized files (JSON, YAML, or Markdown with frontmatter)
  2. Normalizes (generalizes) definitions for portability (removes resource-specific fields)
  3. Infers and resolves inter-agent dependencies (connected agent tools)
  4. Creates or updates agents in dependency-safe order
  5. Applies optional prefix/suffix for environment namespacing
  6. Supports multiple file formats for flexible workflow integration

๐Ÿ”ง Core Functions

Download Functions

  • download_agents(agent_client, file_path, prefix, suffix, format) โ€“ Download and generalize all agents (optional prefix/suffix filters, format selection)
  • download_agent(agent_name, agent_client, file_path, prefix, suffix, format) โ€“ Download and generalize a single agent
  • generalize_agent_dict(data, agent_client, prefix, suffix) โ€“ Normalize agent JSON for portability

Upload Functions

  • create_or_update_agent(agent_data, agent_client, existing_agents, prefix, suffix) โ€“ Upsert a single agent object
  • create_or_update_agents(agents_data, agent_client, prefix, suffix) โ€“ Upsert multiple agents with dependency ordering
  • create_or_update_agent_from_file(agent_name, path, agent_client, prefix, suffix, format) โ€“ Upsert from a specific file
  • create_or_update_agents_from_files(path, agent_client, prefix, suffix, format) โ€“ Bulk load and upsert directory

Internal Helpers (Not all re-exported)

  • read_agent_file(path) / read_agent_files(path, format) โ€“ Load definitions in any supported format (used internally by from_files wrappers)
  • extract_dependencies(agents_data) โ€“ Build dependency graph
  • dependency_sort(agents_data) โ€“ Topological sort of agents
  • get_agent_by_name(name, client) โ€“ Lookup agent object
  • get_agent_name(agent_id, client) โ€“ Reverse lookup by ID

๐ŸŽฏ CLI Reference

aif-workflow-helper arguments:

--agents-dir DIR                Directory for agent definition files (default: agents)
--download-all-agents           Download all existing agents
--download-agent NAME           Download a single agent by name
--upload-all-agents             Create/update all agents from definition files
--upload-agent NAME             Create/update a single agent from definition file
--get-agent-id NAME             Get the agent ID for a given agent name
--prefix TEXT                   Optional prefix applied during download/upload
--suffix TEXT                   Optional suffix applied during download/upload
--format FORMAT                 File format: json, yaml, or md (default: json)
--log-level LEVEL               Logging level (CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET)
--azure-tenant-id TENANT_ID     Azure tenant ID (overrides AZURE_TENANT_ID environment variable)
--project-endpoint ENDPOINT     AI Foundry project endpoint URL (overrides PROJECT_ENDPOINT environment variable)

Authentication Priority

  1. CLI Parameters (highest priority): --azure-tenant-id and --project-endpoint
  2. Environment Variables (fallback): AZURE_TENANT_ID and PROJECT_ENDPOINT

๏ฟฝ Agent Lookup

Get Agent ID by Name

The --get-agent-id option allows you to retrieve the unique ID of an agent by its name. This is useful for scripting and automation scenarios where you need to reference an agent by its ID rather than its name.

Usage:

# Get agent ID
aif-workflow-helper --get-agent-id my-agent

# Use in a script
AGENT_ID=$(aif-workflow-helper --get-agent-id my-agent)
echo "Agent ID: $AGENT_ID"

# With explicit authentication
aif-workflow-helper --get-agent-id my-agent \
  --azure-tenant-id "your-tenant-id" \
  --project-endpoint "your-endpoint"

Output:

  • On success: Prints the agent ID to stdout (suitable for capturing in scripts)
  • On failure: Logs an error message and exits with code 1

Example Output:

========== Looking up agent: my-agent ==========
asst_abc123xyz456
========== Agent 'my-agent' has ID: asst_abc123xyz456 ==========

๏ฟฝ๐Ÿ“„ Supported File Formats

The tool supports three file formats for agent definitions:

JSON Format (Default)

Standard JSON format with all agent properties in a single object:

{
  "name": "my-agent",
  "model": "gpt-4",
  "instructions": "You are a helpful AI assistant...",
  "tools": [],
  "temperature": 0.7,
  "top_p": 1.0
}

YAML Format

Clean YAML format for better readability:

name: my-agent
model: gpt-4
instructions: |
  You are a helpful AI assistant.
  Please provide clear and concise responses.
tools: []
temperature: 0.7
top_p: 1.0

Markdown with Frontmatter

Markdown format where the instructions field becomes the content and all other properties go into YAML frontmatter:

---
name: my-agent
model: gpt-4
tools: []
temperature: 0.7
top_p: 1.0
---
You are a helpful AI assistant.

Please provide clear and concise responses to user questions.

File Extensions:

  • JSON: .json
  • YAML: .yaml or .yml
  • Markdown: .md

๐Ÿ“‹ File Structure

โ”œโ”€โ”€ pyproject.toml               # Package configuration and dependencies
โ”œโ”€โ”€ requirements.txt             # Core runtime dependencies
โ”œโ”€โ”€ README.md                    # Project documentation
โ”œโ”€โ”€ agents/                      # Agent definition files
โ”œโ”€โ”€ tests/                       # Test files
โ””โ”€โ”€ src/aif_workflow_helper/     # Main package source code
    โ”œโ”€โ”€ __init__.py              # Public exports
    โ”œโ”€โ”€ cli/
    โ”‚   โ””โ”€โ”€ main.py              # CLI entrypoint
    โ”œโ”€โ”€ core/
    โ”‚   โ”œโ”€โ”€ upload.py            # Upload + dependency logic
    โ”‚   โ”œโ”€โ”€ download.py          # Download + generalization logic
    โ”‚   โ””โ”€โ”€ formats.py           # Format handling utilities
    โ””โ”€โ”€ utils/
        โ”œโ”€โ”€ logging.py           # Shared logging configuration
        โ””โ”€โ”€ validation.py        # Agent name validation

โš ๏ธ Important Notes

  1. Authentication: Uses DefaultAzureCredential (interactive fallback enabled)
  2. Dependency Ordering: Creates/updates in safe order via topological sort
  3. Name Safety: Validation ensures only alphanumerics + hyphens (prefix/suffix applied consistently)
  4. Logging: Centralized configurable logger (configure_logging)
  5. Efficiency: Minimizes duplicate lookups by caching existing agents during batch operations
  6. Format Flexibility: Supports JSON, YAML, and Markdown with frontmatter for different workflow preferences

๐Ÿ” Troubleshooting

Installation Issues

# Install in development mode for local changes
pip install -e .

# Or install for production use
pip install .

Authentication Errors

# Check environment variables
echo $AZURE_TENANT_ID
echo $PROJECT_ENDPOINT

# Or use CLI parameters (recommended for CI/CD or when environment variables conflict)
aif-workflow-helper --download-all-agents \
  --azure-tenant-id "your-tenant-id" \
  --project-endpoint "your-endpoint"

# Try interactive login
az login --tenant $AZURE_TENANT_ID

Command Not Found Error

If aif-workflow-helper is not found after installation:

# Make sure you installed the package
pip install -e .

# Check if it's in your PATH
which aif-workflow-helper

# Or run directly with Python
python -m aif_workflow_helper.cli.main --help

๐ŸŽ‰ Success Output

Typical successful run output (truncated example):

๐Ÿ”Œ Testing connection...
โœ… Connected! Found X existing agents

๐Ÿ“ฅ Downloading agents...
Saved agent 'agent-name' to agent-name.json

๐Ÿ“‚ Reading agent files...
Found X agents

๐Ÿš€ Creating/updating agents...
Processing 1/X: agent-name
โœ… Successfully processed agent-name

๐Ÿ”„ CI/CD Pipeline

This project includes a comprehensive CI/CD pipeline using GitHub Actions that ensures code quality and functionality.

Pipeline Features

  • Multi-Python Version Testing: Tests on Python 3.10, 3.11, and 3.12
  • Automated Testing: Runs all pytest tests with coverage reporting
  • Code Quality: Includes linting with flake8
  • Package Testing: Verifies the package can be built and installed correctly
  • CLI Testing: Ensures the command-line interface works after installation

Branch Protection

The main branch is protected with the following requirements:

  • โœ… Pull Request Required: Direct pushes to main are not allowed
  • โœ… Tests Must Pass: All CI checks must pass before merging
  • โœ… Code Review: At least 1 approval required
  • โœ… Up-to-date Branch: Branches must be current with main

Running Tests Locally

Before submitting a PR, run tests locally to ensure they pass:

# Activate virtual environment
source .venv/bin/activate

# Install with dev dependencies
pip install -e .[dev]

# Run tests
pytest tests/ -v --tb=short

# Run with coverage
pytest tests/ -v --cov=src --cov-report=term-missing

# Check CLI functionality
aif-workflow-helper --help

Contributing

  1. Create a feature branch from main
  2. Make your changes
  3. Ensure all tests pass locally
  4. Submit a pull request
  5. Wait for CI to pass and get code review approval
  6. Merge when approved

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aif_workflow_helper-0.2.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aif_workflow_helper-0.2.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file aif_workflow_helper-0.2.0.tar.gz.

File metadata

  • Download URL: aif_workflow_helper-0.2.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for aif_workflow_helper-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0ea2771d045718cb42731dbd833bbd811f26ede7c5e295c49e2d89ccb4ec54b1
MD5 339d6477c36c02661ab8f4b910041b2d
BLAKE2b-256 7eeb0fdf2e364feb88bb66643e4f374e086a6d515b0b7251c1524d4cdc5bcc79

See more details on using hashes here.

File details

Details for the file aif_workflow_helper-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aif_workflow_helper-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8378c618fae2bc8fdb4762bcb6a22840bcfa7775d44e60ca141539889fdfa6d8
MD5 7e4442e84f7266e8308ae5141eda0184
BLAKE2b-256 9eb0a50c0caaf05c96572d914a2a2f7b865f357bcdde7c8350c7148d209b5d7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page