A tool-using agent + physics simulator for recommending thermal mitigation strategies in deep space photonic instruments โ runs on managed AWS Bedrock or a self-hosted, fine-tuned open-weight model
Physics simulation ยท Agentic tool use ยท Scenario retrieval ยท XGBoost classification ยท QLoRA + GGUF open-weight fine-tuning ยท Streamlit demo
Photonic Integrated Circuits (PICs) are the backbone of next generation space probe instruments that operate in deep space โ spectrometers, laser communication terminals, waveguide sensor arrays, and photonic signal processors. But space is brutal:
- ๐ก๏ธ Spectral drift โ temperature swings shift refractive indices, pushing resonant wavelengths off-target and corrupting measurements
- ๐ Waveguide misalignment โ differential thermal expansion between chip layers destroys optical coupling, killing signal throughput
- ๐ฅ Mechanical cracking โ repeated thermal cycling fatigues bonding interfaces and dielectric layers until catastrophic failure
A spectrometer on a Jovian probe faces 180 K temperature swings. An optical link in the outer solar system endures 240 K. The wrong mitigation strategy means mission failure.
This project pairs deterministic physics with an agent that reasons over a knowledge data store โ no fine-tuning required. A Bedrock foundation model decides which tools to call for any instrument-material-environment combination, then synthesizes a grounded recommendation:
| Layer | What It Does | Status |
|---|---|---|
| ๐ฌ Physics Simulator | Computes ฮn and strain from first principles | โ Live |
| ๐ค Tool-Using Agent | Reasons over the scenario and calls tools via a pluggable backend | โ Live |
| โ๏ธ Bedrock Backend | Managed foundation model via the Converse API | โ Live |
| ๐ง Open-Weight Backend | Self-hosted Llama 3.3 / Qwen2.5 fine-tuned with QLoRA, served as GGUF | โ Live |
| ๐ Scenario Data Store | Retrieves similar prior cases from the 40K-scenario knowledge base | โ Live |
| ๐ XGBoost Classifier | Fast Passive / Active / Hybrid prediction with calibrated probabilities | โ Live |
| ๐ฅ๏ธ Streamlit App | Interactive two-mode demo (physics + agentic advisor) | โ Live |
| ๐งช CI Pipeline | Automated pytest across Python 3.10โ3.12 on every push and PR | โ Live |
- Knowledge stays out of the weights. The data store holds the facts; updating it means re-indexing, not re-training. Every recommendation cites real simulator output, classifier probabilities, and retrieved scenarios.
- Behavior can be baked into the weights โ for open-weight models. You don't fine-tune to teach facts; you fine-tune so an open-weight model reliably emits this stack's tool calls without babysitting it with a giant system prompt. See Open-Weight Fine-Tuning.
- Composable โ the simulator, classifier, and data store are independent tools the model orchestrates on demand, regardless of backend.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Streamlit Interactive App โ
โ (Physics Simulator ยท Agentic Advisor)โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ThermalAgent โ
โ reason โ act tool-use loop โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Bedrock backend โ โ Local backend โ
โ (managed FM via โ โ (fine-tuned GGUF via โ
โ Converse API) โ โ OpenAI-compatible EP) โ
โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ToolDispatcher โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ simulate_ โ โ classify_ โ โ search_thermal_ โ
โ thermal_ โ โ strategy โ โ knowledge โ
โ drift โ โ (XGBoost) โ โ (data store) โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ ThermalDrift โ โ Strategy โ โ ThermalDataStore โ
โ Simulator โ โ Classifier โ โ TF-IDF ยท 40K rowsโ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
The agent runs a tool-use loop: the model requests a tool, the ToolDispatcher executes it against the simulator, classifier, or data store, the result is fed back, and the loop repeats until the model returns a final recommendation. The model backend is pluggable โ the same loop runs against managed Bedrock or a self-hosted fine-tuned open-weight model (the LocalToolBackend translates Bedrock Converse โ OpenAI tool-calling). The data store is likewise backend-agnostic โ the local TF-IDF index can be swapped for Amazon Bedrock Knowledge Bases in production without changing the agent or tools.
HuggingFace training_data.py finetune.py quantize.py
40K dataset โโโถ SFT trace builder โโโถ QLoRA 4-bit โโโถ merge + GGUF โโโถ GGUF
(real Strategy (LoRA adapter) (Q4_K_M) served by
Classifier + Local backend
ThermalDataStore โ
grounded tool traces)
The SFT builder runs the real StrategyClassifier and ThermalDataStore to ground each training trace in genuine tool outputs (with synthesized fallbacks for unseen inputs), so the fine-tuned open-weight model learns this stack's exact tool-calling dialect โ not synthetic proxies.
40,000 synthetic thermal scenarios โ Taylor658/deep-space-optical-chip-thermal-dataset
The dataset is the agent's knowledge store: scenarios are indexed for retrieval and used to train the XGBoost classifier.
| Material | dn/dT (Kโปยน) | ฮฑ โ Thermal Expansion (Kโปยน) | Sensitivity |
|---|---|---|---|
| Silicon | 1.86 ร 10โปโด | 2.6 ร 10โปโถ | High |
| Silicon Nitride | 2.45 ร 10โปโต | 8.0 ร 10โปโท | Low |
| Polymer | 1.1 ร 10โปโด | 2.2 ร 10โปโถ | Moderate |
| Indium Phosphide | 3.4 ร 10โปโด | 4.6 ร 10โปโถ | Very High |
| Environment | Expected ฮT (K) | Severity |
|---|---|---|
| Near Earth Deep Space | 120 | |
| Mars Transit | 150 | |
| Jovian System | 180 | ๐ด High |
| Outer Solar System | 240 | ๐ด Critical |
- 4 instruments โ Spectrometer, Laser Communication Terminal, Waveguide Sensor Array, Photonic Signal Processor
- 3 strategy types โ Passive, Active, Hybrid
# Clone
git clone https://github.com/ATaylorAerospace/Thermal-Agent.git
cd Thermal-Agent
# Install
pip install -r requirements.txt
# Configure
cp .env.example .env
# โ Edit .env with your AWS credentials (Bedrock access)
# Build the agent's knowledge artifacts:
# - scenario data store (vector index)
# - XGBoost strategy classifier
bash scripts/build_index.sh
# Run the interactive app
streamlit run app/streamlit_app.pyfrom src.simulator import ThermalDriftSimulator
sim = ThermalDriftSimulator()
# Evaluate Indium Phosphide on a Jovian mission
result = sim.evaluate("Indium Phosphide", "Jovian System")
print(f"ฮn = {result['delta_n']:.6f}") # ฮn = 0.061200
print(f"Strain = {result['strain']:.2e}") # Strain = 8.28e-04
print(f"Risk: {result['risk']}") # Risk: Critical
print(f"Strategy: {result['recommended_strategy_hint']}") # Strategy: Hybridfrom src.datastore import ThermalDataStore
store = ThermalDataStore.from_huggingface() # or .load("results/thermal_datastore.pkl")
for hit in store.query("Indium Phosphide spectrometer Jovian spectral drift", top_k=3):
print(f"{hit['similarity']:.3f} {hit['instrument']} โ {hit.get('strategy_type')}")from src.strategy_classifier import StrategyClassifier
clf = StrategyClassifier()
clf.load("results/strategy_classifier.pkl")
proba = clf.predict_proba(
material="Silicon",
instrument="Spectrometer",
environment="Mars Transit",
thermal_effect="Spectral Drift",
)
print(proba)
# {'Active': 0.12, 'Hybrid': 0.61, 'Passive': 0.27}from src.agent import ThermalAgent
# Loads the data store and classifier from config/agent_config.yaml if present
agent = ThermalAgent.from_config()
result = agent.run(
"Instrument: Laser Communication Terminal\n"
"Material: Indium Phosphide\n"
"Environment: Outer Solar System\n"
"Thermal Effect: Waveguide Misalignment\n"
"What thermal mitigation strategy should be used and why?"
)
print(result["answer"]) # the grounded recommendation
print(result["tool_calls"]) # every tool the agent invoked, with inputs + results# One command โ build the data store index and train the classifier
bash scripts/build_index.shRun the same agent against a self-hosted, fine-tuned open-weight model instead of Bedrock. The point isn't to teach the model facts (the data store does that) โ it's to make a raw open-weight model a reliable, low-overhead tool-caller for this exact stack:
- Close the out-of-the-box gap โ off-the-shelf Llama 3.3 / Qwen2.5 are capable but loose at strict tool-call formatting. QLoRA bakes the call format in.
- Teach your dialect โ the SFT traces encode these tool schemas and call patterns, so the model speaks your infrastructure natively.
- Own your unit economics โ with the behavior in the weights you can strip the giant tool-description system prompt, cutting input-token overhead per inference.
# Heavy deps on a GPU host (kept out of core requirements / CI)
pip install -r requirements-finetune.txt
# 1) Build agentic tool-calling SFT data 2) QLoRA fine-tune 3) merge + GGUF quantize
bash scripts/finetune_pipeline.sh| Stage | Module | Output |
|---|---|---|
| Build SFT traces | src/training_data.py |
data/finetune/{train,validation}.jsonl |
| QLoRA fine-tune | src/finetune.py |
LoRA adapter in results/thermal-agent-lora/ |
| Merge + quantize | src/quantize.py |
results/thermal-agent.Q4_K_M.gguf |
Base model, LoRA rank, 4-bit quantization, and the GGUF quant type are all set in config/finetune_config.yaml (defaults: Llama 3.3 70B, nf4 4-bit, Q4_K_M).
Serve the GGUF behind any OpenAI-compatible endpoint (llama.cpp server, Ollama, or vLLM), then flip the provider in config/agent_config.yaml:
agent:
provider: local # bedrock | local
local:
model: thermal-agent
base_url: http://localhost:8000/v1ThermalAgent.from_config() now routes through LocalToolBackend โ the rest of the agent loop is unchanged.
Thermal-Agent/
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # GitHub Actions CI โ pytest on 3.10โ3.12
โโโ app/
โ โโโ streamlit_app.py # Interactive two-tab demo
โโโ config/
โ โโโ agent_config.yaml # Agent provider, data store, classifier paths
โ โโโ finetune_config.yaml # QLoRA + GGUF fine-tuning settings
โโโ docs/
โ โโโ thermals.png # Hero banner image
โโโ notebooks/
โ โโโ 01_eda.ipynb # Exploratory data analysis
โ โโโ 02_agent_walkthrough.ipynb # End-to-end agent walkthrough
โ โโโ 03_open_weight_finetuning.ipynb # QLoRA โ GGUF walkthrough
โโโ results/ # Model, index & adapter artifacts (gitignored)
โโโ scripts/
โ โโโ build_index.sh # Build data store + train classifier
โ โโโ finetune_pipeline.sh # Build SFT data โ QLoRA โ GGUF
โโโ src/
โ โโโ __init__.py # Public API exports
โ โโโ agent.py # Tool-use agent (pluggable backend)
โ โโโ backends.py # Local open-weight (OpenAI-compatible) backend
โ โโโ tools.py # Tool specs + dispatcher
โ โโโ datastore.py # Scenario retrieval (knowledge store)
โ โโโ training_data.py # Agentic SFT data builder
โ โโโ finetune.py # QLoRA fine-tuning (Llama 3.3 / Qwen2.5)
โ โโโ quantize.py # Adapter merge + GGUF quantization
โ โโโ simulator.py # Physics-based thermal drift engine
โ โโโ strategy_classifier.py # XGBoost Passive/Active/Hybrid
โโโ tests/
โ โโโ __init__.py # Test package init
โ โโโ test_agent.py # Agent loop tests (mocked backend)
โ โโโ test_backends.py # Local backend translation tests
โ โโโ test_tools.py # Tool dispatch tests
โ โโโ test_datastore.py # Data store retrieval tests
โ โโโ test_training_data.py # SFT data builder tests
โ โโโ test_classifier.py # Classifier tests
โ โโโ test_simulator.py # Physics simulator tests
โโโ .env.example # Credential / endpoint template
โโโ .gitignore
โโโ conftest.py # Pytest path configuration
โโโ CONTRIBUTING.md # Development setup & PR guidelines
โโโ README.md
โโโ requirements.txt # Core dependencies (agent + tests)
โโโ requirements-finetune.txt # Heavy, optional fine-tuning dependencies
Computes refractive index shift (ฮn = dn/dT ร ฮT) and mechanical strain (ฮต = ฮฑ ร ฮT) for any material-environment pair. Classifies risk as Low โ Moderate โ High โ Critical and maps to a strategy hint. Exposed to the agent as the simulate_thermal_drift tool.
Indexes the 40K HuggingFace scenarios with TF-IDF and retrieves the most similar prior cases by cosine similarity. Backend-agnostic โ swappable for Amazon Bedrock Knowledge Bases in production. Exposed as the search_thermal_knowledge tool.
Bedrock Converse tool specifications plus a ToolDispatcher that routes each tool call to the simulator, classifier, or data store. Tools backed by a missing artifact degrade gracefully.
A tool-using agent that runs a reason-act loop โ requesting tools, feeding results back, and iterating โ until it returns a grounded recommendation along with the full trace of tool calls. The model backend is pluggable (provider: bedrock | local).
๐ง Open-Weight Backend & Fine-Tuning (src/backends.py, src/training_data.py, src/finetune.py, src/quantize.py)
LocalToolBackend runs a self-hosted, QLoRA-fine-tuned Llama 3.3 / Qwen2.5 model (exported to GGUF) behind an OpenAI-compatible endpoint, translating Bedrock Converse โ OpenAI tool-calling so it drops straight into the agent loop. The fine-tuning trio builds agentic SFT traces, runs 4-bit QLoRA, and merges + quantizes the adapter to GGUF.
XGBoost classifier predicting Passive / Active / Hybrid strategies with calibrated probability estimates. Exposed as the classify_strategy tool and usable standalone.
Tests run automatically via GitHub Actions CI on every push and pull request against Python 3.10, 3.11, and 3.12.
# Run all tests locally
pytest tests/ -v
# Run a single suite
pytest tests/test_agent.py -vThe agent tests use a scripted fake Bedrock client, so the full tool-use loop is exercised without any AWS calls.
See CONTRIBUTING.md for development setup, testing instructions, and pull request guidelines.
This work is licensed under CC BY 4.0.
Copyright (c) 2026 A Taylor
Have questions, ideas, or want to collaborate? Reach out directly:
