A conversational AI agent that answers questions about SpaceX using the SpaceX API. Demonstrates agentic patterns, prompt design, tool usage, and system design.
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 |
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- LangGraph: State-based agentic workflow
- LangChain: Tool integration and LLM abstraction
- Conversation Memory: Context across multiple turns
- OpenAI Function Calling: Structured tool invocation
- 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
- Python 3.10+
- OpenAI API key
# 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.txtCreate a .env file (see .env.example):
OPENAI_API_KEY=your_openai_api_key_here
python main.py"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"
quit/exit- End conversationclear- Clear conversation historyhelp- Show help
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
# 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- 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)
┌─────────────────────────────────────────────────────────────┐
│ 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 │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
└─────────────────────────────────────────────────────────────┘
- Flexible over rigid tools: 13 parameter-rich tools instead of 31 single-purpose ones
- MongoDB query support: LLM constructs queries dynamically based on user intent
- No hardcoded responses: All data comes from live API calls
- Offset-based positioning: Supports "Nth to last" and relative queries
- Clear prompt engineering: System prompt guides LLM on query construction
langchain>=0.3.0- LLM frameworklangchain-openai>=0.2.0- OpenAI integrationlanggraph>=0.2.0- Agentic workflow graphshttpx>=0.25.0- HTTP clientpython-dotenv>=1.0.0- Environment variablesrich>=13.0.0- Terminal UI
- SpaceX API - Open source SpaceX data
- LangChain - LLM application framework
- LangGraph - Agentic workflows