cswork / libraryOpen practice workspace

Interview experiences · Cresta

Cresta Software Engineer Interview Experience — AI-Assisted Coding Round: Build a Flight-Booking Chat Agent in Python

OnsiteInterviewed 2026-09

You get an api.md doc plus an agent_starter.py file, and you have to use AI assistance to implement an AI Agent that searches for and books flights. The format is a chat dialog. Note: the language has to be Python, and you need to set up the whole project in your own IDE, so make sure you can actually run Python locally first. They'll also give you OPENAI_API_KEY, OPENAI_BASE_URL, and FLIGHT_API_…

You get an api.md doc plus an agent_starter.py file, and you have to use AI assistance to implement an AI Agent that searches for and books flights. The format is a chat dialog.

Note: the language has to be Python, and you need to set up the whole project in your own IDE, so make sure you can actually run Python locally first. They'll also give you OPENAI_API_KEY, OPENAI_BASE_URL, and FLIGHT_API_KEY.

api.md

  1. Save Passenger Information

POST /api/save_passenger_information

Request:

{ "first_name": "John", "last_name": "Doe", "email": "<email>", "phone": "<phone>", "date_of_birth": "1990-05-15" }

Response (save passenger_id):

{ "success": true, "passenger_id": "<passenger-uuid>", "message": "Passenger information saved successfully" }
  1. Search Flights

POST /api/search_flight

Request:

{ "origin": "JFK", "destination": "LAX", "departure_date": "2025-11-15", "passengers": 1 }

Response (save flight_id from selected flight):

{ "success": true, "flights": [ { "flight_id": "FLABCD1234", "flight_number": "AA123", "airline": "American Airlines", "departure_time": "2025-11-15T08:00:00", "arrival_time": "2025-11-15T11:30:00", "price": 299.99, "available": true } ], "total_results": 20 }
  1. Book Flight

POST /api/book_flight

Request (use IDs from steps 1 & 2):

{ "passenger_id": "<passenger-uuid>", "flight_id": "FLABCD1234", "seat_preference": "window" }

Response (save confirmation_code):

{ "success": true, "booking_id": "<booking-uuid>", "confirmation_code": "A7B3C9", "booking_details": { "pricing": { "total_price": 344.99 } } }

Authentication Example

headers = { "X-API-Key": "your-api-key-here", "Content-Type": "application/json" }

agent_starter.py

#!/usr/bin/env python3
"""
Flight Booking Agent Starter Template
"""

import os
import json
import requests
from openai import OpenAI
from dotenv import load_dotenv

load_dotenv()

# Configuration
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
FLIGHT_API_KEY = os.getenv("FLIGHT_API_KEY", "")
API_BASE_URL = "<flight API base URL>"

client = OpenAI(api_key=OPENAI_API_KEY)

# System prompt - modify as needed
SYSTEM_PROMPT = "You are a helpful flight booking assistant."

# Welcome message
WELCOME_MESSAGE = """Welcome to the Flight Booking Agent!
I can help you book flights. Just tell me where you'd like to go.
Type 'quit' to exit."""

# Define your tools here
TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get the current weather for a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "City name or zip code"
                    },
                    "units": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": "Temperature unit"
                    }
                },
                "required": ["location"],
                "additionalProperties": False
            }
        }
    }
]


def execute_function(function_name: str, arguments: dict) -> dict:
    """Execute API calls based on function name"""
    # Call your functions here

    return {"error": "Not implemented"}


def run_agent():
    """Main conversation loop"""
    messages = [{"role": "system", "content": SYSTEM_PROMPT}]

    print(f"\n{WELCOME_MESSAGE}\n")

    while True:
        user_input = input("You: ").strip()

        if user_input.lower() in ['quit', 'exit']:
            break

        if not user_input:
            continue

        messages.append({"role": "user", "content": user_input})

        # Call LLM
        response = client.chat.completions.create(
            model="gpt-4.1",
            messages=messages,
            tools=TOOLS if TOOLS else None
        )

        assistant_message = response.choices[0].message

        # Handle function calls
        if assistant_message.tool_calls:
            messages.append(assistant_message)

            for tool_call in assistant_message.tool_calls:
                result = execute_function(
                    tool_call.function.name,
                    json.loads(tool_call.function.arguments)
                )
                messages.append({
                    "role": "tool",
                    "tool_call_id": tool_call.id,
                    "name": tool_call.function.name,
                    "content": json.dumps(result)
                })

            # Get response after function execution
            response = client.chat.completions.create(
                model="gpt-4.1",
                messages=messages
            )
            assistant_message = response.choices[0].message

        messages.append(assistant_message)
        print(f"\nAgent: {assistant_message.content}\n")


if __name__ == "__main__":
    run_agent()

Comments

Nothing here yet.

Join in on CSWork →