I built this as the next step after the Edge URL Summarizer example. The URL summarizer showed a simple pattern: run an AI workflow at the edge, fetch external content when needed, summarize it, and keep useful state close to the request. This crop advisory example takes that same pattern into a more real-world workflow.
Instead of only summarizing a page, the app accepts a farmer’s field note or an agriculture advisory URL, classifies the crop issue, returns structured JSON, stores the advisory in a Stateful Actor, tracks issue/severity stats, and flags critical cases for escalation.
So the goal is not “AI gives farming advice” in a vacuum. The goal is to show how an edge-hosted AI app can turn messy field input into something operational: triage, history, stats, and a clear handoff path when a human expert needs to step in.
Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-agri-crop-advisory
What it does
You send the app a crop issue description:
curl -X POST https://edge-agri-crop-advisory-<id>.telnyxcompute.com/advisory \
-H "Content-Type: application/json" \
-d '{"description":"Tomato leaves have holes all over them. I can see green caterpillars on the underside of the leaves."}'
It returns a structured advisory:
{
"id": "adv-msf1zxyc-0",
"farmer_description": "Tomato leaves have holes...",
"source": "text",
"crop_type": "tomato",
"issue_type": "pest",
"severity": "medium",
"confidence": 0.76,
"recommendation": "Inspect the underside of leaves and remove visible caterpillars. Consider an appropriate biological or labeled treatment if damage continues.",
"escalate": false,
"generated_at": "2026-08-04T19:31:04Z"
}
If the case is critical, it gets flagged:
{
"severity": "critical",
"escalate": true,
"escalated_to": "agronomist-on-call"
}
Routes
The example includes:
-
POST /advisory- create an advisory -
GET /advisories- list recent advisories -
GET /advisories/<id>- get one advisory -
GET /stats- see issue/severity/escalation stats -
GET /health/liveness- liveness check -
GET /health/readiness- readiness check
POST /advisory accepts either:
descriptionurl
If you pass a URL, the app fetches the page, strips HTML, and uses that text as input.
The AI call
The app calls:
POST /v2/ai/chat/completions
The current code path uses:
zai-org/GLM-5.2
The prompt asks the model to return JSON only with:
crop_typeissue_typeseverityconfidencerecommendation
Issue types are constrained to:
disease | pest | nutrient | water | weather | unknown
Severity is constrained to:
low | medium | high | critical
That structure makes the response easier to store, display, route, and review.
The Stateful Actor part
The app uses a CropAdvisory Stateful Actor.
It stores:
- advisories by ID
- total advisory count
- counts by issue type
- counts by severity
- escalation count
- recent crop types
So after a few requests, you can inspect the accumulated stats:
curl https://edge-agri-crop-advisory-<id>.telnyxcompute.com/stats
Run it
Clone the repo:
git clone https://github.com/team-telnyx/telnyx-code-examples.git
cd telnyx-code-examples/edge-agri-crop-advisory
Set your Telnyx API key:
telnyx-edge auth api-key set <YOUR_API_KEY>
telnyx-edge secrets add TELNYX_API_KEY "KEY0123..."
Install and deploy:
npm install
telnyx-edge ship
Health check:
curl -sS --retry 30 --retry-delay 5 \
https://edge-agri-crop-advisory-<id>.telnyxcompute.com/health/liveness
Create an advisory:
curl -X POST https://edge-agri-crop-advisory-<id>.telnyxcompute.com/advisory \
-H "Content-Type: application/json" \
-d '{"description":"My corn has yellow streaks on bottom leaves with dark brown spots. About 30% of plants affected."}'
Production notes
This is a triage example, not a replacement for an agronomist.
Before using this pattern in production, I would add:
- authentication
- farmer/account identity
- region and crop stage
- photo input
- weather data
- human review for high and critical cases
- localized treatment guidance
- safety warnings
- SMS or webhook escalation
Still, the pattern is useful: edge function for intake, AI model for structured classification, Stateful Actor for advisory history and stats.
Resources:
- Code: https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-agri-crop-advisory
- Stateful Actors Quick Start: https://developers.telnyx.com/docs/edge-compute/stateful-actors/quick-start
- Telnyx AI Inference docs: https://developers.telnyx.com/docs/inference
- Chat Completions API: https://developers.telnyx.com/api/inference/chat-completions
- Telnyx AI skills and toolkits: https://github.com/team-telnyx/ai
Top comments (0)