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:
+28
-7
@@ -35,6 +35,21 @@ const keepAliveInterval = 20 * time.Second
|
||||
type chatRequest struct {
|
||||
GardenID int64 `json:"gardenId" binding:"required"`
|
||||
Message string `json:"message" binding:"required"`
|
||||
// Today is the sender's local date (YYYY-MM-DD): what the assistant tells the
|
||||
// model the date is, and what the turn's plantings, removals and journal
|
||||
// entries are dated. The UI always sends it, for the same reason it sends
|
||||
// plantedAt on a fill — a gardener placing at 9 pm in Ohio planted today, not
|
||||
// UTC's tomorrow. Optional for bare API callers, who get the server's UTC day.
|
||||
Today string `json:"today"`
|
||||
}
|
||||
|
||||
// validToday accepts an empty date or one in YYYY-MM-DD form.
|
||||
func validToday(s string) bool {
|
||||
if s == "" {
|
||||
return true
|
||||
}
|
||||
_, err := time.Parse("2006-01-02", s)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// chatEvent is one server-sent event. Exactly one field is set.
|
||||
@@ -60,17 +75,23 @@ func (h *handlers) agentChat(c *gin.Context) {
|
||||
// state, not a missing route: answer it plainly rather than 404ing a path
|
||||
// that exists. Loaded once here so a settings-driven swap mid-request can't
|
||||
// make it flip between the guard and the Run call.
|
||||
runner := h.agent.get()
|
||||
if runner == nil {
|
||||
writeAPIError(c, http.StatusServiceUnavailable, "AGENT_DISABLED", "the garden assistant isn't enabled on this instance")
|
||||
return
|
||||
}
|
||||
|
||||
// The body is checked before the runner: a malformed request is a 400
|
||||
// whether or not there is a model behind the route, so a client can't
|
||||
// mistake its own bad date for the assistant being off.
|
||||
var req chatRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
writeAPIError(c, http.StatusBadRequest, "INVALID_INPUT", "a gardenId and a message are required")
|
||||
return
|
||||
}
|
||||
if !validToday(req.Today) {
|
||||
writeAPIError(c, http.StatusBadRequest, "INVALID_INPUT", "today must be a YYYY-MM-DD date")
|
||||
return
|
||||
}
|
||||
runner := h.agent.get()
|
||||
if runner == nil {
|
||||
writeAPIError(c, http.StatusServiceUnavailable, "AGENT_DISABLED", "the garden assistant isn't enabled on this instance")
|
||||
return
|
||||
}
|
||||
actor := mustActor(c)
|
||||
|
||||
history, err := h.svc.AgentHistory(c.Request.Context(), actor.ID, req.GardenID)
|
||||
@@ -88,7 +109,7 @@ func (h *handlers) agentChat(c *gin.Context) {
|
||||
stopBeat := stream.keepAlive(keepAliveInterval)
|
||||
defer stopBeat()
|
||||
|
||||
turn, err := runner.Run(c.Request.Context(), actor.ID, req.GardenID, req.Message,
|
||||
turn, err := runner.Run(c.Request.Context(), actor.ID, req.GardenID, req.Message, req.Today,
|
||||
replayHistory(history),
|
||||
func(s mdagent.Step) {
|
||||
send(chatEvent{Step: &stepEvent{Index: s.Index, Tools: toolNames(s)}})
|
||||
|
||||
@@ -47,3 +47,27 @@ func TestAgentDisabledWithoutAKey(t *testing.T) {
|
||||
t.Errorf("editor load: status %d, want 200 — an unconfigured agent must not break the app", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// TestChatRejectsAMalformedToday — the sender's local date is validated before
|
||||
// anything else about the request, assistant or no assistant: a bad body is a
|
||||
// 400 either way, so a client can't mistake its own bad date for the assistant
|
||||
// being off.
|
||||
func TestChatRejectsAMalformedToday(t *testing.T) {
|
||||
r := authEngine(t, localCfg())
|
||||
cookie := registerAndCookie(t, r, "[email protected]")
|
||||
gid := createGardenAPI(t, r, cookie, "G")
|
||||
|
||||
w := doJSON(t, r, http.MethodPost, "/api/v1/agent/chat",
|
||||
map[string]any{"gardenId": gid, "message": "plant garlic", "today": "Aug 22"}, cookie)
|
||||
if w.Code != http.StatusBadRequest {
|
||||
t.Errorf("chat with today=%q: status %d, want 400", "Aug 22", w.Code)
|
||||
}
|
||||
// A well-formed date (or none) gets past validation to the runner check.
|
||||
for _, today := range []string{"2026-08-22", ""} {
|
||||
w := doJSON(t, r, http.MethodPost, "/api/v1/agent/chat",
|
||||
map[string]any{"gardenId": gid, "message": "plant garlic", "today": today}, cookie)
|
||||
if w.Code != http.StatusServiceUnavailable {
|
||||
t.Errorf("chat with today=%q: status %d, want 503 (no runner configured)", today, w.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user