Skip to content

About

Agronomic decision-support AI agent built around an explicit, framework-free Agentic Loop

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

karasu-scout

Agronomic decision-support AI agent for Mato Grosso cotton and soybean operations (Fazenda Karasu — Sorriso/MT), built from scratch around an explicit, framework-free Agentic Loop (no LangChain, LlamaIndex, or CrewAI).

Architecture (Hexagonal / Ports & Adapters)

src/karasu_scout/
├── domain/
│   ├── models.py           # Pure Pydantic v2 models (plots, pests, weather, work orders, traces)
│   └── agronomy_rules.py   # Deterministic GDD, pest threshold, and spray window calculations
├── ports/
│   ├── llm.py              # LLMClient protocol
│   └── approval.py         # ApprovalHandler protocol (Human-in-the-Loop gate)
├── engine/
│   ├── registry.py         # ToolRegistry: OpenAI JSON schema generation + safe dispatch
│   └── harness.py          # AgentHarness: explicit loop, short-term memory, HITL gate, trace events
├── adapters/
│   ├── farm_repository.py  # Mato Grosso cotton & soybean plots, scouting logs, weather windows
│   ├── openai_client.py    # OpenAI SDK adapter implementing LLMClient
│   └── sqlite_store.py     # SQLiteAuditStore for trace_events and spray work_orders
├── tools/
│   └── agronomy_tools.py   # 7 registered tools (6 read/calc + 1 HITL-gated work order tool)
└── cli.py                  # RichTraceRenderer, CLIApprovalHandler, interactive REPL & --dry-run

Key Capabilities

  • Explicit Agentic Loop: Bounded by max_steps, emitting structured TraceEvent telemetry (USER_INPUT, LLM_REQUEST, LLM_TOOL_CALL, TOOL_APPROVAL_REQUESTED, TOOL_APPROVAL_DENIED, TOOL_EXECUTED, TOOL_ERROR, LLM_TEXT_REPLY, MAX_STEPS_EXCEEDED).
  • Deterministic Agronomy Rules: Growing Degree Days (calculate_gdd), pest control thresholds (Anthonomus grandis >= 5.0% attacked squares; Euschistus heros >= 2.0/m), and operational spray window evaluation (IDEAL, MARGINAL, UNFAVORABLE) are never delegated to LLM math.
  • Human-in-the-Loop (HITL) Approval Gate: Mutating tools (issue_spray_work_order) require explicit operator approval via ApprovalHandler before execution. Denials feed REJECTED_BY_OPERATOR back into the loop so the model adapts cleanly.
  • SQLite Audit & Persistence: Every trace event and approved SprayWorkOrder is persisted to SQLite (karasu_scout.db by default).

Setup

Requires Python 3.12+ and uv.

uv sync

Configure environment variables (e.g., in .env) for live OpenAI mode:

OPENAI_API_KEY=sk-...
# Optional:
# OPENAI_BASE_URL=https://api.openai.com/v1
# KARASU_MODEL=gpt-4o-mini

Usage

Run the scripted multi-step demo without an API key:

uv run karasu-scout --dry-run --auto-approve

Run the interactive REPL:

uv run karasu-scout

CLI flags & REPL commands:

  • --dry-run: Run the built-in DemoScriptedLLMClient scenario.
  • --db-path PATH: SQLite database path (default: karasu_scout.db).
  • --auto-approve: Skip interactive [y/N] confirmation for mutating tools.
  • /orders: Display persisted SprayWorkOrder records from SQLite.
  • /reset: Clear short-term conversation memory and start a new session ID.
  • /exit: Quit the REPL.

Development & Verification

make check   # ruff check + ruff format --check + pyright (strict) + pytest
make cov     # pytest with line coverage report
make ci      # make check + pip-audit

License

MIT

About

Agronomic decision-support AI agent built around an explicit, framework-free Agentic Loop

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages