# Dear Farm — external agent API Dear Farm is a farm record: farms, plots, plants, activity logs, notes, a calendar, expenses and a knowledge graph the app's own agent maintains. This API lets an agent running somewhere else read that record and add to it on a farmer's behalf. You need one thing: a key the farmer issues from Settings -> External Agents. Send it as the "x-agent-key" header on every call, or as "Authorization: Bearer " if that is what your client sends — both are read. The key pins who you act as; there is no user id to send. Base URL: https://www.dear.farm ## Start here 1. GET https://www.dear.farm/api/agent/tools with your key. That tells you your agent name, the scopes you hold, and every tool with its arguments — including the ones you cannot call, so you can ask for the permission you need. 2. Call get_farms. Almost everything else takes a farm_id. 3. If you hold memory:request, GET /api/agent/memory/request once to read the reporting contract before you report anything. ## The rules 1. YOU CANNOT WRITE THE MIND The Mind is Dear Farm's own agent's knowledge graph, and that agent is its only author. No scope grants a write, and no tool that performs one is callable — the endpoint answers 'unknown tool' whatever your key holds. What you can do is REPORT: POST /api/agent/memory/request with a plain-language observation, and that agent decides whether to keep it, how to key it and how to link it. You propose; it disposes. 2. THERE IS NO APPROVAL STEP HERE Inside the app, every write an agent proposes is a card the farmer clicks to accept. This endpoint has no card and no UI to draw one in, so a write lands the moment you call it. Do not tell the farmer something is 'awaiting approval' — it is already done. Confirm with them BEFORE you call a write tool, not after. 3. YOU ACT AS ONE PERSON, AND ONLY AS THEM Your key is pinned to one user in one organization at one role. Identity is never read from the request body, so there is nothing you can send that makes a call act as somebody else. Everything you read and write is what that person can read and write. 4. NOTHING REACHES SETTINGS No tool changes account settings, permissions, billing, or who the agent is. The agent's personality is a settings change and a Mind write at once, and is withheld on both counts. 5. DELETES ARE MOSTLY SOFT, AND THERE IS NO UNDO HERE Deleting a plot, plant, note or activity log hides it from every read rather than destroying it — but no tool here brings it back. Calendar events are the exception: those are removed outright. Prefer an edit over a delete when the farmer means 'this changed' rather than 'this never happened'. ## Authentication Header: x-agent-key: or: Authorization: Bearer Either is accepted and they are the same credential. Prefer the first — it is what the contract documents — but if your client only knows how to send a bearer token, that works and nothing else needs configuring. Keys look like df_ followed by random characters. They are shown once when issued and cannot be recovered — if one is lost, the farmer revokes it and issues another. Revocation takes effect immediately. A 401 body says which failure it was: "no_key" (nothing presented), "wrong_auth_scheme" (an Authorization header that is not Bearer) or "unknown_key" (presented but not recognised — mistyped, truncated or revoked). 403 names the scope you are missing. 400 means your arguments were wrong and says how. ## Scopes A key holds some of these. They only ever subtract: a key can never do more than the person it acts as. - identity:read — Resolve a phone number to a user and organization. Needed only by an agent that receives messages from numbers it must match to accounts — a key that already acts as one person does not need this. - farm:read — Farms, plots, plants, activity, notes, calendar, weather, catalog, attachments and stats — for the farms this key's user can reach. Read-only and repeatable; nothing here consumes anything. - farm:write — Create, update AND DELETE plots, plants, activity logs, notes and calendar events, and edit farm details. Writes land immediately — there is no approval step on this endpoint, so the guest must confirm with the farmer itself. Deletes are soft except calendar events, which are removed outright. - expenses — Read and write expenses, and extract them from uploaded receipts. New expenses land as drafts for the farmer to confirm. - attachments — Upload photos, PDFs and documents, and attach them to records. - messages — Send message history into the app's message log. This is for an agent that fronts a messaging channel — a guest that talks to the farmer somewhere else does not need it. - events:consume — Poll the queue of things that happened in the app. GRANT THIS TO EXACTLY ONE AGENT. Reading DRAINS it — each event is delivered once, to whichever caller asks first — so a second holder does not see the same events, it silently steals them, and the first agent simply stops hearing about things with no error anywhere. The queue is also organization-wide rather than farm-scoped: its rows carry no farm id, so its summaries name farms outside this key's farm access. - memory:read — Read the knowledge graph, research reports, and the agent's composed system prompt. - memory:request — Report something learned elsewhere. Dear Farm's agent decides whether to record it, how to key it and how to link it. No external key can write the Mind directly — this is the only road in. Retired and no longer grantable: memory:write, memory:destructive. See rule 1. ## Endpoints GET /api/agent/tools [any scope] What this key can do. Returns every tool with its parameters and whether this key holds the scope for it — tools it cannot call are listed too, so the agent can ask the farmer for the right permission instead of guessing. POST /api/agent/tools [any scope] Run one tool. Body: { tool, input }. The scope required depends on the tool. GET /api/agent/memory [memory:read] The knowledge graph as nodes and edges, for display. Add ?summary=true for prose instead. GET /api/agent/memory/request [memory:request] The reporting contract — what is worth reporting to the Mind and what is not. Read this once at session start. POST /api/agent/memory/request [memory:request] Report something you learned. Body: { observation }. Dear Farm's own agent decides whether to record it. This is the ONLY way anything external reaches the Mind. POST /api/agent/upload [attachments] Upload a file as base64 and attach it to a record. Body: { file_base64, filename, content_type, entity_type, entity_id } — or set create_note: true with farm_id to file it onto a new note. POST /api/agent/messages [messages] Push message history into the app's message log. For an agent that fronts a messaging channel. GET /api/agent/lookup [identity:read] Resolve ?phone= to a user and organization. Only useful to an agent that must match inbound numbers to accounts. GET /api/agent/openapi [public] This contract as an OpenAPI 3.1 document, including every tool's argument schema. Public — no key needed. ## Tools Call a tool with: POST https://www.dear.farm/api/agent/tools x-agent-key: Content-Type: application/json { "tool": "get_farms", "input": {} } The response is { "result": ... }. A tool that fails validation inside the tool layer answers 200 with an "error" field on the result — read it, it says what to fix. get_farms [farm:read] List every farm this key can reach, with id, name, address, size in acres and notes. Start here — most other tools need a farm_id. (no arguments) update_farm [farm:write] (WRITES) Edit a farm's name, address or notes. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. farm_id (string, required, uuid) — The farm to edit. name (string) — New name. Omit to leave unchanged. address (string) — New address. Omit to leave unchanged. notes (string) — New notes. Omit to leave unchanged. get_plots [farm:read] List the plots on one farm. farm_id (string, required, uuid) — The farm whose plots to list. create_plot [farm:write] (WRITES) Create a plot on a farm. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. farm_id (string, required, uuid) — The farm to create the plot on. name (string, required) — Plot name, e.g. 'North terrace'. description (string) — Free text about the plot. crop_type (string) — What is grown here, e.g. 'coffee'. variety (string) — Cultivar or variety. plant_count (number) — How many plants the plot holds. water_schedule (string) — Free text, e.g. 'drip, alternate days'. hardiness_zone (string) — USDA-style zone string. soil_type (string) — Free text, e.g. 'red laterite'. update_plot [farm:write] (WRITES) Edit a plot. Every field is optional; omitted fields are left alone. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. plot_id (string, required, uuid) — The plot to edit. name (string) — New name. description (string) — New description. Send an empty string to clear it. crop_type (string) — New crop type. variety (string) — New variety. plant_count (number) — New plant count. delete_plot [farm:write] (WRITES) Delete a plot. The delete is soft — the record is hidden from every read, not destroyed — but there is no tool here to bring it back. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. plot_id (string, required, uuid) — The plot to delete. get_plants [farm:read] List the plants on one farm. farm_id (string, required, uuid) — The farm whose plants to list. create_plant [farm:write] (WRITES) Record a plant (or a group of plants) on a farm. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. farm_id (string, required, uuid) — The farm the plant is on. plot_id (string, uuid) — Attach to a specific plot. Omit for farm level. label (string, required) — How the farmer refers to it, e.g. 'Row 4 arabica'. crop_catalog_id (string, uuid) — Link to a catalog entry. Find one with search_catalog first — it fills in the botany. common_name (string) — Common name, if not using the catalog. scientific_name (string) — Binomial name, if not using the catalog. variety (string) — Cultivar or variety. plant_category (string) — Botanical category. One of: tree, shrub, vine, herb, grass, ground_cover, succulent, fern, aquatic, leafy_green, root_vegetable, fruit, legume, grain_cereal, flower_ornamental. lifecycle_type (string) — How long the plant lives. One of: annual, biennial, perennial. quantity (number, default 1) — How many plants this record stands for. planted_date (string, date) — When it went in the ground (YYYY-MM-DD). health_status (string, default healthy) — Current condition. One of: healthy, stressed, diseased, dormant, dead, removed. growth_stage (string) — Where it is in its life. One of: seedling, juvenile, mature, fruiting, senescent. notes (string) — Free text about this plant. update_plant [farm:write] (WRITES) Edit a plant. Use this to record a change in health or growth stage — it is the most common write after an inspection. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. plant_id (string, required, uuid) — The plant to edit. label (string) — New label. health_status (string) — New condition. One of: healthy, stressed, diseased, dormant, dead, removed. growth_stage (string) — New growth stage. One of: seedling, juvenile, mature, fruiting, senescent. quantity (number) — New count. notes (string) — New notes. Send an empty string to clear them. delete_plant [farm:write] (WRITES) Delete a plant record. Soft, like every delete here. If a plant died, prefer update_plant with health_status 'dead' — that keeps the history. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. plant_id (string, required, uuid) — The plant to delete. get_recent_activity [farm:read] The most recent activity logs on a farm, newest first. farm_id (string, required, uuid) — The farm whose activity to read. limit (number, default 10) — How many entries to return. get_activity_types [farm:read] The activity type vocabulary for this organization — slug, label, group and colour. Call this before create_activity_log to get a valid log_type slug. (no arguments) create_activity_log [farm:write] (WRITES) Log something that was done on the farm — watering, pruning, spraying, a harvest. This is the right home for transient events; do not report them to the Mind. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. farm_id (string, required, uuid) — The farm the work happened on. title (string, required) — Short description of the work, e.g. 'Pruned north block'. plot_id (string, uuid) — Attach to a specific plot. Omit for farm level. notes (string) — Longer detail. log_date (string, date, default today) — When the work happened (YYYY-MM-DD). end_date (string, date) — For work spanning days, the last day (YYYY-MM-DD). log_type (string) — An activity type slug from get_activity_types. An unrecognised slug is stored as-is and will not group correctly in the app. update_activity_log [farm:write] (WRITES) Edit an activity log entry. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. log_id (string, required, uuid) — The entry to edit. title (string) — New title. notes (string) — New notes. Send an empty string to clear them. log_type (string) — New activity type slug. log_date (string, date) — New date (YYYY-MM-DD). end_date (string, date) — New end date (YYYY-MM-DD). delete_activity_log [farm:write] (WRITES) Delete an activity log entry. Soft. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. log_id (string, required, uuid) — The entry to delete. get_notes [farm:read] Recent notes on a farm. farm_id (string, required, uuid) — The farm whose notes to read. limit (number, default 10) — How many notes to return. create_note [farm:write] (WRITES) Write a note against a farm, plot or plant — an observation that is not a task that was performed. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. farm_id (string, required, uuid) — The farm the note belongs to. content (string, required) — The note body. plot_id (string, uuid) — Attach to a specific plot. Omit for farm level. plant_id (string, uuid) — Attach to a specific plant. update_note [farm:write] (WRITES) Replace a note's content. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. note_id (string, required, uuid) — The note to edit. content (string, required) — The new body. This replaces the old one entirely. delete_note [farm:write] (WRITES) Delete a note. Soft. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. note_id (string, required, uuid) — The note to delete. get_calendar_events [farm:read] Calendar events on a farm within a date window. farm_id (string, required, uuid) — The farm whose calendar to read. start_date (string, date, default today) — Window start (YYYY-MM-DD). end_date (string, date, default 30 days from today) — Window end (YYYY-MM-DD). create_calendar_event [farm:write] (WRITES) Put something on the farm calendar. Lands on the farm's system calendar; the farm must already have one. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. farm_id (string, required, uuid) — The farm whose calendar to write to. summary (string, required) — Event title. start_date (string, required, date) — When it starts (YYYY-MM-DD). end_date (string, date, default same as start_date) — When it ends (YYYY-MM-DD). description (string) — Longer detail. all_day (boolean, default true) — Pass false only for a timed event. location (string) — Where it happens. plot_id (string, uuid) — Attach to a specific plot. Omit for farm level. delete_calendar_event [farm:write] (WRITES) Remove a calendar event. Unlike the other deletes here this one is HARD — the row is removed and cannot be recovered. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. event_id (string, required, uuid) — The event to remove. get_weather [farm:read] Daily forecast for a farm's location — max/min temperature, precipitation, wind and weather code. Needs the farm to have a location set. farm_id (string, required, uuid) — The farm to forecast for. days (number, default 7) — How many days ahead. search_catalog [farm:read] Search the shared crop catalog by name, variety, crop type or scientific name. Returns up to 5 matches. Use the id with create_plant or get_crop_enrichment. query (string, required) — What to search for, e.g. 'arabica'. get_crop_enrichment [farm:read] Read one section of the researched detail behind a catalog entry. Returns a 'not available yet' message rather than an error when the section has not been generated. crop_catalog_id (string, required, uuid) — Catalog entry id, from search_catalog. section (string, required) — Which section to read. One of: growing_conditions, pest_profile, companion_plants, revenue_potential, products, regional_notes. get_attachments [farm:read] List the files attached to one record. entity_type (string, required) — What kind of record. One of: farm, plot, plant, note, farmLog. entity_id (string, required, uuid) — The record's id. get_plant_stats [farm:read] Counts of plants grouped by category, health and lifecycle. Omit farm_id for a total across every farm this key can reach. farm_id (string, uuid) — Limit to one farm. Omit for all of them. get_pending_events [events:consume] Things that happened in the app since anyone last asked. DRAINS ON READ: each event is delivered exactly once, to whichever caller asks first, so a second agent polling the same organization does not see them — it takes them. Returns up to 50. (no arguments) read_memory [memory:read] Read the farmer's knowledge graph — what Dear Farm's own agent has concluded about them and their land. query (string) — Narrow to matching nodes. Omit for a summary of the whole graph. get_memory_graph [memory:read] Node and edge counts plus a prose summary of the graph. (no arguments) get_system_prompt [memory:read] The composed system prompt Dear Farm's own agent runs under — its active personality and the farmer's standing instructions. Read it to stay consistent with how that agent behaves. (no arguments) get_research_report [memory:read] Load a research report in full — title, summary, markdown body, findings and sources. report_id (string, required, uuid) — The report to load. get_expenses [expenses] List expenses, newest first. farm_id (string, uuid) — Limit to one farm. category (string) — Limit to one category. limit (number, default 20) — How many to return. create_expense [expenses] (WRITES) Record an expense. It lands as a draft — the farmer confirms it in the app before it syncs to their accounting system. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. amount (number, required) — The amount. Positive. description (string, required) — What it was for. farm_id (string, uuid) — Which farm to book it against. plot_id (string, uuid) — Attach to a specific plot. Omit for farm level. currency (string, default USD) — ISO 4217 code, e.g. 'INR'. category (string) — Free text matching the farmer's accounting categories, e.g. 'Fertilizer'. merchant (string) — Who was paid. expense_date (string, date, default today) — When it was incurred (YYYY-MM-DD). metadata (object) — Free-form extra fields kept with the expense. update_expense [expenses] (WRITES) Edit an expense. Every field is optional. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. expense_id (string, required, uuid) — The expense to edit. amount (number) — New amount. description (string) — New description. category (string) — New category. merchant (string) — New merchant. farm_id (string, uuid) — Move it to a different farm. plot_id (string, uuid) — Attach to a specific plot. Omit for farm level. expense_date (string, date) — New date (YYYY-MM-DD). status (string) — Sync lifecycle state. Leave this alone unless the farmer asked — moving an expense to 'confirmed' is what pushes it to their accounting system. One of: draft, confirmed, synced, sync_error. extract_expense_from_file [expenses] (WRITES) Read a receipt that has already been uploaded and pull the amount, merchant, date and line items out of it. Upload the file first — this takes an attachment id, not bytes. WRITES IMMEDIATELY when called on this endpoint — there is no approval step here, so confirm with the farmer yourself before calling it. attachment_id (string, required, uuid) — The uploaded receipt, from POST /api/agent/upload. ## Not callable, on purpose - update_memory — Only Dear Farm's own agent writes the Mind. Use POST /api/agent/memory/request. - write_preferences_root — Writes the Mind. - write_research_report_node — Writes the Mind. - write_personality_from_preset — Writes the Mind, and rewrites who the agent is. Withheld twice over: it is also a settings change. - delete_memory_node — Erases the Mind. - delete_memory_edge — Erases the Mind. - clean_memory — Erases the Mind. - reset_memory — Erases the Mind. - forget_farm_skeleton — Erases the Mind. ## Machine-readable https://www.dear.farm/api/agent/openapi — OpenAPI 3.1, with every argument schema. Public.