Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpaceX Conversational AI Agent

A conversational AI agent that answers questions about SpaceX using the SpaceX API. Demonstrates agentic patterns, prompt design, tool usage, and system design.

Features

Flexible Query-Based Tools (13 Tools)

Instead of rigid single-purpose tools, the agent uses flexible, parameter-rich tools that support MongoDB-style queries:

Tool Description
query_spacex_api Core flexible tool - any MongoDB query on any endpoint
get_launches Filter by type (past/upcoming/latest), sort, limit, offset
get_launches_by_date_range Filter launches by date range
get_launches_by_rocket Filter by rocket type
get_launches_by_launchpad Filter by launch site
search_by_name Regex search on any endpoint
full_text_search Full-text search across fields
get_all_items Get items from any endpoint
get_by_id Get specific item by ID
count_items Count with optional filter
compare_items Compare multiple items
get_company_info SpaceX company details
get_roadster_info Tesla Roadster status

MongoDB Query Support

The agent can construct complex queries:

{"success": True}                                    # Boolean filter
{"name": {"$regex": "starlink", "$options": "i"}}   # Case-insensitive search
{"date_utc": {"$gte": "2022-01-01"}}                # Date comparison
{"$text": {"$search": "crew"}}                       # Full text search

Modern LLM Engineering

  • LangGraph: State-based agentic workflow
  • LangChain: Tool integration and LLM abstraction
  • Conversation Memory: Context across multiple turns
  • OpenAI Function Calling: Structured tool invocation

Agentic Behaviors

  • Multi-tool reasoning: Multiple API calls for complete information
  • Relative position queries: "2nd to last launch", "the one before that"
  • Context maintenance: Handles follow-up questions like "how many times has that flown?"
  • No hardcoded responses: All data from live API

Installation

Prerequisites

  • Python 3.10+
  • OpenAI API key

Setup

# Create virtual environment
python -m venv venv

# Activate (Windows)
.\venv\Scripts\Activate.ps1
# Or (macOS/Linux)
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Configuration

Create a .env file (see .env.example):

OPENAI_API_KEY=your_openai_api_key_here

Usage

Run the Agent

python main.py

Example Queries

"When was the last SpaceX launch?"
"What's the next SpaceX launch and where is it happening?"
"How many launches did SpaceX complete in 2024?"
"Which rocket was used for the Starlink 9-1 mission?"
"Show me all successful Falcon 9 launches."
"What was the outcome of the first Falcon Heavy launch?"
"Tell me about the most recent launch from Vandenberg."
"What was the 2nd to last launch?"
"Give me the 5th latest launch"
"Now tell me the one right before that"

Commands

  • quit / exit - End conversation
  • clear - Clear conversation history
  • help - Show help

Project Structure

Podium_Project/
├── main.py                     # Console interface
├── requirements.txt            # Dependencies
├── README.md
├── src/
│   ├── agent/
│   │   └── spacex_agent.py     # LangGraph agent + sync fallback
│   └── tools/
│       └── spacex_api.py       # 13 flexible API tools
├── test_tools.py               # Tool unit tests
├── test_agent.py               # PDF query tests
├── test_validation.py          # API validation tests
├── test_context.py             # Multi-turn context tests
└── test_weird_questions.py     # Edge case tests

Testing

Run All Tests

# Test API tools
python test_tools.py

# Test PDF example queries
python test_agent.py

# Test with API validation
python test_validation.py

# Test multi-turn context
python test_context.py

# Test edge cases / weird questions
python test_weird_questions.py

Test Results

  • PDF Queries: 7/7 passed
  • Weird Questions: 10/10 passed (including "2nd to last", slang, negations)
  • Context Tests: 6/6 passed (follow-ups, pronouns, relative references)

Architecture

┌─────────────────────────────────────────────────────────────┐
│                Console Interface (main.py)                   │
└─────────────────────────────┬───────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                  LangGraph Agent Workflow                    │
│  ┌──────────┐    ┌───────────┐    ┌───────────────────┐    │
│  │  State   │───▶│   Agent   │───▶│  Tool Execution   │    │
│  │ Manager  │◀───│   Node    │◀───│  (13 flex tools)  │    │
│  └──────────┘    └───────────┘    └───────────────────┘    │
│        │                                                     │
│        ▼                                                     │
│  ┌───────────────────────────────────────────────────────┐  │
│  │           Memory Saver (Conversation Context)          │  │
│  └───────────────────────────────────────────────────────┘  │
└─────────────────────────────┬───────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                   OpenAI GPT-4o-mini                         │
│                 (Function Calling API)                       │
└─────────────────────────────┬───────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                  SpaceX REST API (v4)                        │
│              https://api.spacexdata.com/v4/                  │
│  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐           │
│  │Launches │ │ Rockets │ │  Crew   │ │Capsules │  + more   │
│  └─────────┘ └─────────┘ └─────────┘ └─────────┘           │
└─────────────────────────────────────────────────────────────┘

Design Decisions

  1. Flexible over rigid tools: 13 parameter-rich tools instead of 31 single-purpose ones
  2. MongoDB query support: LLM constructs queries dynamically based on user intent
  3. No hardcoded responses: All data comes from live API calls
  4. Offset-based positioning: Supports "Nth to last" and relative queries
  5. Clear prompt engineering: System prompt guides LLM on query construction

Dependencies

  • langchain>=0.3.0 - LLM framework
  • langchain-openai>=0.2.0 - OpenAI integration
  • langgraph>=0.2.0 - Agentic workflow graphs
  • httpx>=0.25.0 - HTTP client
  • python-dotenv>=1.0.0 - Environment variables
  • rich>=13.0.0 - Terminal UI

Acknowledgments

About

Agentic LLM system for SpaceX data with tool-first design, dynamic query construction, deterministic outputs (temp=0), LangGraph state management, and full API validation across complex + weird queries.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages