Agent: what a day of live use asked for
Twenty-one prompts against the live assistant found one fabricated success,
a model that believed it was 2025, and a describe_garden that was ~450 plop
entries per turn. This is the set of fixes, each traceable to a finding:
- The gardener's LOCAL day travels with the turn (`today` on POST /agent/chat,
sent by the UI like plantedAt) into the system prompt and every dated tool
default. Left to guess, the model dated journal entries a year back; left to
the server, a 9 pm fill landed on UTC's tomorrow.
- describe_garden groups plops by plant — count, where, planted date, days to
maturity — and lists ids only for groups of ≤ 8; list_plantings spells a big
group out on demand and remove_plantings acts on one plant in a bed ("take
the beets out, leave the garlic"), which used to mean 116 single removals.
- New tools: move_planting (keeps the planting date; across beds via the new
MovePlanting, which is why the store's UPDATE now writes object_id),
update_plant, read_history, copy_garden (the "<garden> — <year>" plan
convention). fill_region takes an explicit local rectangle and a seedLotId;
place_planting's radius defaults to one plant (spacing/2) instead of a guess.
- The system prompt states the date and the gardener's units, forbids claiming
a change no tool made, says it cannot undo and points at the Undo button,
asks before clearing beds on an ambiguous sentence, and stops narrating its
own plantings into the journal.
- A mutation aimed at ANOTHER garden inside a turn is recorded under that
garden as its own change set, not filed into the open scope.
- UI: the thread scrolls inside the Assistant panel so the composer stays
put; every tool has a step label; wide tables stay inside the bubble.
Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
+253
-14
@@ -24,7 +24,7 @@ import (
|
||||
func TestToolboxScenario(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc, ownerID := newAgentTestService(t)
|
||||
box := NewToolbox(svc, ownerID)
|
||||
box := NewToolbox(svc, ownerID, "")
|
||||
|
||||
call := func(name string, args any) llm.ToolResult {
|
||||
t.Helper()
|
||||
@@ -78,12 +78,17 @@ func TestToolboxScenario(t *testing.T) {
|
||||
if len(desc.Objects) != 1 {
|
||||
t.Fatalf("objects = %d, want 1", len(desc.Objects))
|
||||
}
|
||||
// Plantings come grouped by plant: a group's Where names the region when the
|
||||
// whole group sits in one, and a small group also lists its plops.
|
||||
seen := map[string]map[string]bool{}
|
||||
for _, p := range desc.Objects[0].Plantings {
|
||||
if seen[p.Plant] == nil {
|
||||
seen[p.Plant] = map[string]bool{}
|
||||
for _, g := range desc.Objects[0].Plantings {
|
||||
if seen[g.Plant] == nil {
|
||||
seen[g.Plant] = map[string]bool{}
|
||||
}
|
||||
seen[g.Plant][g.Where] = true
|
||||
for _, p := range g.Each {
|
||||
seen[g.Plant][p.Location] = true
|
||||
}
|
||||
seen[p.Plant][p.Location] = true
|
||||
}
|
||||
if !seen["Garlic"]["NE corner"] {
|
||||
t.Errorf("garlic at %v, want NE corner", seen["Garlic"])
|
||||
@@ -108,7 +113,7 @@ func TestToolboxScenario(t *testing.T) {
|
||||
if _, err := svc.AddShare(ctx, ownerID, g.ID, "[email protected]", domain.RoleViewer); err != nil {
|
||||
t.Fatalf("share: %v", err)
|
||||
}
|
||||
viewerBox := NewToolbox(svc, viewerUser.ID)
|
||||
viewerBox := NewToolbox(svc, viewerUser.ID, "")
|
||||
vr := viewerBox.Execute(ctx, llm.ToolCall{ID: "2", Name: "fill_region", Arguments: mustJSON(t, map[string]any{
|
||||
"objectId": bed.ID, "region": "all", "plantId": garlic.ID,
|
||||
})})
|
||||
@@ -148,7 +153,7 @@ func mustPlant(t *testing.T, svc *service.Service, owner int64, name string, spa
|
||||
func TestGarlicBedToCucumbers(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc, owner := newAgentTestService(t)
|
||||
box := NewToolbox(svc, owner)
|
||||
box := NewToolbox(svc, owner, "")
|
||||
|
||||
call := func(name string, args any) llm.ToolResult {
|
||||
t.Helper()
|
||||
@@ -233,7 +238,7 @@ func TestGarlicBedToCucumbers(t *testing.T) {
|
||||
func TestFindPlantReturnsCandidatesNotAGuess(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc, owner := newAgentTestService(t)
|
||||
box := NewToolbox(svc, owner)
|
||||
box := NewToolbox(svc, owner, "")
|
||||
|
||||
mustPlant(t, svc, owner, "German Red Garlic", 15, "🧄")
|
||||
|
||||
@@ -272,7 +277,7 @@ func TestCreatePlantIsUserScoped(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("register: %v", err)
|
||||
}
|
||||
box := NewToolbox(svc, other.ID)
|
||||
box := NewToolbox(svc, other.ID, "")
|
||||
|
||||
raw, _ := json.Marshal(map[string]any{
|
||||
"name": "Painted Mountain Corn", "category": "vegetable",
|
||||
@@ -310,7 +315,7 @@ func TestCreatePlantIsUserScoped(t *testing.T) {
|
||||
func TestJournalToolWritesADatedObservation(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc, owner := newAgentTestService(t)
|
||||
box := NewToolbox(svc, owner)
|
||||
box := NewToolbox(svc, owner, "")
|
||||
|
||||
g, err := svc.CreateGarden(ctx, owner, service.GardenInput{Name: "Plot", WidthCM: 2000, HeightCM: 2000})
|
||||
if err != nil {
|
||||
@@ -354,7 +359,7 @@ func TestJournalToolWritesADatedObservation(t *testing.T) {
|
||||
func TestCorrectiveTools(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc, owner := newAgentTestService(t)
|
||||
box := NewToolbox(svc, owner)
|
||||
box := NewToolbox(svc, owner, "")
|
||||
|
||||
var gid int64 // set once the garden exists; the describe closure reads it.
|
||||
call := func(name string, args any) llm.ToolResult {
|
||||
@@ -405,10 +410,10 @@ func TestCorrectiveTools(t *testing.T) {
|
||||
t.Fatalf("place_planting: %s", r.Content)
|
||||
}
|
||||
d = describe()
|
||||
if len(d.Objects[0].Plantings) != 1 {
|
||||
t.Fatalf("want 1 plop before removal, got %d", len(d.Objects[0].Plantings))
|
||||
if len(d.Objects[0].Plantings) != 1 || len(d.Objects[0].Plantings[0].Each) != 1 {
|
||||
t.Fatalf("want 1 plop before removal, got %+v", d.Objects[0].Plantings)
|
||||
}
|
||||
plop := d.Objects[0].Plantings[0]
|
||||
plop := d.Objects[0].Plantings[0].Each[0]
|
||||
if r := call("remove_planting", map[string]any{"plantingId": plop.ID, "version": plop.Version}); r.IsError {
|
||||
t.Fatalf("remove_planting: %s", r.Content)
|
||||
}
|
||||
@@ -487,3 +492,237 @@ func newAgentTestService(t *testing.T) (*service.Service, int64) {
|
||||
}
|
||||
return svc, owner.ID
|
||||
}
|
||||
|
||||
// TestToolsFromTheLiveSweep covers what a day of driving the live assistant
|
||||
// asked for: grouped describes, whole-group removal, moves that keep the
|
||||
// planting date, fills by rectangle, seed attribution, catalog edits, history
|
||||
// reads, plan copies — and every date stamped the gardener's local day rather
|
||||
// than the server's (UTC) or the model's (a year from its training data).
|
||||
func TestToolsFromTheLiveSweep(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
svc, owner := newAgentTestService(t)
|
||||
const today = "2026-08-22"
|
||||
box := NewToolbox(svc, owner, today)
|
||||
call := func(name string, args any) llm.ToolResult {
|
||||
t.Helper()
|
||||
return box.Execute(ctx, llm.ToolCall{ID: "1", Name: name, Arguments: mustJSON(t, args)})
|
||||
}
|
||||
ok := func(name string, args any) string {
|
||||
t.Helper()
|
||||
r := call(name, args)
|
||||
if r.IsError {
|
||||
t.Fatalf("%s: %s", name, r.Content)
|
||||
}
|
||||
return r.Content
|
||||
}
|
||||
decode := func(raw string, into any) {
|
||||
t.Helper()
|
||||
if err := json.Unmarshal([]byte(raw), into); err != nil {
|
||||
t.Fatalf("decode %v: %s", err, raw)
|
||||
}
|
||||
}
|
||||
|
||||
g, err := svc.CreateGarden(ctx, owner, service.GardenInput{Name: "Plot", WidthCM: 2000, HeightCM: 2000, UnitPref: domain.UnitImperial})
|
||||
if err != nil {
|
||||
t.Fatalf("garden: %v", err)
|
||||
}
|
||||
garlic := mustPlant(t, svc, owner, "Garlic", 15, "🧄")
|
||||
beet := mustPlant(t, svc, owner, "Beet", 10, "🌱")
|
||||
tomato := mustPlant(t, svc, owner, "Cherokee Purple", 60, "🍅")
|
||||
bed, err := svc.CreateObject(ctx, owner, g.ID, service.ObjectInput{Kind: domain.KindBed, Name: "South bed", XCM: 1000, YCM: 1000, WidthCM: 240, HeightCM: 120})
|
||||
if err != nil {
|
||||
t.Fatalf("bed: %v", err)
|
||||
}
|
||||
other, err := svc.CreateObject(ctx, owner, g.ID, service.ObjectInput{Kind: domain.KindBed, Name: "North bed", XCM: 1000, YCM: 300, WidthCM: 240, HeightCM: 120})
|
||||
if err != nil {
|
||||
t.Fatalf("other bed: %v", err)
|
||||
}
|
||||
lot, err := svc.CreateSeedLot(ctx, owner, service.SeedLotInput{PlantID: beet.ID, Quantity: 500, Unit: "seeds"})
|
||||
if err != nil {
|
||||
t.Fatalf("lot: %v", err)
|
||||
}
|
||||
|
||||
// fill_region by rectangle (the middle third of the bed's width), in grid mode,
|
||||
// charged to the lot, dated today by default.
|
||||
ok("fill_region", map[string]any{
|
||||
"objectId": bed.ID, "plantId": beet.ID, "mode": "grid", "seedLotId": lot.ID,
|
||||
"x0Cm": -40.0, "y0Cm": -60.0, "x1Cm": 40.0, "y1Cm": 60.0,
|
||||
})
|
||||
// Neither a region nor a full rectangle is a mistake the model can read.
|
||||
if r := call("fill_region", map[string]any{"objectId": bed.ID, "plantId": beet.ID, "x0Cm": -40.0}); !r.IsError || !strings.Contains(r.Content, "x0Cm, y0Cm, x1Cm, y1Cm") {
|
||||
t.Errorf("half a rectangle: %+v, want a readable refusal", r)
|
||||
}
|
||||
if r := call("fill_region", map[string]any{"objectId": bed.ID, "plantId": beet.ID}); !r.IsError {
|
||||
t.Error("fill_region with nowhere to fill succeeded")
|
||||
}
|
||||
// place_planting without a radius → one plant at half the spacing; two garlic
|
||||
// cloves along the north edge, dated today.
|
||||
ok("place_planting", map[string]any{"objectId": bed.ID, "plantId": garlic.ID, "xCm": -100, "yCm": -50})
|
||||
ok("place_planting", map[string]any{"objectId": bed.ID, "plantId": garlic.ID, "xCm": 100, "yCm": -50})
|
||||
// And a tomato planted back in May, with an explicit date.
|
||||
ok("place_planting", map[string]any{"objectId": bed.ID, "plantId": tomato.ID, "xCm": 0, "yCm": 0, "plantedAt": "2026-05-20"})
|
||||
|
||||
// describe_garden: one group per plant, dated; only the small ones listed.
|
||||
var d service.DescribeResult
|
||||
groups := func() map[string]service.DescribeGroup {
|
||||
t.Helper()
|
||||
decode(ok("describe_garden", map[string]any{"gardenId": g.ID}), &d)
|
||||
out := map[string]service.DescribeGroup{}
|
||||
for _, o := range d.Objects {
|
||||
if o.ID == bed.ID {
|
||||
for _, gr := range o.Plantings {
|
||||
out[gr.Plant] = gr
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
gs := groups()
|
||||
beets := gs["Beet"]
|
||||
if beets.Plops <= 8 || beets.Each != nil {
|
||||
t.Errorf("beets: %d plops, each=%v; want a large group with no per-plop listing", beets.Plops, beets.Each)
|
||||
}
|
||||
if beets.PlantedAt != today || beets.Plants != beets.Plops {
|
||||
t.Errorf("beets plantedAt %q plants %d; want today and one plant per grid plop", beets.PlantedAt, beets.Plants)
|
||||
}
|
||||
if !strings.Contains(beets.Where, "cm from the centre") {
|
||||
t.Errorf("beets where = %q, want the bounding box of a middle-third fill", beets.Where)
|
||||
}
|
||||
cloves := gs["Garlic"]
|
||||
if cloves.Plops != 2 || len(cloves.Each) != 2 || cloves.Where != "north half" || cloves.PlantedAt != today {
|
||||
t.Errorf("garlic group = %+v, want 2 listed plops in the north half, dated today", cloves)
|
||||
}
|
||||
if r := cloves.Each[0].RadiusCM; r != 7.5 {
|
||||
t.Errorf("a clove placed without a radius got %v, want spacing/2 = 7.5", r)
|
||||
}
|
||||
tom := gs["Cherokee Purple"]
|
||||
if tom.Plops != 1 || tom.Where != "center" || tom.PlantedAt != "2026-05-20" {
|
||||
t.Errorf("tomato group = %+v, want one plop at the center dated 2026-05-20", tom)
|
||||
}
|
||||
|
||||
// The lot counts the beets as used.
|
||||
var lots []struct {
|
||||
Used float64 `json:"used"`
|
||||
Remaining float64 `json:"remaining"`
|
||||
}
|
||||
decode(ok("list_seed_lots", map[string]any{"plantId": beet.ID}), &lots)
|
||||
if len(lots) != 1 || lots[0].Used != float64(beets.Plants) || lots[0].Remaining != 500-float64(beets.Plants) {
|
||||
t.Errorf("lots = %+v, want %d used of 500", lots, beets.Plants)
|
||||
}
|
||||
|
||||
// list_plantings spells the big group out, narrowed to one plant.
|
||||
var listed []service.DescribePlanting
|
||||
decode(ok("list_plantings", map[string]any{"objectId": bed.ID, "plantId": beet.ID}), &listed)
|
||||
if len(listed) != beets.Plops {
|
||||
t.Errorf("list_plantings: %d beets, want %d", len(listed), beets.Plops)
|
||||
}
|
||||
|
||||
// move_planting: the tomato to the north bed, date kept; a within-bed move too.
|
||||
var moved domain.Planting
|
||||
decode(ok("move_planting", map[string]any{
|
||||
"plantingId": tom.Each[0].ID, "version": tom.Each[0].Version, "toObjectId": other.ID, "xCm": 10.0, "yCm": -20.0,
|
||||
}), &moved)
|
||||
if moved.ObjectID != other.ID || moved.PlantedAt == nil || *moved.PlantedAt != "2026-05-20" {
|
||||
t.Errorf("moved tomato = %+v, want it in the north bed with its May date", moved)
|
||||
}
|
||||
decode(ok("move_planting", map[string]any{
|
||||
"plantingId": cloves.Each[0].ID, "version": cloves.Each[0].Version, "xCm": -110.0, "yCm": -55.0,
|
||||
}), &moved)
|
||||
if moved.ObjectID != bed.ID || moved.XCM != -110 {
|
||||
t.Errorf("within-bed move = %+v, want the same bed at x=-110", moved)
|
||||
}
|
||||
|
||||
// remove_plantings: the beets out, the garlic stays — dated today.
|
||||
var removed struct {
|
||||
Removed int `json:"removed"`
|
||||
}
|
||||
decode(ok("remove_plantings", map[string]any{"objectId": bed.ID, "plantId": beet.ID}), &removed)
|
||||
if removed.Removed != beets.Plops {
|
||||
t.Errorf("remove_plantings removed %d, want the %d beets", removed.Removed, beets.Plops)
|
||||
}
|
||||
gs = groups()
|
||||
if _, still := gs["Beet"]; still || gs["Garlic"].Plops != 2 {
|
||||
t.Errorf("after remove_plantings the bed has %+v, want the garlic only", gs)
|
||||
}
|
||||
var pulled domain.Planting
|
||||
decode(ok("remove_planting", map[string]any{"plantingId": gs["Garlic"].Each[0].ID, "version": gs["Garlic"].Each[0].Version}), &pulled)
|
||||
if pulled.RemovedAt == nil || *pulled.RemovedAt != today {
|
||||
t.Errorf("remove_planting dated the removal %v, want today %s", pulled.RemovedAt, today)
|
||||
}
|
||||
|
||||
// read_history sees all of that, newest first, and marks what was undone.
|
||||
var hist struct {
|
||||
Entries []historyEntry `json:"entries"`
|
||||
HasMore bool `json:"hasMore"`
|
||||
}
|
||||
decode(ok("read_history", map[string]any{"gardenId": g.ID, "limit": 3}), &hist)
|
||||
if len(hist.Entries) != 3 || !hist.HasMore {
|
||||
t.Fatalf("read_history = %d entries, hasMore=%v; want 3 and more", len(hist.Entries), hist.HasMore)
|
||||
}
|
||||
if e := hist.Entries[1]; !strings.HasPrefix(e.Summary, "Removed Beet from South bed") || !strings.Contains(e.Changes, "planting") || e.Undone {
|
||||
t.Errorf("entry = %+v, want the beet removal, not undone", e)
|
||||
}
|
||||
if _, conflicts, err := svc.RevertChangeSet(ctx, owner, hist.Entries[1].ID, domain.SourceUI); err != nil || len(conflicts) != 0 {
|
||||
t.Fatalf("undo: err=%v conflicts=%+v", err, conflicts)
|
||||
}
|
||||
decode(ok("read_history", map[string]any{"gardenId": g.ID, "limit": 3}), &hist)
|
||||
if hist.Entries[0].Undo == nil || !hist.Entries[2].Undone {
|
||||
t.Errorf("after an undo: newest = %+v, undone = %+v; want the revert to point at the removal, and the removal marked undone", hist.Entries[0], hist.Entries[2])
|
||||
}
|
||||
|
||||
// update_plant on the user's own plant; a built-in is refused.
|
||||
var matches []struct {
|
||||
ID int64 `json:"id"`
|
||||
Version int64 `json:"version"`
|
||||
}
|
||||
decode(ok("find_plant", map[string]any{"query": "cherokee"}), &matches)
|
||||
var updated domain.Plant
|
||||
decode(ok("update_plant", map[string]any{"plantId": matches[0].ID, "version": matches[0].Version, "daysToMaturity": 75}), &updated)
|
||||
if updated.DaysToMaturity == nil || *updated.DaysToMaturity != 75 || updated.Name != "Cherokee Purple" {
|
||||
t.Errorf("update_plant = %+v, want days 75 and the name untouched", updated)
|
||||
}
|
||||
decode(ok("find_plant", map[string]any{"query": "basil"}), &matches)
|
||||
if r := call("update_plant", map[string]any{"plantId": matches[0].ID, "version": matches[0].Version, "daysToMaturity": 60}); !r.IsError {
|
||||
t.Error("update_plant changed a built-in")
|
||||
}
|
||||
|
||||
// add_journal_entry is dated today unless told otherwise.
|
||||
ok("add_journal_entry", map[string]any{"gardenId": g.ID, "body": "aphids on the beets"})
|
||||
entries, _, err := svc.ListJournal(ctx, owner, g.ID, service.JournalQuery{})
|
||||
if err != nil {
|
||||
t.Fatalf("ListJournal: %v", err)
|
||||
}
|
||||
if len(entries) != 1 || entries[0].ObservedAt != today {
|
||||
t.Errorf("journal = %+v, want one entry observed %s", entries, today)
|
||||
}
|
||||
|
||||
// copy_garden makes next year's plan: a whole copy under the plan name.
|
||||
var plan domain.Garden
|
||||
decode(ok("copy_garden", map[string]any{"gardenId": g.ID, "name": "Plot — 2027"}), &plan)
|
||||
if plan.Name != "Plot — 2027" || plan.ID == g.ID {
|
||||
t.Errorf("copy_garden = %+v, want a new garden named for the plan", plan)
|
||||
}
|
||||
decode(ok("describe_garden", map[string]any{"gardenId": plan.ID}), &d)
|
||||
if len(d.Objects) != 2 {
|
||||
t.Errorf("the plan copy has %d objects, want the source's 2", len(d.Objects))
|
||||
}
|
||||
}
|
||||
|
||||
// TestToolsDefaultToTheServiceDayWithoutOne — a toolbox built with no local day
|
||||
// (a bare API caller) still dates everything: the service's UTC today.
|
||||
func TestToolsDefaultToTheServiceDayWithoutOne(t *testing.T) {
|
||||
a := &adapter{today: ""}
|
||||
if d := a.day(""); d != nil {
|
||||
t.Errorf("no day at all → %q, want nil (the service default)", *d)
|
||||
}
|
||||
if d := a.day(" 2026-01-02 "); d == nil || *d != "2026-01-02" {
|
||||
t.Errorf("an explicit day → %v, want it trimmed", d)
|
||||
}
|
||||
a.today = "2026-08-22"
|
||||
if d := a.day(""); d == nil || *d != "2026-08-22" {
|
||||
t.Errorf("the gardener's day → %v, want 2026-08-22", d)
|
||||
}
|
||||
if d := a.day("2026-05-20"); d == nil || *d != "2026-05-20" {
|
||||
t.Errorf("an explicit day beats the default: %v", d)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user