Phase 11, part 4: agents' limits, recent calls and a pause switch
Each agent has calls a minute and things it may ask to send out a day, checked on every tool call and every request to send; every call is recorded (tool, outcome, time) and the agent's page lists the last 50 and what it's waiting on. Pause refuses all its calls at once. Also fixes each agent's MCP server being shared with others that had the same scopes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,3 +105,40 @@ func TestAgentKeys(t *testing.T) {
|
||||
t.Error("keys outlived the agent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentLimitsAndCalls(t *testing.T) {
|
||||
d := openDB(t)
|
||||
now := time.Now()
|
||||
a, _ := CreateAgent(d, "Bot", "", now)
|
||||
l, _ := LimitsOf(d, a.ID)
|
||||
if l.PerMinute != DefaultPerMinute || l.OutPerDay != DefaultOutPerDay || !l.Paused.IsZero() {
|
||||
t.Errorf("defaults %+v", l)
|
||||
}
|
||||
if err := SetLimits(d, a.ID, 0, 5); err == nil {
|
||||
t.Error("zero accepted")
|
||||
}
|
||||
SetLimits(d, a.ID, 10, 5)
|
||||
Pause(d, a.ID, true, 7, now)
|
||||
l, _ = LimitsOf(d, a.ID)
|
||||
if l.PerMinute != 10 || l.OutPerDay != 5 || l.Paused.IsZero() || l.PausedBy != 7 {
|
||||
t.Errorf("set %+v", l)
|
||||
}
|
||||
Pause(d, a.ID, false, 7, now)
|
||||
if l, _ = LimitsOf(d, a.ID); !l.Paused.IsZero() || l.PerMinute != 10 {
|
||||
t.Errorf("resumed %+v", l)
|
||||
}
|
||||
RecordCall(d, Call{Agent: a.ID, At: now.Add(-2 * time.Minute), Tool: "x", Outcome: CallOK})
|
||||
RecordCall(d, Call{Agent: a.ID, At: now, Tool: "y", Outcome: CallError, Detail: strings.Repeat("e", 400), Took: 1500 * time.Millisecond})
|
||||
RecordCall(d, Call{Agent: a.ID, At: now, Tool: "z", Outcome: CallRefused})
|
||||
if n, _ := CallsSince(d, a.ID, now.Add(-time.Minute)); n != 1 {
|
||||
t.Errorf("calls in a minute: %d", n)
|
||||
}
|
||||
calls, _ := RecentCalls(d, a.ID, 10)
|
||||
if len(calls) != 3 || calls[1].Tool != "y" || calls[1].Took != 1500*time.Millisecond || len([]rune(calls[1].Detail)) != 300 {
|
||||
t.Errorf("recent %+v", calls)
|
||||
}
|
||||
PruneCalls(d, now.Add(31*24*time.Hour))
|
||||
if calls, _ = RecentCalls(d, a.ID, 10); len(calls) != 0 {
|
||||
t.Error("not pruned")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user