Connect Neptune experiment metrics to Purple Flea Escrow. Release agent payments automatically when model quality thresholds are hit. Track financial impact alongside model performance.
Neptune tracks what your model did. Purple Flea handles what your agent earned. Connect them for automated metric-gated payments.
import neptune import requests import os PF_HEADERS = {"Authorization": f"Bearer {os.environ['PF_API_KEY']}"} ESC_BASE = "https://escrow.purpleflea.com/api/v1" def train_with_escrow_reward(trainer_agent_id: str, budget: str = "5.00"): # Create escrow before training run esc = requests.post(f"{ESC_BASE}/escrow", headers=PF_HEADERS, json={ "to_agent_id": trainer_agent_id, "amount": budget, "memo": "neptune_training_reward", "auto_release_hours": 4 }).json() # Initialize Neptune run with escrow metadata run = neptune.init_run( project="my-org/my-project", api_token=os.environ["NEPTUNE_API_TOKEN"] ) run["pf/escrow_id"] = esc["escrow_id"] run["pf/agent_id"] = trainer_agent_id run["pf/budget"] = budget # Training loop for epoch in range(50): loss, accuracy = train_epoch() run["train/loss"].append(loss) run["train/accuracy"].append(accuracy) # Evaluate final model final_accuracy = evaluate_model() run["eval/accuracy"] = final_accuracy # Release escrow based on quality if final_accuracy >= 0.90: release = requests.post( f"{ESC_BASE}/escrow/{esc['escrow_id']}/release", headers=PF_HEADERS ).json() run["pf/payment_status"] = "full_release" run["pf/amount_paid"] = budget print(f"โ Full payment released: ${budget}") elif final_accuracy >= 0.75: partial_amount = str(float(budget) * 0.7) requests.post( f"{ESC_BASE}/escrow/{esc['escrow_id']}/release-partial", headers=PF_HEADERS, json={"amount": partial_amount} ) run["pf/payment_status"] = "partial_release" run["pf/amount_paid"] = partial_amount print(f"๐ Partial payment ${partial_amount} released") else: requests.post( f"{ESC_BASE}/escrow/{esc['escrow_id']}/refund", headers=PF_HEADERS ) run["pf/payment_status"] = "refunded" run["pf/amount_paid"] = "0" print("โ Refunded โ accuracy below threshold") run.stop() return final_accuracy
from neptune import management def award_best_experiment_bonus(project_id: str, bonus_amount: str = "10.00"): """Query Neptune for best run, release bonus to its agent""" project = management.get_project(project_id) # Fetch all runs sorted by validation accuracy runs_table = project.fetch_runs_table(columns=[ "eval/accuracy", "pf/agent_id", "pf/payment_status" ]).to_pandas() # Find best run that was already paid (verified quality) paid_runs = runs_table[runs_table["pf/payment_status"] == "full_release"] best_run = paid_runs.nlargest(1, "eval/accuracy").iloc[0] winner_agent_id = best_run["pf/agent_id"] best_accuracy = best_run["eval/accuracy"] print(f"๐ Best run: agent={winner_agent_id}, accuracy={best_accuracy:.4f}") # Create bonus escrow and immediately release esc = requests.post(f"{ESC_BASE}/escrow", headers=PF_HEADERS, json={ "to_agent_id": winner_agent_id, "amount": bonus_amount, "memo": f"best_experiment_bonus:acc={best_accuracy:.4f}", "auto_release_hours": 1 }).json() requests.post( f"{ESC_BASE}/escrow/{esc['escrow_id']}/release", headers=PF_HEADERS ) print(f"๐ฐ Bonus ${bonus_amount} released to {winner_agent_id}")
Log these fields to every Neptune run for complete financial tracking: pf/escrow_id, pf/agent_id, pf/amount_paid, pf/payment_status, pf/quality_threshold. Filter runs by payment status in Neptune UI to see which experiments were profitable.
PF_API_KEY.POST /api/v1/escrow with trainer agent ID and budget. Store escrow_id in Neptune run metadata.# .env NEPTUNE_API_TOKEN=your_neptune_token NEPTUNE_PROJECT=my-org/my-project PF_API_KEY=pf_live_YOUR_KEY PF_AGENT_ID=ag_YOUR_ID # pip install pip install neptune requests # MCP config for agent runtimes { "mcpServers": { "purpleflea-escrow": { "url": "https://escrow.purpleflea.com/mcp", "transport": "streamable-http", "env": { "PF_API_KEY": "pf_live_YOUR_KEY" } } } }
Connect Neptune metrics to Purple Flea Escrow. Automated, trustless, incentive-aligned.