CattleOSCattleOSDevelopers

Cooper AI

The intelligent cattle management assistant — architecture, capabilities, and integration guide.

Overview

Cooper is CattleOS's AI assistant that helps farmers manage their operations through natural language. Rather than navigating forms and menus, farmers can simply tell Cooper what they need — "add 50 Angus steers to the North Pen" or "how many cattle are sick?" — and Cooper executes the action or queries the data directly.

Cooper is powered by OpenAI's GPT-4o model with real-time access to 100+ platform tools. When you call the Cooper API, the model decides which tools to invoke, executes them server-side against your farm's data, and returns a natural language summary along with the raw tool results.

Cooper is stateless per request — you maintain conversation history client-side and pass it with each call for multi-turn conversations.

Architecture

Request Flow

Client Request
     │
     ▼
┌─────────────────────────────────────────────────┐
│  POST /api/v1/cooper/chat                       │
│  Authentication: API Key (cos_live_xxx)         │
│  Scope required: cooper:chat                    │
└─────────────────────────────────────────────────┘
     │
     ▼
┌─────────────────────────────────────────────────┐
│  System Prompt + User Messages                  │
│  ──────────────────────────────                 │
│  Sent to OpenAI GPT-4o with 100+ tool defs     │
└─────────────────────────────────────────────────┘
     │
     ▼
┌─────────────────────────────────────────────────┐
│  Tool Execution Loop (up to N rounds)           │
│  ──────────────────────────────────             │
│  1. Model returns tool_calls                    │
│  2. Server executes each tool against your DB   │
│  3. Results fed back to model                   │
│  4. Repeat until model has final answer         │
└─────────────────────────────────────────────────┘
     │
     ▼
┌─────────────────────────────────────────────────┐
│  JSON Response                                  │
│  ──────────────                                 │
│  { message, tool_calls[], model, usage }        │
└─────────────────────────────────────────────────┘

Two-Tier Model Strategy (Internal)

Within the CattleOS app, Cooper uses a two-tier model approach for optimal speed and quality:

  • GPT-4o-mini for tool-routing turns — fast, cheap, and accurate at choosing which tool to call and extracting parameters from natural language
  • GPT-4o for the final synthesis turn — composes the user-facing natural language answer from tool results

Via the API, you can choose which model handles the entire flow (both routing and synthesis) using the model parameter.

Tool Execution

Tools execute server-side through the same data layer that powers the REST API. Each tool:

  1. Has a Zod schema that validates the model's arguments (same schemas as the HTTP endpoints)
  2. Resolves the user's farm context from the API key
  3. Calls the data layer directly (no HTTP self-loop)
  4. Returns a structured result that's fed back to the model

Large Result Handling

When a tool returns large datasets (e.g. listing 2000+ cattle), the results are automatically compacted before being fed back to the model — truncated to 25 items with a count of total matches. This prevents context window overflow while still giving the model accurate aggregate information. If more detail is needed, the model can re-call with more specific filters.

System Prompt

Cooper's behavior is defined by its system prompt. The API uses a focused, tool-oriented prompt:

You are Cooper, the AI assistant for CattleOS — a cattle management platform.

You have access to real platform tools via function calling. Use them to answer
questions and perform actions on the user's farm data.

Rules:
- For ANY question about farm data (cattle counts, pen info, activities),
  CALL the matching tool.
- For ANY write action (add, create, update, delete, move),
  CALL the matching tool.
- DO NOT answer data questions from memory — always call a tool.
- After tools return, respond in natural language summarizing what happened.
- Be conversational and helpful. If you need more information before acting, ask.
- When adding cattle, ALWAYS ask for a tag number — never auto-generate one.
- For inventory, always require name and quantity.

The internal app version (used in the CattleOS UI) includes additional context like the user's identity, team roster, and detailed interaction examples — but the core philosophy is the same: always use tools for data, never guess.

Available Tools (100+)

Cooper has access to the full CattleOS platform through OpenAI function calling. Tools are defined using Zod schemas that match the REST API — ensuring the AI can do exactly what the UI can do, no more, no less.

Cattle

  • list_cattle — Query cattle with filters (status, pen, health, sex, pregnancy, tag)
  • get_cattle — Fetch a single animal by ID
  • create_cattle — Add a new animal (requires tag number)
  • update_cattle — Modify fields on an existing record
  • delete_cattle — Remove a record (prefer status change over delete)
  • add_weight_record — Log a weight measurement
  • add_health_record — Log vaccinations, treatments, checkups

Pens & Barns

  • list_pens / list_barns — Query pen/barn inventory
  • create_pen / create_barn — Add new infrastructure
  • update_pen / update_barn — Modify capacity, name, etc.
  • delete_pen / delete_barn — Remove infrastructure
  • move_cattle — Move animals between pens
  • add_pen_movement — Log a pen transfer event
  • update_pen_count — Adjust head count in a pen

Inventory & Feed

  • list_inventory — Query feed, medications, supplies
  • add_inventory_item — Add new stock
  • update_inventory_item — Adjust quantities
  • record_inventory_transaction — Log usage/purchase events
  • add_feed_activity — Record feeding events
  • add_medication_activity — Record medication administration

Zones & Properties (Ranch Map)

  • list_zones / list_properties — Query geographic data
  • create_zone / create_property — Add pastures, buildings, water sources
  • move_cattle_between_zones — Transfer animals geographically
  • assign_cattle_to_zone — Place animals in a zone
  • list_zone_movements — View movement history

Financial

  • list_costs / list_revenue — Query financial records
  • create_cost / create_revenue — Record expenses and income
  • create_financial_transaction — General ledger entry
  • record_cattle_sale — Log a sale with revenue + status update
  • list_other_costs — Miscellaneous expense tracking

