Skip to content

Build Flight Booking Agent (Strands) #197

@aarora79

Description

@aarora79

Parent Issue: #195

Quick Links

Objective

Create a Strands-based agent that manages flight reservations and bookings for a fictional airline.

Important Architecture Clarification

Agent Skills (Tools) work directly with embedded SQLite databases for all CRUD operations. There is NO API layer between agent tools and the database:

  • Agent tools invoke Python SQLite methods directly
  • Query results are returned immediately to the agent
  • Agent skills receive calls from other agents via REST API (A2A protocol)
  • Each agent has its own embedded SQLite database (not shared)

Tech Stack

  • Framework: Strands (Python agentic framework)
  • Database: SQLite (in-process, embedded, direct CRUD from agent tools)
  • API: REST (A2A protocol - only for inter-agent communication)
  • Container: Docker

Agent Skills (Tools)

These tools interact directly with the embedded SQLite database:

  1. check_availability - Check seat availability for specific flight

    • Direct SQLite: SELECT available_seats FROM flights WHERE id=?
    • Returns: Number of available seats
  2. reserve_flight - Reserve seats on a flight for passengers

    • Direct SQLite: INSERT INTO bookings (...); INSERT INTO booking_passengers (...)
    • Direct SQLite: UPDATE seat_inventory SET status='reserved' WHERE flight_id=?
    • Returns: Booking number and reservation status
  3. confirm_booking - Confirm and finalize a flight booking

    • Direct SQLite: UPDATE bookings SET status='confirmed' WHERE booking_number=?
    • Direct SQLite: UPDATE seat_inventory SET status='booked' WHERE seat_number IN (?)
    • Returns: Confirmation code and final status
  4. process_payment - Process payment (simulated, no real integration)

    • Direct SQLite: INSERT INTO payments (...)
    • Direct SQLite: UPDATE bookings SET status='paid' WHERE booking_number=?
    • Returns: Transaction ID and payment status
  5. manage_reservation - Update, view, or cancel existing reservations

    • Direct SQLite: SELECT * FROM bookings WHERE booking_number=?
    • Direct SQLite: UPDATE bookings SET status='cancelled' WHERE booking_number=?
    • Direct SQLite: INSERT INTO cancellations (...)
    • Returns: Updated reservation details

Data Flow

External Request (from Travel Assistant Agent)
    ↓
[Flight Booking Agent (Strands) - REST API receives request]
    ├─→ Skill: check_availability
    │   └─→ Direct SQLite CRUD: SELECT from flights table
    ├─→ Skill: reserve_flight
    │   └─→ Direct SQLite CRUD: INSERT bookings, passengers, seat_inventory
    ├─→ Skill: confirm_booking
    │   └─→ Direct SQLite CRUD: UPDATE bookings, seat_inventory
    ├─→ Skill: process_payment
    │   └─→ Direct SQLite CRUD: INSERT payments, UPDATE bookings
    └─→ Skill: manage_reservation
        └─→ Direct SQLite CRUD: SELECT/UPDATE bookings, INSERT cancellations

SQLite Schema

Bookings Table

CREATE TABLE bookings (
  id INTEGER PRIMARY KEY,
  booking_number TEXT UNIQUE NOT NULL,
  flight_id INTEGER NOT NULL,
  total_price DECIMAL(10,2),
  status TEXT CHECK(status IN ('pending', 'confirmed', 'paid', 'cancelled')),
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  confirmed_at DATETIME,
  FOREIGN KEY (flight_id) REFERENCES flights(id)
);

Booking Passengers Table

CREATE TABLE booking_passengers (
  id INTEGER PRIMARY KEY,
  booking_id INTEGER NOT NULL,
  passenger_name TEXT NOT NULL,
  email TEXT,
  seat_number TEXT,
  FOREIGN KEY (booking_id) REFERENCES bookings(id)
);

Payments Table

CREATE TABLE payments (
  id INTEGER PRIMARY KEY,
  booking_id INTEGER NOT NULL,
  amount DECIMAL(10,2),
  status TEXT CHECK(status IN ('pending', 'completed', 'failed')),
  payment_method TEXT,
  processed_at DATETIME,
  FOREIGN KEY (booking_id) REFERENCES bookings(id)
);

Seat Inventory Table

CREATE TABLE seat_inventory (
  id INTEGER PRIMARY KEY,
  flight_id INTEGER NOT NULL,
  seat_row TEXT,
  seat_column TEXT,
  status TEXT CHECK(status IN ('available', 'reserved', 'booked')),
  FOREIGN KEY (flight_id) REFERENCES flights(id)
);

Cancellations Table

CREATE TABLE cancellations (
  id INTEGER PRIMARY KEY,
  booking_id INTEGER NOT NULL,
  reason TEXT,
  refund_amount DECIMAL(10,2),
  cancelled_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (booking_id) REFERENCES bookings(id)
);

Sample Data

Bookings

INSERT INTO bookings (booking_number, flight_id, total_price, status, created_at, confirmed_at) VALUES
('BK001', 1, 500.00, 'confirmed', '2025-11-01 10:00:00', '2025-11-01 10:15:00'),
('BK002', 1, 250.00, 'pending', '2025-11-01 11:00:00', NULL),
('BK003', 2, 560.00, 'confirmed', '2025-11-01 12:00:00', '2025-11-01 12:10:00'),
('BK004', 3, 440.00, 'confirmed', '2025-11-01 13:00:00', '2025-11-01 13:05:00');

Booking Passengers

INSERT INTO booking_passengers (booking_id, passenger_name, email, seat_number) VALUES
(1, 'John Smith', 'john@example.com', '12A'),
(1, 'Jane Smith', 'jane@example.com', '12B'),
(2, 'Bob Johnson', 'bob@example.com', '14C'),
(3, 'Alice Williams', 'alice@example.com', '1A'),
(4, 'Charlie Brown', 'charlie@example.com', '5B');

Payments

INSERT INTO payments (booking_id, amount, status, payment_method, processed_at) VALUES
(1, 500.00, 'completed', 'credit_card', '2025-11-01 10:15:00'),
(2, 250.00, 'pending', 'credit_card', NULL),
(3, 560.00, 'completed', 'credit_card', '2025-11-01 12:10:00'),
(4, 440.00, 'completed', 'paypal', '2025-11-01 13:05:00');

Seat Inventory (Sample for Flight 1 - UA101)

INSERT INTO seat_inventory (flight_id, seat_row, seat_column, status) VALUES
(1, '1', 'A', 'booked'),
(1, '1', 'B', 'booked'),
(1, '1', 'C', 'available'),
(1, '1', 'D', 'available'),
(1, '12', 'A', 'booked'),
(1, '12', 'B', 'booked'),
(1, '12', 'C', 'available'),
(1, '12', 'D', 'available'),
(1, '14', 'C', 'booked'),
(1, '14', 'D', 'available');

REST API Endpoints (A2A Protocol)

These endpoints receive requests from other agents (Travel Assistant Agent):

  • POST /api/check-availability - Called by Travel Assistant to check seats
  • POST /api/reserve-flight - Called by Travel Assistant to create reservation
  • POST /api/confirm-booking - Called by Travel Assistant to finalize booking
  • POST /api/process-payment - Called by Travel Assistant to process payment
  • GET /api/reservation/{id} - Called by Travel Assistant to retrieve booking
  • DELETE /api/reservation/{id} - Called by Travel Assistant to cancel booking
  • GET /api/health - Health check endpoint

Note: These endpoints route requests to agent skills, which then use direct SQLite CRUD operations. There is NO intermediate API layer between skills and database.

Acceptance Criteria

  • Built with Strands framework
  • All skills (tools) use direct SQLite CRUD (no backend API)
  • Registers with A2A Registry with appropriate tags
  • Docker image builds and runs
  • SQLite initialized with all schemas + seed data on startup
  • Receives booking requests from Travel Assistant Agent via REST A2A API
  • Manages seat inventory correctly via direct SQLite updates
  • Simulated payment processing (no real integration)
  • Error handling and logging for database operations
  • Follows patterns from referenced repos
  • Architecture clarification documented (no DB API layer)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions