Skip to content

popovicidaniela/gn-ai-takehome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GenAI Takehome: End-to-End Fault-Tolerant Agent System

Overview

This project demonstrates an End-to-End Fault-Tolerant GenAI Agent System with the following components:

  • Ticketing API (Server): In-memory ticket management using FastAPI
  • GenAI Agent (Client): CLI agent that interacts with the API
  • PR Review Bot: Automated PR reviews via GitHub Actions
  • Infrastructure: Azure deployment using Terraform
gn-ai-takehome/
├── app/                # FastAPI server for ticketing
├── agent/              # GenAI CLI agent
├── pr_review_bot/      # PR review automation
├── shared/             # (shared code, if any)
├── infra/              # Terraform infrastructure
├── .github/            # GitHub Actions workflows
├── .gitignore
└── README.md

1. Launch the Ticketing API

Locally:

pip install -r app/requirements.txt
# Run from the project root
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000

Note: Always run this command from the project root (gn-ai-takehome), not from within the app directory. This ensures Python recognizes app as a package and allows absolute imports to work correctly.

Alternatively, with Docker:

docker build -t ticket-api:latest .
docker run -d -p 8000:8000 ticket-api:latest

Visit http://localhost:8000/docs for the Swagger UI and API documentation.


2. Launch GenAI Client CLI

  1. Create a .env file in the project root with the following content:

    AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
    AZURE_OPENAI_KEY=your-azure-openai-key
    AZURE_OPENAI_DEPLOYMENT=your-deployment-name
    AZURE_OPENAI_API_VERSION=2024-12-01-preview
  2. Install dependencies for the agent:

    pip install -r agent/requirements.txt
  3. Ensure your .env file is filled out as described above. Only API_BASE_URL is set in agent/main.py if you need to point to a different API location.

  4. In terminal:

    cd agent
    python main.py
  5. Interact with the AI Client using prompts such as:

    • Create a new ticket about a keyboard not working.
    • Retrieve all open tickets.
    • Get details for ticket 1.
    • Update ticket 1 to have the status PROGRESS.
    • Update ticket 2 to be RESOLVED, adding 'Replaced faulty cable' as the resolution.
    • Update ticket 10 to 'CLOSED'.
  6. Tool call logs are available in tool_calls.log.


3. PR Review Bot (GitHub Actions)

To run the PR review bot locally for testing:

  1. Install dependencies:

    pip install -r pr_review_bot/requirements.txt
  2. Ensure your .env file is filled out as described above in the previous section.

  3. When running locally, set the following environment variables in your shell (these are normally provided by GitHub Actions):

    export GITHUB_TOKEN="<your_personal_access_token_or_test_token>"
    export GITHUB_REPOSITORY="<owner>/<repo>"
    export PR_NUMBER="<pull_request_number>"
  4. In GitHub Actions, store the corresponding secrets in your repository's GitHub Secrets. The workflow .github/workflows/pr-review.yml loads them as environment variables for the PR review bot.

  5. Run the bot:

    python pr_review_bot/analyze_pr.py

4. Azure Deployment with Terraform

The infra/ folder contains Terraform definitions for Azure resources required to run the Ticket API.

Key files:

  • provider.tf – Azure provider configuration
  • variables.tf – Customizable settings
  • terraform.tfvars – Actual values
  • main.tf – Resource group creation
  • ticket-api.tf – Container Registry, App Service Plan, App Service (Docker)
  • outputs.tf – Useful deployment outputs

Prerequisites:

  1. Install Terraform:
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
  1. Verify installation:
terraform --version

Usage:

  1. Log in to Azure and create a service principal for Terraform deployments.
  2. In terminal:
cd infra
terraform init      # Initialize
terraform validate  # Validate
terraform plan      # Preview changes

Example output:

Changes to Outputs:
  + api_swagger_docs                = (known after apply)
  + app_service_url                 = (known after apply)
  + container_registry_login_server = (known after apply)
  + resource_group_name             = "gn-ai-takehome-rg"
  1. Build and push Docker image to Azure Container Registry (ACR):
docker build -t ticket-api:latest .
docker tag ticket-api:latest <registry>.azurecr.io/ticket-api:latest
docker push <registry>.azurecr.io/ticket-api:latest

Alternatively, set up a GitHub Action to build and deploy the image to ACR on PR merge to main.

Releases

No releases published

Packages

 
 
 

Contributors