Skip to content

Repository files navigation

FastAPI Tool Agent

A powerful AI agent with multiple tools, deployed on Azure App Service with automated CI/CD and secure Key Vault integration.

🌟 Features

  • AI-Powered Tools - Calculator, time, file operations, text analysis, RAG search
  • FastAPI REST API - Clean, documented endpoints with Swagger UI
  • Azure Integration - Deployed on Azure App Service with Key Vault
  • CI/CD Pipeline - Automated deployment via GitHub Actions
  • Security First - All secrets stored in Azure Key Vault
  • Production Ready - Comprehensive error handling and monitoring

🛠️ Available Tools

  • Calculator Tool - Mathematical calculations
  • Time Tool - Current date and time
  • File Operations - Read, write, list files
  • Text Analysis - Sentiment analysis, word count
  • RAG Search - Document search and retrieval
  • Web Search - Mock web search functionality

🏗️ Architecture

GitHub Repo → GitHub Actions → Azure App Service → Azure OpenAI

📁 Project Structure

fastapi-tool-agent/
├── .github/workflows/
│   └── azure-deploy.yml          # CI/CD pipeline
├── fastapi_agent.py              # Main FastAPI application
├── tool_agent.py                 # AI agent with tools
├── azure_config.py               # Azure configuration
├── config.py                     # Local configuration
├── startup.py                    # Azure startup script
├── test_api.py                   # API test client
├── start_api.sh                  # Local startup script
├── deploy_to_azure.sh            # Azure deployment script
├── setup_github_repo.sh          # GitHub setup script
├── requirements.txt              # Python dependencies
└── README.md                     # This file

🚀 Quick Start

Local Development

# Install dependencies
pip install -r requirements.txt

# Run locally
python3 fastapi_agent.py
# or
./start_api.sh

Azure Deployment

# Setup GitHub repository
./setup_github_repo.sh

# Deploy to Azure
./deploy_to_azure.sh

# Add GitHub secret: AZURE_WEBAPP_PUBLISH_PROFILE
# Push to main to trigger deployment

🔧 API Endpoints

Main Agent

  • POST /agent/query - Natural language queries

Individual Tools

  • POST /tools/calculator - Math calculations
  • POST /tools/time - Current date/time
  • POST /tools/file - File operations
  • POST /tools/search - Web search
  • POST /tools/analyze - Text analysis
  • POST /tools/rag - Document search

Information

  • GET / - API information
  • GET /health - Health check
  • GET /tools - Available tools
  • GET /examples - Usage examples

🧪 Testing

Local Testing

# Test the agent
python3 -c "
import asyncio
from tool_agent import ToolBasedAgent

async def test():
    agent = ToolBasedAgent()
    result = await agent.run('What is 2 + 2?')
    print(result)

asyncio.run(test())
"

# Test the API
python3 test_api.py

API Testing

# Test health check
curl https://your-app.azurewebsites.net/health

# Test agent query
curl -X POST "https://your-app.azurewebsites.net/agent/query" \
  -H "Content-Type: application/json" \
  -d '{"query": "What is 2 + 2?"}'

🔐 Configuration

Environment Variables

  • AZURE_OPENAI_API_KEY - Azure OpenAI API key
  • AZURE_OPENAI_ENDPOINT - Azure OpenAI endpoint
  • AZURE_OPENAI_API_VERSION - API version
  • AZURE_OPENAI_DEPLOYMENT_NAME - Model deployment name

GitHub Secrets

  • AZURE_WEBAPP_PUBLISH_PROFILE - Azure deployment credentials

🔄 CI/CD Pipeline

The GitHub Actions workflow automatically:

  1. Tests the application
  2. Builds deployment package
  3. Deploys to Azure App Service
  4. Configures environment variables
  5. Verifies deployment health

📊 Monitoring

  • Azure Portal - App Service monitoring
  • Application Logs - Real-time logging
  • Health Endpoints - Service availability
  • GitHub Actions - CI/CD status

🎯 Use Cases

  • Web Applications - AI-powered web apps
  • Mobile Apps - Backend API for mobile
  • Automation - Workflow automation
  • Development - AI-assisted development tools

🔧 Troubleshooting

Common Issues

  1. Deployment fails:

    • Check GitHub Actions logs
    • Verify Azure credentials
    • Check app settings
  2. App won't start:

    • Check startup command
    • Verify Python version
    • Check application logs
  3. API errors:

    • Verify Azure OpenAI configuration
    • Check environment variables
    • Test locally first

Debug Commands

# Check app status
az webapp show --name your-app-name --resource-group your-resource-group

# Check logs
az webapp log tail --name your-app-name --resource-group your-resource-group

# Restart app
az webapp restart --name your-app-name --resource-group your-resource-group

📚 Documentation

  • API Documentation - Interactive Swagger UI at /docs
  • Deployment Guide - See AZURE_DEPLOYMENT_GUIDE.md
  • API Reference - See API_DOCS.md

🆘 Support

  • Issues - Create GitHub issues
  • Documentation - Check /docs endpoint
  • Logs - Check Azure App Service logs

🎉 Project Status: PRODUCTION READY

All features implemented and testedDeployment pipeline configuredDocumentation completeReady for production use

Your FastAPI Tool Agent is ready for deployment! 🚀

About

Production LLM agent with FastAPI, Azure OpenAI, tool use, CI/CD & Key Vault

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages