Skip to content

๐ŸŒก๏ธ Ambient Intelligence โ€‹

Flows that sense the device's physical state โ€” battery, network quality, CPU pressure โ€” and dynamically adapt their behavior.
100%
4g
Low
flow.execute()
Standard Execution

The Concept โ€‹

A heavy data sync shouldn't drain a dying phone. A large payload shouldn't be fetched on 2G. Ambient Intelligence makes flows device-aware.

Quick Start โ€‹

ts
const { data, execute } = useFlow(syncHeavyData, {
  ambient: {
    enabled: true,
    rules: {
      lowBattery: { below: 15, action: "defer" },
      slowNetwork: { below: "2g", action: "compress" },
      highCPU: { above: 80, action: "throttle" },
    },
    onAdapt: (adaptation) => {
      toast.info(`Flow adapted: ${adaptation.reason}`);
    },
  },
});

Device Sensors โ€‹

SensorAPI UsedFallback
Batterynavigator.getBattery()Ignored if unavailable
Networknavigator.connection.effectiveTypeIgnored if unavailable
CPU LoadFrame rate monitoring via requestAnimationFrameEstimated from FPS drop
Memoryperformance.measureUserAgentSpecificMemory()Not available on all browsers

Adaptation Actions โ€‹

ActionBehavior
deferQueue execution for later when conditions improve
compressRequest compressed/minimal payload variant
throttleReduce polling frequency and concurrency
purgeAggressively clear cache to free memory
skipSkip execution entirely

API Reference โ€‹

AmbientSensor โ€‹

ts
import { AmbientSensor } from "@asyncflowstate/core";

const sensor = AmbientSensor.getInstance();
const state = sensor.getState();
// { battery: 23, charging: false, networkType: '4g', estimatedCPU: 15, ... }

The sensor is a singleton that monitors device state globally โ€” it's shared across all flows.

Built with by AsyncFlowState Contributors
Open Source ยท MIT License