repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Low Compute Mode |
| #3 | * |
| #4 | * Manages transitions between survival tiers. |
| #5 | * When credits run low, the automaton enters increasingly restricted modes. |
| #6 | */ |
| #7 | |
| #8 | import type { |
| #9 | AutomatonConfig, |
| #10 | AutomatonDatabase, |
| #11 | InferenceClient, |
| #12 | SurvivalTier, |
| #13 | } from "../types.js"; |
| #14 | |
| #15 | export interface ModeTransition { |
| #16 | from: SurvivalTier; |
| #17 | to: SurvivalTier; |
| #18 | timestamp: string; |
| #19 | creditsCents: number; |
| #20 | } |
| #21 | |
| #22 | /** |
| #23 | * Apply survival tier restrictions to the automaton. |
| #24 | */ |
| #25 | export function applyTierRestrictions( |
| #26 | tier: SurvivalTier, |
| #27 | inference: InferenceClient, |
| #28 | db: AutomatonDatabase, |
| #29 | ): void { |
| #30 | switch (tier) { |
| #31 | case "normal": |
| #32 | inference.setLowComputeMode(false); |
| #33 | break; |
| #34 | |
| #35 | case "low_compute": |
| #36 | // Switch to cheaper model, slower heartbeat |
| #37 | inference.setLowComputeMode(true); |
| #38 | break; |
| #39 | |
| #40 | case "critical": |
| #41 | // Cheapest model, minimal operations |
| #42 | inference.setLowComputeMode(true); |
| #43 | break; |
| #44 | |
| #45 | case "dead": |
| #46 | // No inference at all. Heartbeat only. |
| #47 | inference.setLowComputeMode(true); |
| #48 | break; |
| #49 | } |
| #50 | |
| #51 | db.setKV("current_tier", tier); |
| #52 | } |
| #53 | |
| #54 | /** |
| #55 | * Record a tier transition. |
| #56 | */ |
| #57 | export function recordTransition( |
| #58 | db: AutomatonDatabase, |
| #59 | from: SurvivalTier, |
| #60 | to: SurvivalTier, |
| #61 | creditsCents: number, |
| #62 | ): ModeTransition { |
| #63 | const transition: ModeTransition = { |
| #64 | from, |
| #65 | to, |
| #66 | timestamp: new Date().toISOString(), |
| #67 | creditsCents, |
| #68 | }; |
| #69 | |
| #70 | // Store transition history |
| #71 | const historyStr = db.getKV("tier_transitions") || "[]"; |
| #72 | const history: ModeTransition[] = JSON.parse(historyStr); |
| #73 | history.push(transition); |
| #74 | |
| #75 | // Keep last 50 transitions |
| #76 | if (history.length > 50) { |
| #77 | history.splice(0, history.length - 50); |
| #78 | } |
| #79 | |
| #80 | db.setKV("tier_transitions", JSON.stringify(history)); |
| #81 | |
| #82 | return transition; |
| #83 | } |
| #84 | |
| #85 | /** |
| #86 | * Check if the agent should be allowed to run inference in current tier. |
| #87 | */ |
| #88 | export function canRunInference(tier: SurvivalTier): boolean { |
| #89 | return tier === "normal" || tier === "low_compute" || tier === "critical"; |
| #90 | } |
| #91 | |
| #92 | /** |
| #93 | * Get the model to use for the current tier. |
| #94 | */ |
| #95 | export function getModelForTier( |
| #96 | tier: SurvivalTier, |
| #97 | defaultModel: string, |
| #98 | ): string { |
| #99 | switch (tier) { |
| #100 | case "normal": |
| #101 | return defaultModel; |
| #102 | case "low_compute": |
| #103 | return "gpt-4o-mini"; |
| #104 | case "critical": |
| #105 | return "gpt-4o-mini"; |
| #106 | case "dead": |
| #107 | return "gpt-4o-mini"; // Won't be used, but just in case |
| #108 | } |
| #109 | } |
| #110 |