Repository navigation
OpenTea DX-OS v1.14.0
The agentic layer arrives. One AI agent per cooperative reviews pending journal entries and proposes; a manager or officer approves on the web or from Telegram, and every step is in the audit chain. A cooperative can switch an agent to Claude or OpenAI within a monthly budget, with personal data masked first. Staff work gains automation and AI-ranked suggestions, and a sensor station simulator joins the repository.
Added
- Agentic layer milestone M3: external LLM providers (
platform/agent,apps/web,docker): a manager can switch each agent of the cooperative (A1 journal review, A6 digest) from the local Ollama to Claude (Anthropic) or OpenAI on a new settings page (/manager/ai/settings, read only for officers), with a confirmation that lists what leaves the server; only providers whose key the agent container holds are offered, and every change is audited. The agent calls both APIs over plain HTTP from the standard library, masks phone numbers, e-mails and identity numbers before any external call, and falls back to Ollama, then to the rules, on any failure (cut network, 5xx, timeout, refusal, malformed output; a 429 pauses the provider for at least 60 s). Runs report provider, model, tokens and estimated cost; a run that called an external provider writes oneagent.external_callaudit event without content. A monthly budget per cooperative warns the managers at 80% and stops external calls at 100% until the Vietnam month ends (Telegram message once per threshold and month, banner in the inbox). A6 sends the daily report at the cooperative's report time. The keys (ANTHROPIC_API_KEY,OPENAI_API_KEY, optionalDXOS_ANTHROPIC_MODEL,DXOS_OPENAI_MODEL) reach onlydxos-agent; a test-only LLM stub (profilellm-test) andplatform/tests/smoke-llm.shcover the path in CI. - Agentic layer milestone M2: Telegram (
platform/telegram,apps/web,platform/agent,workflows):dxos-telegramrelays Telegram updates to the web and sends what the web queues (long polling, no public address needed; idle when no bot token is set). People link their account from their profile page with a one-time code (/start <code>,/stop); a manager can link the cooperative's group for reports. Proposals reach linked approvers with Approve and Reject buttons signed by the web (callback_dataHMAC, private chats only, roles re-checked with Keycloak at the moment of the tap); a rejection asks for a reason; every message of a proposal is edited to show who decided. The agent posts daily (18:00) and weekly (Monday 07:00) figures that the web renders and sends; health alerts cover stale agent or relay heartbeats, repeated agent failures and n8n failures, recorded by the newworkflows/system-error-alert.json(set aserrorWorkflowof every workflow). New:./dxos telegram enable|disable, realm roletelegram, tables inplatform/postgres/init/09-telegram.sql, a stub Bot API andplatform/tests/smoke-telegram.sh. SetTELEGRAM_BOT_TOKEN,TELEGRAM_BOT_USERNAMEand, for a release,DXOS_TELEGRAM_CALLBACK_KEYindocker/.env.local. - Tea IoT Station (
apps/tea-iot): a WPF sensor station simulator for tea hills that publishes soil moisture, soil and air temperature, air humidity and rainfall to the core broker (htx/<HTX>/plot/<parcel>/<sensor>, QoS 1, store and forward while offline), with drought, heavy rain, frost and faulty-sensor scenarios. Field alerts (dry soil, frost, heat) become task suggestions in Tea Staff Manager.apps/tea-iot/docker/mqtt-port.override.ymlpublishes the broker on 127.0.0.1 for local development. - Tea Staff Manager 1.3.0: Automation page (recurring work, cover for rejected work and approved leave, forgotten check-outs, overdue warnings, draft payroll), an explainable ranking of who fits a task shown with its facts,
POST /api/iot/alerts, and Tea Work sign-in with the shared Keycloak account. Tea Work 1.2.0 documents the shared account on its sign-in screen. - Agentic layer milestone M1c (
platform/agent, APISIX,docker/docker-compose.yml): implemented stdlib-onlydxos-agentruntime modules: cross-language canonical JSON + SHA-256evidence.py, schema-validated LLM provider abstraction with 1-retry JSON repair (ReplayProviderandOllamaProviderwith>= 60sHTTP 429 backoff over dedicated APISIX route/api/internal/agent/llm/v1/chat/completions), Keycloak/Hasura/internal-API client, Agent A1journal-reviewwith deterministic farming hard rules (WITHDRAWAL_PERIOD,MISSING_INFO,DOSAGE,INCONSISTENT), prompt-injection resistance, rule-based fallback on LLM outage, andplatform/agent/tests/scenarios/a1_journal_review.jsonscenario tests. - Agentic layer milestone M1b (
dxos, Keycloak, Hasura, APISIX,apps/web): added realm roleagentand./dxos agent enable|disable <HTX>to provision/revoke per-cooperative Keycloak client-credentials clients (dxos-agent-<htx>with mode-600 runtime env files), read-only zero-PII Hasuraagentpermissions across cooperative tables, internal-only APISIX:9081route/api/internal/agent/*injectingX-Dxos-Gatewayafter claim validation, RS256 JWKS verification + internal run/proposal ingestion routes inapps/web, Jest unit/route tests, andplatform/tests/smoke-agent.shboundary smoke checks. - Agentic layer milestone M1a (
apps/web,platform/postgres/init/08-agent.sql): addedplatform.agent_runs,platform.agent_proposals(withagent_proposals_one_openpartial unique index), andplatform.agent_settingswith row-level audit triggers; typed action catalogue (journal.approve,journal.reject), canonical evidence hashing, proposal creation and single-execution claim/decision use cases with audit trail, HTTP routes (/api/agent/proposals,/api/agent/proposals/[id]/decision,/api/journal/[id]/review),journal_entries.review_notemigration, and theProposalInboxUI at/manager/aiand/officer/ai. - Agentic layer milestone M0 skeletons (
platform/agent,platform/telegram): stdlib-only heartbeat skeleton containers (dxos-agent,dxos-telegram) added todocker/docker-compose.yml,docker/docker-compose.release.yml,Makefile(make up-agent,stop-extras,platform-up), CI unit test jobs, and release/edge image matrices. They start and report health without running agents or connecting to Telegram yet. - Architecture Decision Records: ADR 0003 (agentic layer with human approval and trust-zone separation) and ADR 0004 (optional external LLM providers with local-first fallback).
- Mini-app
hub-mobile(miniapps/hub-mobile): a card in the app store and an open page (/public/<htxCode>) with the download link of the Android APK and the steps to add the web build to an iPhone home screen. Links come fromHUB_APK_URLandHUB_WEB_URL; the app stores and reads nothing. The 67 MB APK itself is not in the repository.
Changed
- Web package version
1.14.0. - Agent credentials (
./dxos agent enable|disable,docker/docker-compose.yml): the per-cooperative credentials now live in thedxos-agent-envvolume, written by a short-lived root helper that receives them on stdin and stores them as uid 10001, so the agent can read them on Linux. Upgrade note: run./dxos agent enable <HTX>once for every cooperative that had the agent enabled; the old files underdocker/runtime/<project>/agent/are no longer read.enablenow refuses a cooperative that does not exist. - Agent evidence version 2 (
apps/web,platform/agent): proposals carry every column the rules read (journal entry, its activities and the crop cycles compared), hashed with one canonical JSON shared by TypeScript and Python (platform/agent/tests/fixtures/evidence-vectors.json). Open proposals made with version 1 answer stale on decision. - Agent schedule (
platform/agent): journal review runs on the first cycle, when the pending entries change, or hourly between 06:00 and 20:00 Vietnam time; an empty queue no longer writes a run row. Out-of-range dosage and a missing withdrawal period now ask for a correction (REQUEST_CHANGES) instead of a rejection. Thresholds are documented indocs/rules-and-limits.md§3.8. - Proposal dedupe (
apps/web,08-agent.sql): duplicates are judged by the journal entries a proposal acts on (subject_ids), not by the key the agent sends. - Release override: the web and APISIX refuse to start when
DXOS_INTERNAL_GATEWAY_SECRETis missing or still the public development value. docs/rules-and-limits.md: amended §1.1 (AI Principle Invariant) and §1.2 (MNM Invariant) per milestone M0 to permit typed catalogue action proposals (with human approval in normal mode, or manager-enabled bounded autonomous mode) and optional per-cooperative external LLM providers while keeping local Ollama as the zero-key default.
Fixed
-
Telegram messages for proposals, reports and alerts (
PrismaTelegramRepository): the link and outbox column lists were plain strings inside$queryRawtemplates, so Prisma sent them as a bound value; recipients came back without a chat id and queuing a message failed. They are SQL fragments now, checked by a unit test and against a real Postgres. -
Mosquitto restart loop: on kernels with
fs.protected_regular(including WSL 2) a restarted broker container failed with "can't create /tmp/mosquitto.passwd: Permission denied"; the entrypoint now removes the old password file first. -
The PostgreSQL scripts of the staff app (
apps/staff-desktop/database/postgres) were hidden by the root*.sqlignore rule. -
Withdrawal checks fail closed (
approve-harvest,CreateLotUseCase, lot trace, farmer dashboard): spraying recorded in a rejected, returned or pending journal entry still blocks harvest approval, lot creation and QR export; only drafts are ignored. Without this, rejecting a journal through the new review flow would have hidden a real spray from the withdrawal period. -
Agent A1 withdrawal rule: compares Vietnam calendar days (a harvest on the spraying day is a violation, a harvest on the safe day is allowed) instead of UTC timestamps; the invented 7-day minimum is removed; Vietnamese numbers such as "1.200 ml" and "0,5 kg" are read correctly.
-
Agent tokens limited to their routes (APISIX): tokens of the
agentrole are refused on the workflow, disease and chat LLM routes; the internal agent route is rate-limited per token. -
Proposal creation checks: evidence values must match their hashes, referenced rows must belong to the caller's cooperative, at most 50 rows, known agent names only, bounded body size.
-
Journal review races: review and batch approval change only entries that are still pending and record the reviewer; a returned or rejected entry can be edited and goes back to pending.
-
Agent containers:
dxos-agentanddxos-telegramrun read-only, without capabilities, with process and CPU limits;08-agent.sqlis mounted for fresh databases. -
Agent resilience: provider failures of any kind fall back to rule-only reasons, HTTP 429 no longer blocks the agent loop, and one malformed credentials file or journal entry no longer stops the others.
-
Journal reject/request-changes flow (
officer-journal-approval.tsx,POST /api/journal/[id]/review): officer "Từ chối" / "Yêu cầu sửa" actions previously posted ignoredisApproved/rejectionReasonfields to/api/journal/batch-approveand approved the entry; they now invoke the dedicated review endpoint, recordreview_note, and keep rejected entries out ofAPPROVED.
Upgrade notes
- Set
DXOS_INTERNAL_GATEWAY_SECRETandDXOS_TELEGRAM_CALLBACK_KEYindocker/.env.localto long random values. With the release override the web does not start while either is missing or still the development value, and APISIX does not start without the first. make platform-up, thenmake web-up: the first creates the agent and Telegram tables (08-agent.sql,09-telegram.sql), applies the database migrations and startsdxos-agentanddxos-telegram; the second rebuilds the web app at1.14.0. No data migration.- AI layer:
./dxos agent enable <HTX>for each cooperative that should get it; the running agent picks it up on its next cycle, and the command creates the realm roleagentwhen it is missing (on a smaller stack,make up-agentstarts the agent). A cooperative enabled frommainbefore this release runsenableonce more: the credentials moved to thedxos-agent-envvolume. - Telegram (optional): set
TELEGRAM_BOT_TOKENandTELEGRAM_BOT_USERNAMEfrom BotFather, run./dxos telegram enable, then link a phone from the profile page. - External LLM providers (optional): set
ANTHROPIC_API_KEY(andDXOS_ANTHROPIC_MODELto change the defaultclaude-haiku-5-5) orOPENAI_API_KEYwithDXOS_OPENAI_MODEL, restartdxos-agent, then choose the provider for an agent on/manager/ai/settings. Without a key everything runs on Ollama as before. - n8n: import the workflows again (
n8n import:workflow, seedocs/dev-setup.md); every workflow now namesworkflows/system-error-alert.jsonas its error workflow, so failures reach managers. - Withdrawal checks now count every journal entry that is not a draft: a harvest or a lot that passed before because the spraying entry was rejected, returned or pending is blocked until the withdrawal period ends. Open AI proposals made before the upgrade answer stale when decided.
- Tea Staff Manager's shared sign-in needs a Keycloak client created by hand: see
apps/staff-desktop/docs/core-integration.md.
Known limits
- The withdrawal checks read at most 100 journal entries of a parcel (issue #67).
- A farmer cannot yet edit a returned journal entry from the web form (issue #68).
- Telegram delivery is at least once: a message can arrive twice if the relay stops between Telegram's answer and reporting it.
- With an external provider, names a farmer writes inside a note are not masked; the confirmation on the settings page says so. Costs are estimated from a small price table in code; a model not in the table counts as 0.
- The browser checks of
app-kit.spec.tscan fail on a frame that is still navigating (issue #44); a failedPlatform Smoke Testjob on that spec is re-run.
Container images
ghcr.io/maiychrus25/opentea-dx-os-web:1.14.0ghcr.io/maiychrus25/opentea-dx-os-api:1.14.0ghcr.io/maiychrus25/opentea-dx-os-postgres:1.14.0ghcr.io/maiychrus25/opentea-dx-os-scanner:1.14.0ghcr.io/maiychrus25/opentea-dx-os-migrate:1.14.0ghcr.io/maiychrus25/opentea-dx-os-dataops:1.14.0ghcr.io/maiychrus25/opentea-dx-os-agent:1.14.0ghcr.io/maiychrus25/opentea-dx-os-telegram:1.14.0
Deploy
Download opentea-dx-os-1.14.0.tar.gz, verify it with SHA256SUMS, then follow the
release deployment guide (6-step order: postgres, platform-init, migrate, platform-init again, rest, then --profile tools run --rm ollama-init to pull the pinned LLM model).
Set DXOS_MQTT_DEVICES and DXOS_MQTT_INGEST_PASSWORD in docker/.env.local first: the broker refuses to start while any MQTT password begins with change_me.
Optional: set ANTHROPIC_API_KEY or OPENAI_API_KEY in docker/.env.local to let an agent use an external provider (ADR 0004). Empty keys keep every agent on Ollama, and only dxos-agent receives them.
Also set MINIO_ACCESS_KEY, MINIO_SECRET_KEY (SeaweedFS refuses placeholders), KEYCLOAK_ADMIN, KEYCLOAK_ADMIN_PASSWORD and DXOS_INTERNAL_GATEWAY_SECRET (a long random value: the web and the gateway refuse to start while it is empty or the public dev default), DXOS_TELEGRAM_CALLBACK_KEY (a long random value: the web refuses to start while it is empty or the dev default), and run every command as docker compose --env-file docker/.env.local -f docker/docker-compose.yml -f docker/docker-compose.release.yml ..., otherwise Compose ignores those values.