# ๐Ÿซ SchoolOps Agent

### Autonomous AI Operations Manager for Schools

SchoolOps Agent is an AI-powered school operations system that helps administrators handle teacher absences and exam-supervision changes automatically.

When a teacher is absent, the agent can inspect the current exam schedule, check teacher availability, evaluate scheduling conflicts, select the best available replacement, update the exam assignment in Firestore, verify the change, and record an audit log.

The goal is to turn a manual school-operations task into a **safe, verifiable, autonomous workflow**.

---

## ๐Ÿš€ What Problem Does SchoolOps Solve?

School administrators often need to react quickly when a teacher becomes unavailable.

A simple replacement process can involve:

1. Finding the teacher's exam assignment.

2. Checking which teachers are available.

3. Checking whether those teachers already have another exam.

4. Choosing the best replacement.

5. Updating the schedule.

6. Confirming that the update actually happened.

7. Keeping a record of what changed and why.

Doing this manually can be time-consuming and can introduce scheduling mistakes.

SchoolOps Agent automates this workflow while keeping the final database operation controlled and verifiable.

---

# ๐Ÿค– How SchoolOps Works

Example request:

**"Ahmed is absent tomorrow."**

The SchoolOps workflow:


Administrator Request

        โ”‚

        โ–ผ

   SchoolOps Agent

        โ”‚

        โ–ผ

Read Current Exam Schedule

        โ”‚

        โ–ผ

Find Ahmed's Exam

        โ”‚

        โ–ผ

Read Teacher Availability

        โ”‚

        โ–ผ

Check Scheduling Conflicts

        โ”‚

        โ–ผ

Select Best Replacement

        โ”‚

        โ–ผ

Update Firestore

        โ”‚

        โ–ผ

Verify Database Change

        โ”‚

        โ–ผ

Create Audit Log

The system does not simply generate a recommendation.

It can **actually update the exam assignment and verify the resulting database state**.

---

# โœจ Key Features

## 1. Autonomous Teacher Replacement

The system identifies the exam supervised by an absent teacher and searches for suitable replacements.

Example:


Ahmed โ†’ Absent



Grade 8 English

09:00

Room 4

The system evaluates available teachers and selects the best valid candidate.

---

## 2. Availability-Based Selection

Teachers have availability information stored in Firestore.

Example:


Fatima

Status: Available

Available:

09:00

11:00

The workflow considers the teacher's availability when selecting a replacement.

When multiple teachers are suitable, the current workflow prefers the teacher with the **greatest availability**.

---

## 3. Conflict Detection

Before assigning a replacement teacher, SchoolOps checks the current exam schedule.

A teacher who already has an exam at the required time is rejected.

This prevents assignments such as:


Fatima

09:00 โ†’ Exam A



Fatima

09:00 โ†’ Exam B

---

## 4. Safe Database Updates

The replacement is not considered successful merely because an update command was executed.

The system:

1. Finds the affected exam.

2. Checks the replacement teacher.

3. Performs the update.

4. Reads the exam again.

5. Verifies that the new teacher is actually assigned.

Only then does the workflow report success.

---

## 5. Audit Logging

Every successful replacement is recorded in Firestore.

Example:


Action:

REPLACEMENT\_TEACHER\_ASSIGNED



Old Teacher:

Ahmed



New Teacher:

Fatima



Reason:

Ahmed is absent tomorrow. Selected the teacher

with the greatest availability and no scheduling conflict.

This provides a history of operational changes.

---

# ๐Ÿง  AI Agent

SchoolOps uses **Google ADK** with a Gemini model as the reasoning layer.

The agent has access to the following operational tools:


get\_exam\_schedule

get\_teacher\_availability

check\_teacher\_conflict

update\_exam\_schedule

The agent's instructions require it to:

* Inspect the real schedule.

* Identify the affected exam.

* Check teacher availability.

* Check scheduling conflicts.

* Select an appropriate replacement.

* Use the actual exam ID.

* Perform the database update.

* Verify the updated schedule.

* Never claim success unless the update succeeds.

This makes the AI agent operate as an **action-oriented operations manager**, rather than only a conversational chatbot.

---

# ๐Ÿ—๏ธ Architecture


โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚        React Frontend         โ”‚

โ”‚                               โ”‚

โ”‚  Schedule / Teachers / Agent  โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

                โ”‚

                โ”‚ HTTP

                โ–ผ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚        FastAPI Backend        โ”‚

โ”‚                               โ”‚

โ”‚   REST API + Agent Runner     โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

                โ”‚

        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

        โ”‚                โ”‚

        โ–ผ                โ–ผ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

โ”‚ Google ADK /  โ”‚  โ”‚ SchoolOps     โ”‚

โ”‚ Gemini Agent  โ”‚  โ”‚ Tools         โ”‚

โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

                           โ”‚

                           โ–ผ

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

                  โ”‚ Google Firestoreโ”‚

                  โ”‚                 โ”‚

                  โ”‚ Exams           โ”‚

                  โ”‚ Teachers        โ”‚

                  โ”‚ Audit Logs      โ”‚

                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

# ๐Ÿ› ๏ธ Technology Stack

### Frontend

* React

* Vite

* JavaScript

* CSS

### Backend

* Python

* FastAPI

* Uvicorn

### AI

* Google ADK

* Gemini

* Google GenAI SDK

### Database

* Google Cloud Firestore

### Development

* Git

* GitHub

* Python virtual environment

---

# ๐Ÿ“ Project Structure


schoolops-agent/

โ”‚

โ”œโ”€โ”€ backend/

โ”‚   โ”œโ”€โ”€ agent/

โ”‚   โ”œโ”€โ”€ agent.py

โ”‚   โ”œโ”€โ”€ database.py

โ”‚   โ”œโ”€โ”€ main.py

โ”‚   โ”œโ”€โ”€ tools.py

โ”‚   โ”œโ”€โ”€ .env

โ”‚   โ””โ”€โ”€ schoolops.db

โ”‚

โ”œโ”€โ”€ frontend/

โ”‚   โ””โ”€โ”€ src/

โ”‚       โ””โ”€โ”€ App.jsx

โ”‚

โ”œโ”€โ”€ docs/

โ”‚

โ”œโ”€โ”€ tests/

โ”‚

โ”œโ”€โ”€ main.py

โ”œโ”€โ”€ .gitignore

โ””โ”€โ”€ README.md

.env, virtual environments, Python cache files, and database files are excluded from Git using .gitignore.

---

# โ˜๏ธ Firestore Data Model

SchoolOps currently uses three main Firestore collections.

## teachers

Example document:


teachers/fatima


{

  "name": "Fatima",

  "status": "Available",

  "available\_times": \[

    "09:00",

    "11:00"

  ]

}

Example teachers currently used by the project:


Ahmed

Ali

Fatima

Sara

---

## exams

Example document:


exams/grade8\_english


{

  "grade": "Grade 8",

  "subject": "English",

  "teacher": "Ahmed",

  "room": "Room 4",

  "time": "09:00"

}

Current demonstration schedule:

| Grade | Subject | Teacher | Room | Time |

| ------- | ----------- | ------- | ------ | ----- |

| Grade 8 | English | Ahmed | Room 4 | 09:00 |

| Grade 8 | Mathematics | Sara | Room 2 | 11:00 |

| Grade 8 | Science | Ali | Room 3 | 13:00 |

---

## audit\_logs

Successful operational changes are stored in:


audit\_logs

Example:


{

  "exam\_id": 1,

  "action": "REPLACEMENT\_TEACHER\_ASSIGNED",

  "old\_teacher": "Ahmed",

  "new\_teacher": "Fatima",

  "reason": "Ahmed is absent tomorrow. Selected the teacher with the greatest availability and no scheduling conflict.",

  "created\_at": "server timestamp"

}

---

# ๐Ÿ” Environment Variables

Create:


backend/.env

Add your Gemini API key:


GOOGLE\_API\_KEY=your\_gemini\_api\_key

Never commit the real API key.

The repository's .gitignore excludes:


.env

venv/

\_\_pycache\_\_/

\*.pyc

\*.db

---

# ๐Ÿ’ป Local Setup

## 1. Clone the repository


git clone https://github.com/Iram-Khaliq/schoolops-agent.git

cd schoolops-agent