Activities & Notes

  • list_notes / list_activity_log — Query farm journal
  • create_note — Add a journal entry
  • log_activity — Record an operation (feeding, treatment, observation)
  • list_custom_activities — Farm-specific activity types

Contacts & Team

  • list_contacts — Query buyers, vets, suppliers
  • create_contact / update_contact — Manage contacts
  • list_team_members — View farm team roster
  • send_dm — Send a direct message to a team member

Tasks & Lifecycle

  • list_tasks — Query farm tasks
  • create_task / complete_task — Manage work items
  • list_lifecycle_stages — View cattle lifecycle configuration
  • record_mortality — Log an animal death

Batches

  • list_batches — Query cattle batches/lots
  • create_batch — Group cattle into a batch
  • update_batch — Modify batch attributes

API Reference

Endpoint

POST https://app.cattleos.com/api/v1/cooper/chat

Headers

Authorization: Bearer cos_live_your_key_here
Content-Type: application/json

Request Body

FieldTypeRequiredDescription
messagesarrayYesArray of message objects with role and content
messages[].rolestringYes"user" or "assistant"
messages[].contentstringYesThe message text
modelstringNo"gpt-4o" (default) or "gpt-4o-mini"
temperaturenumberNo0-2, default 0.7. Lower = more deterministic
max_tool_roundsnumberNo1-10, default 5. Max tool execution loops before forcing a response

Response Body

{
  "data": {
    "message": "You have 2,353 cattle. 847 are in the North Pen, 1,206 in South Pen...",
    "tool_calls": [
      {
        "name": "list_cattle",
        "arguments": {},
        "result": {
          "matchingCount": 2353,
          "items": [...]
        }
      }
    ],
    "model": "gpt-4o",
    "usage": {
      "prompt_tokens": 1850,
      "completion_tokens": 67,
      "total_tokens": 1917
    }
  }
}

Response Fields

FieldDescription
data.messageCooper's natural language response
data.tool_callsArray of tools that were executed, with arguments and results
data.modelWhich model was used
data.usageToken consumption for billing awareness

Examples

Query: "How many cattle do I have?"

curl -X POST https://app.cattleos.com/api/v1/cooper/chat \
  -H "Authorization: Bearer cos_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "How many cattle do I have?"}]
  }'

Cooper calls list_cattle with no filters, gets the total count, and responds with the number.

Action: "Add a Black Angus heifer, tag 445, 620 lbs"

curl -X POST https://app.cattleos.com/api/v1/cooper/chat \
  -H "Authorization: Bearer cos_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{
      "role": "user",
      "content": "Add a Black Angus heifer, tag 445, 620 lbs"
    }]
  }'

Cooper calls create_cattle with {tagNumber: "445", breed: "Black Angus", sex: "Heifer", weight: 620} and confirms the addition.

Multi-turn: Follow-up questions

curl -X POST https://app.cattleos.com/api/v1/cooper/chat \
  -H "Authorization: Bearer cos_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "How many cattle are in the North Pen?"},
      {"role": "assistant", "content": "You have 847 cattle in the North Pen."},
      {"role": "user", "content": "Move 50 of them to the South Pen"}
    ]
  }'

Cooper uses conversation context to understand "them" refers to cattle in the North Pen, then calls move_cattle.

Complex: "Record that I vaccinated tags 101-105 with Bovishield"

curl -X POST https://app.cattleos.com/api/v1/cooper/chat \
  -H "Authorization: Bearer cos_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{
      "role": "user",
      "content": "Record that I vaccinated tags 101, 102, 103, 104, and 105 with Bovishield Gold today"
    }],
    "max_tool_rounds": 8
  }'

Cooper calls list_cattle to resolve tag numbers to IDs, then calls add_health_record for each animal. Multiple tool rounds are used automatically.

Design Philosophy

Always Use Tools, Never Guess

Cooper never answers data questions from context or memory. Even if the system prompt contains farm stats, the tool-calling path forces the model to query real-time data for every response. This ensures answers are always current.

Ask Before Acting

For write operations, Cooper asks for required fields before executing. Tag numbers are never auto-generated. This prevents accidental data creation from ambiguous instructions.

One Source of Truth

Tool definitions are generated from the same Zod schemas that validate REST API requests. The AI can do exactly what the REST API can do — same validation, same data layer, same permissions.

Graceful Degradation

If a tool call fails (e.g. cattle not found), the error is fed back to the model which then explains the issue to the user naturally. Tool failures never crash the request.

Context Window Protection

Large list results are automatically truncated to 25 items + a total count. A safety cap on tool rounds (default 5, max 10) prevents runaway loops. Response payloads over 50KB are compressed.

Limits & Considerations

Rate limit100 requests/minute per API key
Max tool rounds10 per request (default 5)
Max response tokens1,500 per model call
Message historyYou manage context client-side; no server-side session
Token usageReturned in each response for your tracking; OpenAI costs are included in your CattleOS plan

Integration Ideas

  • Voice assistants — Pipe speech-to-text output into Cooper for hands-free farm management while working in the field
  • Chatbots — Embed Cooper in WhatsApp, Telegram, or SMS for farmers who prefer messaging
  • Automated reporting — Schedule daily queries ("Give me a summary of today's activities") and email the results
  • IoT integration — When a scale reads a weight, send "Record weight 847 lbs for tag 234" to automatically log it
  • Mobile apps — Build custom farm management UIs that use Cooper as the backend intelligence
  • Slack/Teams bots — Let your team query farm data from their existing chat tools