← Back to Blog

Unveiling Project Nighthawks: Building the Next-Generation AI-Powered Task Scheduler

  • 🤖 AI-Driven Scheduling: Integrates OpenAI GPT and the Graphiti knowledge graph to achieve intelligent conversion from natural language to Cron expressions.
  • 🧠 Context-Aware Execution: Task execution is no longer isolated; the system can remember historical execution patterns and optimize based on context.
  • 🏗️ Enterprise-Grade Architecture: Built on FastAPI with a microservices design, supporting high-availability, scalable production deployments with Docker and Kubernetes.
  • 📊 Comprehensive Observability: Deeply integrated with Prometheus and Grafana to provide full-stack monitoring from the application to the system level.
  • 🔒 Multi-Layered Security: Offers comprehensive security mechanisms, including JWT, API keys, and role-based access control.

A Deep Dive into the System Architecture

The architecture of Nighthawks is designed on principles of high availability, scalability, and security. Below is an overview of its layered architecture.


+--------------------------------+
|        UI & Access Layer       |
|  +-----------+   +-----------+ |
|  |  Web UI   |-->| RESTful API | |
|  +-----------+   +-----------+ |
+--------------------------------+
                 |
                 v
+--------------------------------+
| Application Service Layer (FastAPI) |
|  +-----------+                 |
|  | Main App  |-----------------+
|  +-----------+                 |
|   | |   |   |                  |
|   v v   v   v                  |
| [Auth][Scheduler][NLP][Metrics]|
+--------------------------------+
    |      |      |      |
    |      |      |      +------>[Prometheus]-->[Grafana]
    |      |      |
    |      |      +------------->[AI Layer: OpenAI, Graphiti]
    |      |
    |      +--------------------->[AI Agent]
    |      +--------------------->[Execution Logs]
    |
    +---------------------------->[Data Storage: PostgreSQL, Redis]

Key Module Analysis

  1. Natural Language Processing (NLP) Module This is the "brain" of the system. When a user inputs "Generate and send the sales report every Friday at 5 PM," this module calls the OpenAI GPT model. It not only parses the Cron expression 0 17 * * 5 but also extracts the core task "generate and send sales report" as the execution directive for the AI Agent. Through carefully designed Prompt Engineering, we have achieved a parsing accuracy of over 95%.

  2. AI Agent and Knowledge Graph Each task is executed by an independent AI Agent. Before execution, this Agent queries the Graphiti knowledge graph to retrieve relevant historical information, user preferences, or contextual data for the task. For example, if a previous report failed due to data source delays, the Agent might automatically learn to check the data source status before execution. This mechanism enables Nighthawks to have continuous learning and evolution capabilities.

  3. Task Scheduler (APScheduler) We chose APScheduler as the underlying execution engine. It provides stable and reliable distributed task scheduling capabilities. The AI layer is responsible for "deciding what to do and when," while the scheduler is responsible for "executing on time."

  4. Data Model (SQLModel) We use SQLModel to define our data structures. It combines the advantages of Pydantic and SQLAlchemy, providing type-safe ORM operations that significantly improve development efficiency and code robustness.

Technology Stack Highlights

Tier Technology Choice Description
Web Framework FastAPI Offers unparalleled performance and asynchronous support, making it the ideal choice for building high-performance APIs.
AI Engine OpenAI GPT + Graphiti GPT understands intent, and Graphiti retains knowledge. Together, they form a powerful intelligent core.
Task Scheduling APScheduler Mature, stable, and supports various triggers and distributed deployments.
Containerization Docker + Kubernetes Enables standardized deployment and management, with easy auto-scaling via HPA.
Monitoring Prometheus + Grafana Provides powerful observability, allowing us to gain real-time insights into system status and performance bottlenecks.

From Idea to Reality: A Usage Example

Let's walk through a concrete example to see how Nighthawks works.

1. User inputs a natural language command:

curl -X POST http://localhost:9527/api/v1/nlp/parse \
  -d '{"text": "Check server health and send an email notification every weekday at 9 AM"}'

2. Nighthawks' AI parses the request:

The system returns a structured task definition:

{
  "success": true,
  "task_name": "Server Health Check",
  "cron_expression": "0 9 * * 1-5",
  "agent_prompt": "Check server health status and email the results to the administrator.",
  "confidence": 0.98
}

3. Create and schedule the task:

After user confirmation, the task is persisted to the database and scheduled by APScheduler.

4. Task execution:

At 9 AM every weekday, the scheduler triggers the corresponding AI Agent. The Agent first queries the knowledge graph and might discover that "Server B had high CPU usage at 9 AM last week," so it prioritizes checking Server B. After completing the health check, it generates a report and sends it via email. All execution details, including token consumption and execution time, are logged for future optimization.

Conclusion

The Nighthawks project is more than just a technical exploration; it is a reflection on the future of automated work patterns. It demonstrates that by combining large language models, knowledge graphs, and traditional software engineering, we can create tools that are far more intelligent and user-friendly than ever before.

We believe that the software of the future will no longer be just a cold executor of instructions but an intelligent partner capable of understanding, learning, and collaborating efficiently with humans. Nighthawks is a solid step in this direction.