AgriPen
An offline-capable AI advisor that turns field photographs and sensor readings into concrete agronomic decisions for smallholder farms.
- Year
- 2025
- Type
- AI decision system for agriculture
- Status
- Live
- Audience
- Smallholder farmers, agricultural cooperatives and regional agronomy advisors.

The context.
AgriPen was built for farms that operate far outside reliable connectivity, where an agronomist visit can take weeks and a misdiagnosed crop disease costs an entire season.
The system pairs a lightweight vision model running on-device with a server-side knowledge layer that reconciles local observations against regional agronomic data.
It was presented at Djazair IA — AI For Good, a side event of the African Startup Conference, under the patronage of the Ministry of Knowledge Economy.
What was actually broken.
- Disease identification depends on scarce, expensive expert visits.
- Connectivity in production areas is intermittent and often absent.
- Advice arrives days after the window for intervention has closed.
- Historical field data is kept on paper and never becomes knowledge.
Cooperatives lose yield they cannot recover, and have no auditable record of what was treated, when, and with what result.
Inference has to happen on low-end Android hardware, without network, and still stay consistent with a central knowledge base once the device reconnects.
What was engineered.
- A quantised vision model runs entirely on-device, producing a diagnosis and confidence band in under a second without any network call.
- Every observation is written to a local append-only log and synchronised opportunistically through a conflict-free merge strategy when connectivity returns.
- A server-side reasoning layer enriches raw diagnoses with regional context — season, soil profile, recent treatments — and returns a ranked intervention plan.
- Cooperative dashboards aggregate anonymised field data into early-warning signals for outbreak clusters.
Layer by layer.
Installable PWA with a full offline shell and background sync queue.
- React
- TypeScript
- Vite
- Workbox
Async API handling enrichment, sync reconciliation and advisory generation.
- FastAPI
- Python
- Pydantic
Versioned REST surface with idempotent sync endpoints and cursor pagination.
- OpenAPI
- REST
- JSON Schema
Relational core for field records, with spatial indexes on parcel geometry.
- PostgreSQL
- PostGIS
Quantised on-device model with a server fallback for low-confidence cases.
- ONNX Runtime
- PyTorch
Containerised services behind a reverse proxy with rolling deployments.
- Docker
- Nginx
- GitHub Actions
Short-lived tokens with device binding and cooperative-scoped access.
- JWT
- Argon2
- RBAC
Object storage for field imagery with lifecycle rules and signed reads.
- S3-compatible
- Signed URLs
The why behind each trade-off.
Why on-device inference instead of a cloud API?
The users who need a diagnosis most are the ones with no signal. A cloud-only design would have been an elegant system that fails exactly where it matters, so inference moved to the device and the cloud became an enrichment layer, not a dependency.
Why FastAPI?
The Python ecosystem owns the model tooling, and FastAPI gives async I/O with typed request contracts and generated OpenAPI. Schema and implementation never drift apart.
Why PostgreSQL with PostGIS?
Parcel geometry, outbreak clustering and treatment history are all relational and spatial questions. One database answers them correctly instead of three services approximating them.
Why an append-only sync log?
Devices reconnect out of order, sometimes days apart. An append-only log with deterministic merge makes reconciliation provable rather than heuristic.
What resisted.
- Performance
The first model was accurate and unusable — three seconds on target hardware. Quantisation and input-pipeline rework brought it under 900ms with a marginal accuracy cost.
- Offline support
Designing for weeks of disconnection meant treating the network as an optional enhancement everywhere in the data layer, not as a failure state to catch.
- AI limitations
Low-confidence predictions are shown as questions rather than answers. The system never presents a guess with the visual authority of a fact.
- Security
Field imagery can expose parcel location. Coordinates are coarsened before aggregation and never leave the cooperative boundary at full precision.
What it taught.
- Constraints define the architecture. The offline requirement was not a feature — it was the shape of the entire system.
- Confidence communication matters more than raw accuracy when a human acts on the output.
- A sync protocol you can reason about on paper is worth more than one that is fast in the happy path.
Measured, not claimed.
<900ms
Inference
On low-end Android hardware, offline.
21 days
Offline window
Verified continuous disconnected use.
40+
Diagnosis classes
Crop and disease combinations covered.
0
Sync conflicts
Deterministic merge across test corpus.
The system in context.


Technology stack
- React
- TypeScript
- Vite
- Tailwind CSS
- Workbox
- Python
- FastAPI
- Pydantic
- Celery
- PyTorch
- ONNX Runtime
- OpenCV
- PostgreSQL
- PostGIS
- Redis
- Docker
- Nginx
- GitHub Actions