---

## 2. Create the Python environment

From the project root:

### Windows PowerShell


python -m venv backend\\venv

Activate it:


.\\backend\\venv\\Scripts\\Activate.ps1

---

## 3. Install backend dependencies

Install the required packages used by the project.

For example:


pip install fastapi uvicorn python-dotenv google-adk google-genai google-cloud-firestore

---

# โ˜๏ธ Google Cloud / Firestore Authentication

The project uses Google Application Default Credentials for Firestore.

After installing the Google Cloud CLI, authenticate:


gcloud auth application-default login

Set the project:


gcloud config set project schoolop

Verify:


gcloud config get-value project

Expected:


schoolop

The Firestore client is configured for the schoolop Google Cloud project.

---

# โ–ถ๏ธ Run the Backend

From:


D:\\schoolops-agent

activate the environment:


.\\backend\\venv\\Scripts\\Activate.ps1

Then start FastAPI:


python -m uvicorn backend.main:app --reload

The API runs at:


http://127.0.0.1:8000

---

# ๐ŸŒ API Endpoints

## Health Check


GET /

Returns:


{

  "message": "SchoolOps API is running"

}

---

## Get Exam Schedule


GET /api/exams

Returns the current Firestore exam schedule.

---

## Get Teacher Availability


GET /api/teachers

Returns teachers and their availability.

---

## Get Audit Logs


GET /api/audit-logs

Returns recorded operational changes.

---

## Update Exam


POST /api/update-exam

Updates an exam supervisor after conflict validation.

---

## Run Local SchoolOps Workflow


POST /api/run-workflow

Example request:


Ahmed is absent tomorrow

The endpoint identifies the absent teacher and executes the deterministic SchoolOps workflow.

---

## Run AI Agent


POST /api/test-agent

This endpoint sends the request through the Google ADK agent.

Example:


Ahmed is absent tomorrow

The ADK agent can inspect the schedule, use its tools, perform the replacement, and report the result.

---

# ๐Ÿงช Testing the Workflow

With the backend running, test the AI agent from PowerShell:


Invoke-RestMethod `

  -Uri "http://127.0.0.1:8000/api/test-agent?request=Ahmed%20is%20absent%20tomorrow" `

  -Method POST

A successful response contains:


success : True

mode    : adk

The agent response describes the resulting schedule change.

---

# ๐Ÿ”Ž Verify the Database

You can verify the exam assignment directly:


python -c "from backend.database import get\_exams; import pprint; pprint.pp(get\_exams())"

Example successful result:


Grade 8 English

Teacher: Fatima

Time: 09:00

The remaining schedule stays unchanged:


Grade 8 Mathematics

Teacher: Sara

Time: 11:00



Grade 8 Science

Teacher: Ali

Time: 13:00

---

# ๐Ÿงพ Verify the Audit Log

Run:


python -c "from backend.database import get\_audit\_logs; import pprint; pprint.pp(get\_audit\_logs())"

You should see a record similar to:


action:

REPLACEMENT\_TEACHER\_ASSIGNED



old\_teacher:

Ahmed



new\_teacher:

Fatima

---

# ๐Ÿง  Example Decision

Suppose Ahmed is absent for the 09:00 English exam.

Available teachers:


Ali

Available: 09:00



Sara

Available: 09:00



Fatima

Available: 09:00, 11:00

The workflow checks:


Ali

09:00 โ†’ no conflict



Sara

09:00 โ†’ no conflict



Fatima

09:00 โ†’ no conflict

All three are valid candidates.

The current selection strategy prefers the teacher with the greatest availability:


Fatima โ†’ 2 available times

Ali    โ†’ 1 available time

Sara   โ†’ 1 available time

Therefore:


Ahmed โ†’ Fatima

The database is then updated and verified.

---

# ๐Ÿ›ก๏ธ Safety and Verification

SchoolOps is designed around several important safeguards.

### No invented schedules

The agent is instructed to use the database tools instead of inventing schedule information.

### Conflict prevention

A teacher with a conflicting exam assignment is rejected.

### Database-backed updates

The replacement is actually written to Firestore.

### Post-update verification

The system reads the schedule again after the update.

### Auditability

