This repository contains lightweight demos for structured LLM API usage, agent-oriented workflows, and research prototyping.
The goal of this repository is to collect small, reusable examples for experimenting with modern LLM APIs, including structured outputs, tool/function calling, prompt-based extraction, and early-stage agent workflow design.
This repository supports my broader research on trustworthy multi-agent AI systems and LLM-agent collaboration. In particular, these demos provide practical building blocks for:
- structured proposal generation;
- evidence-aware LLM outputs;
- agent response formatting;
- lightweight evaluation pipelines;
- API-based research prototyping.
It is not intended to be a full framework. Instead, it serves as a compact experimental space for testing API behaviors and implementation patterns that may later be integrated into larger research systems.
Current and future examples may include:
- structured JSON output generation;
- function/tool calling demos;
- multi-agent interaction prototypes;
- claim verification or evidence-grounded response examples;
- prompt templates for research experiments;
- basic visualization or analysis utilities.
This project demonstrates three core capabilities of modern LLM APIs:
- Structured Extraction: Parse unstructured text into validated JSON schemas
- Function Calling: Enable LLMs to interact with external tools and APIs
- Multi-Agent Systems: Use LLMs for high-level coordination in MARL environments
Each demo is self-contained, well-documented, and includes practical examples.
Directory: 01_structured_extract/
Extract structured metadata from academic papers using three major LLM providers:
- OpenAI GPT-4: Strict JSON schema enforcement
- Anthropic Claude: Tool-based extraction
- Google Gemini: JSON mode extraction
Key Features:
- JSON Schema validation with
jsonschema - API rate limiting handling
- Unified schema across providers
- Batch processing support
Example:
cd 01_structured_extract
python openai_demo.py samples/paper.txtOutput: Validated JSON with title, authors, venue, year, keywords, etc.
Directory: 02_tool_calling/
An AI day planner that demonstrates LLM function calling with real-world APIs:
- Weather API: Fetch forecasts from Open-Meteo
- Calendar API: Find free slots and book meetings
- Routing API: Estimate travel time with OSRM
Key Features:
- OpenAI function calling with multiple tools
- File-based input/output for easy testing
- Batch processing of multiple requests
- Human-readable Markdown output
Example:
cd 02_tool_calling
python planner.py --request requests/example1_basic.txtOutput: Comprehensive daily plan with weather, meetings, and travel times.
Directory: 03_MARL_ViZ_Demo/
API-first multi-agent reinforcement learning visualization without training:
- High-level Director: Greedy or LLM-based agent-landmark assignment
- Low-level Actor: HTTP policy server or local heuristics
- Environments: PettingZoo cooperative (spread) and adversarial (tag)
Key Features:
- Real-time GIF generation with English captions
- Dual-axis metrics plots (reward + coverage)
- Modular architecture (director + actor)
- No training required (demonstration only)
Example:
cd 03_MARL_ViZ_Demo
# Terminal 1: Start policy server (optional)
python src/policy_server.py
# Terminal 2: Run visualization
python src/marl_viz.py --env spread --steps 200 --director greedy --actor localOutput:
outputs/rollout_*.gif: 20-second animated visualizationoutputs/metrics_*.png: Performance charts
- Python 3.11 or higher
- API keys (at least one):
- OpenAI: Get API key
- Anthropic: Get API key
- Google Gemini: Get API key
# Clone the repository
git clone https://github.com/yourusername/API_Demo.git
cd API_Demo
# Install all dependencies
pip install -r requirements.txt
# Set up API keys
echo "OPENAI_API_KEY=your_key_here" > .env
echo "ANTHROPIC_API_KEY=your_key_here" >> .env
echo "GEMINI_API_KEY=your_key_here" >> .env# Demo 1: Structured extraction
cd 01_structured_extract
python run_all.py
# Demo 2: Function calling
cd ../02_tool_calling
python run_examples.py
# Demo 3: MARL visualization
cd ../03_MARL_ViZ_Demo
python src/marl_viz.py --env spread --steps 100 --director greedyAPI_Demo/
βββ README.md # This file
βββ requirements.txt # Unified dependencies
βββ LICENSE # MIT License
βββ .gitignore # Git ignore rules
β
βββ 01_structured_extract/ # Demo 1: Structured Extraction
β βββ README.md # Detailed documentation
β βββ requirements.txt # Local dependencies
β βββ openai_demo.py # OpenAI implementation
β βββ anthropic_demo.py # Anthropic implementation
β βββ gemini_demo.py # Google Gemini implementation
β βββ run_all.py # Batch runner
β βββ common/ # Shared modules
β β βββ schema.py # JSON schema definition
β β βββ validate.py # Validation utilities
β βββ samples/ # Example inputs
β βββ paper.txt
β βββ paper_noise.txt
β
βββ 02_tool_calling/ # Demo 2: Function Calling
β βββ README.md # Detailed documentation
β βββ DEMO_GUIDE.md # Presentation guide
β βββ requirements.txt # Local dependencies
β βββ planner.py # Main planner script
β βββ run_examples.py # Batch processor
β βββ requests/ # Example requests
β β βββ README.md
β β βββ example1_basic.txt
β β βββ example2_complex.txt
β β βββ example3_weather_focused.txt
β βββ plans/ # Output directory (generated)
β
βββ 03_MARL_ViZ_Demo/ # Demo 3: MARL Visualization
βββ README.md # Detailed documentation
βββ DEMO_GUIDE.md # Presentation guide
βββ requirements.txt # Local dependencies
βββ src/
β βββ marl_viz.py # Main visualization client
β βββ policy_server.py # FastAPI policy server
β βββ llm_director.py # Assignment coordinator
βββ outputs/ # Output directory (generated)
All demos share these core dependencies:
openai>=1.0.0- OpenAI API clientanthropic>=0.34.0- Anthropic API clientgoogle-generativeai>=0.3.0- Google Gemini API clientpython-dotenv>=1.0.0- Environment variable managementrequests>=2.32.0- HTTP requests
Demo 1 (Structured Extract):
jsonschema>=4.22.0- JSON schema validation
Demo 2 (Tool Calling):
python-dateutil>=2.8.0- Date parsing
Demo 3 (MARL Viz):
pettingzoo[mpe]>=1.24- Multi-agent environmentsgymnasium>=0.29- RL environment frameworknumpy>=1.26- Numerical computingimageio>=2.34- GIF generationpillow>=10.3- Image processingmatplotlib>=3.8- Plottingfastapi>=0.115- API serveruvicorn>=0.30- ASGI server
# Install all dependencies (recommended)
pip install -r requirements.txt
# Or install per demo
pip install -r 01_structured_extract/requirements.txt
pip install -r 02_tool_calling/requirements.txt
pip install -r 03_MARL_ViZ_Demo/requirements.txtCreate a .env file in the project root or in each demo directory:
# OpenAI
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o-mini # Optional: override default model
# Anthropic
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_MODEL=claude-sonnet-4-5 # Optional
# Google Gemini
GEMINI_API_KEY=AI...- Google Gemini Free Tier: 5 RPM (handled automatically with delays)
- OpenAI: Depends on your tier
- Anthropic: Depends on your tier
Each demo includes test scripts:
# Demo 1: Test all three providers
cd 01_structured_extract
python run_all.py
# Demo 2: Test all example requests
cd 02_tool_calling
python run_examples.py
# Demo 3: Test both environments
cd 03_MARL_ViZ_Demo
python src/marl_viz.py --env spread --steps 50
python src/marl_viz.py --env tag --steps 50- Rapid prototyping of LLM-powered systems
- Benchmarking different API providers
- Teaching LLM application development
- Data extraction pipelines
- Intelligent assistants with tool use
- Multi-agent system coordination
- Hands-on LLM API tutorials
- Best practices for API integration
- Prompt engineering examples
Issue: ModuleNotFoundError
- Solution: Install dependencies:
pip install -r requirements.txt
Issue: API key not found
- Solution: Create
.envfile with your API keys
Issue: Rate limit errors (Google Gemini)
- Solution: Use free tier with built-in delays or upgrade plan
Issue: Import errors from pettingzoo
- Solution: Update imports (handled automatically in latest version)
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for GPT-4 API
- Anthropic for Claude API
- Google for Gemini API
- PettingZoo for multi-agent environments
- FastAPI for the elegant web framework
For questions or suggestions, please open an issue or contact 2614067X@student.gla.ac.uk.
β If you find this project useful, please consider giving it a star!