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
Locally:
pip install -r app/requirements.txt
# Run from the project root
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000Note: 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:latestVisit http://localhost:8000/docs for the Swagger UI and API documentation.
-
Create a
.envfile 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
-
Install dependencies for the agent:
pip install -r agent/requirements.txt
-
Ensure your
.envfile is filled out as described above. OnlyAPI_BASE_URLis set inagent/main.pyif you need to point to a different API location. -
In terminal:
cd agent python main.py -
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'.
-
Tool call logs are available in
tool_calls.log.
To run the PR review bot locally for testing:
-
Install dependencies:
pip install -r pr_review_bot/requirements.txt
-
Ensure your
.envfile is filled out as described above in the previous section. -
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>"
-
In GitHub Actions, store the corresponding secrets in your repository's GitHub Secrets. The workflow
.github/workflows/pr-review.ymlloads them as environment variables for the PR review bot. -
Run the bot:
python pr_review_bot/analyze_pr.py
The infra/ folder contains Terraform definitions for Azure resources required to run the Ticket API.
Key files:
provider.tf– Azure provider configurationvariables.tf– Customizable settingsterraform.tfvars– Actual valuesmain.tf– Resource group creationticket-api.tf– Container Registry, App Service Plan, App Service (Docker)outputs.tf– Useful deployment outputs
Prerequisites:
- 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- Verify installation:
terraform --versionUsage:
- Log in to Azure and create a service principal for Terraform deployments.
- In terminal:
cd infra
terraform init # Initialize
terraform validate # Validate
terraform plan # Preview changesExample 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"
- 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:latestAlternatively, set up a GitHub Action to build and deploy the image to ACR on PR merge to main.