Successful changes are recorded in the audit log.

### No false success

The system does not report a successful replacement unless the update succeeds and can be verified.

---

# ๐Ÿ”„ AI Failure Handling

The backend also contains a deterministic local workflow.

This provides a useful fallback architecture:


                    User Request

                         โ”‚

                         โ–ผ

                  Google ADK Agent

                         โ”‚

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”

                  โ”‚             โ”‚

              Available      API/Quota

                โ”‚             Failure

                โ–ผ                โ”‚

          AI Workflow            โ–ผ

                           Local Workflow

                                โ”‚

                                โ–ผ

                         Firestore Update

This allows the core scheduling operation to remain deterministic even when the Gemini service is temporarily unavailable.

---

# ๐ŸŽฏ Why This Is an Agent

SchoolOps is designed around an agentic workflow rather than a simple question-answering chatbot.

The agent can:


Observe

   โ†“

Reason

   โ†“

Choose

   โ†“

Act

   โ†“

Verify

   โ†“

Report

For example:


Observe:

Ahmed is absent.



Reason:

Ahmed supervises the 09:00 English exam.



Observe:

Fatima, Ali and Sara are available.



Reason:

Check their scheduling conflicts.



Choose:

Fatima has the greatest availability.



Act:

Update the exam assignment.



Verify:

Read the database again.



Report:

Ahmed was replaced by Fatima.

---

# ๐Ÿ† Hackathon Value

SchoolOps demonstrates several important AI-agent capabilities:

* Autonomous multi-step reasoning

* Tool calling

* Real database interaction

* Constraint-based decision making

* Conflict detection

* Persistent state

* Action execution

* Post-action verification

* Auditability

* Graceful fallback behavior

The important distinction is that the agent is not only generating text.

It can **take an operational action and verify the resulting state**.

---

# ๐Ÿ“Š Current Project Status

| Component | Status |

| --------------------- | ------------- |

| React frontend | โœ… Working |

| FastAPI backend | โœ… Working |

| Google ADK agent | โœ… Working |

| Gemini integration | โœ… Tested |

| Firestore | โœ… Connected |

| Teacher collection | โœ… Working |

| Exam collection | โœ… Working |

| Conflict detection | โœ… Working |

| Automatic replacement | โœ… Working |

| Database verification | โœ… Working |

| Audit logging | โœ… Working |

| Git/GitHub | โœ… Configured |

| Cloud Run deployment | โณ Future step |

---

# ๐Ÿ”ฎ Future Improvements

Possible next steps include:

### Multi-exam optimization

Handle multiple absent teachers and optimize the complete exam schedule.

### Better constraint solving

Consider:

* Teacher subject expertise

* Grade preferences

* Room restrictions

* Maximum supervision load

* Teacher availability windows

### Authentication

Add administrator authentication and role-based access.

### Richer audit history

Provide filtering and reporting for historical scheduling changes.

### Notifications

Notify administrators and teachers when a replacement is assigned.

### Production deployment

Deploy the backend and frontend to production infrastructure.

### Persistent agent sessions

Move beyond the current demo session handling toward persistent operational conversations.

---

# ๐Ÿ“ธ Demo

Recommended demonstration flow:


1\. Open SchoolOps frontend

             โ†“

2\. Show current exam schedule

             โ†“

3\. Ask:

   "Ahmed is absent tomorrow."

             โ†“

4\. Agent inspects schedule

             โ†“

5\. Agent checks teacher availability

             โ†“

6\. Agent checks conflicts

             โ†“

7\. Agent selects Fatima

             โ†“

8\. Firestore is updated

             โ†“

9\. Agent verifies the assignment

             โ†“

10\. Audit log is created

Expected result:


Grade 8 English

09:00

Ahmed โ†’ Fatima

---

# ๐Ÿ”— Repository

GitHub:

**Iram-Khaliq/schoolops-agent**

---

# ๐Ÿ‘ฉโ€๐Ÿ’ป Author

**Iram Khaliq**

Software Engineer focused on building practical AI-powered applications and autonomous workflows.

---

# ๐Ÿ“„ License

This project is currently intended as a hackathon/demo project.

A production license can be added when the project is prepared for public distribution.

Share this project:

Updates