A rebuild summarizes the whole merged log, so it can need more calls
than a probe sample. The import of two chats estimates 647 calls, close
to the 660 calls of the probe, and a stop at the limit swaps nothing and
wastes the calls. The rebuild now stops after 1,500 calls, and the quota
stop still guards the account. The probe keeps its own limit of 660
calls.
Issue:
b0b8bf9
The import merges the full log in date order and builds its tree with
real compactor calls, the agent prompt, and the agent cache key. It uses
The import merges the full log in date order and builds its tree with
real compactor calls, the agent prompt, and the agent cache key. It uses
-the probe's 660-call and 15-quota-point limits and prints the same usage
-report. Its estimate is about 1.3 calls per merged message, not a cost
-guarantee. A stopped or failed run leaves the agent unchanged. A new run
-starts over. Success keeps the other agent files and renames the old
-directory to ``agent-backup-TIMESTAMP`` before it installs the new one.
-Keep the backup until the new memory is checked, then start the daemon.
-Message IDs change to their positions in the merged log.
+a limit of 1,500 calls and the probe's 15-quota-point limit, and prints
+the same usage report. Its estimate is about 1.3 calls per merged
+message, not a cost guarantee. A stopped or failed run leaves the agent
+unchanged. A new run starts over. Success keeps the other agent files
+and renames the old directory to ``agent-backup-TIMESTAMP`` before it
+installs the new one. Keep the backup until the new memory is checked,
+then start the daemon. Message IDs change to their positions in the
+merged log.
// buildQuotaLimit is the largest increase in used quota points of a run.
const buildQuotaLimit = 15.0
// buildQuotaLimit is the largest increase in used quota points of a run.
const buildQuotaLimit = 15.0
-// buildCallLimit is the most model calls of a run.
-const buildCallLimit = 660
-
// BuildRun appends messages, builds their tree, and stops the run by the rules
// of buildStop.
type BuildRun struct {
// BuildRun appends messages, builds their tree, and stops the run by the rules
// of buildStop.
type BuildRun struct {
// probeName is the agent name of a probe run. The cache key comes from
// it.
probeName = "Probe"
// probeName is the agent name of a probe run. The cache key comes from
// it.
probeName = "Probe"
+
+ // probeCallLimit is the most model calls of a probe run.
+ probeCallLimit = 660
)
// probe runs "onechat probe LOG COUNT [BUILDS]". It appends the first COUNT
// messages of LOG, one JSON object {kind, text} per line, to a new chat in
// probe/ in the data directory, and builds its tree with the real compactor.
// Before each user message it waits for the builds, as a turn does. It stops at
)
// probe runs "onechat probe LOG COUNT [BUILDS]". It appends the first COUNT
// messages of LOG, one JSON object {kind, text} per line, to a new chat in
// probe/ in the data directory, and builds its tree with the real compactor.
// Before each user message it waits for the builds, as a turn does. It stops at
-// the first failed call, after buildCallLimit calls, or when the used percent
+// the first failed call, after probeCallLimit calls, or when the used percent
// of a quota window grows by more than buildQuotaLimit points. At the end it
// reports the calls, the time per call, the calls at once, the cached share,
// the quota, the retries, and the line sizes. BUILDS, from 1 to buildMax,
// of a quota window grows by more than buildQuotaLimit points. At the end it
// reports the calls, the time per call, the calls at once, the cached share,
// the quota, the retries, and the line sizes. BUILDS, from 1 to buildMax,
usagePath := filepath.Join(root, "usage.jsonl")
client := newModelClient(address, auth, "onechat-"+probeName, usagePath)
usagePath := filepath.Join(root, "usage.jsonl")
client := newModelClient(address, auth, "onechat-"+probeName, usagePath)
- client.LimitCalls(buildCallLimit)
+ client.LimitCalls(probeCallLimit)
summarizer := ProbeSlotSummarizer{
inner: newCompactor(client, probePrompt, config.Compactor),
summarizer := ProbeSlotSummarizer{
inner: newCompactor(client, probePrompt, config.Compactor),
+// rebuildCallLimit is the most model calls of a rebuild. A rebuild summarizes
+// the whole merged log, which can need more calls than a probe sample, and the
+// quota stop of the build run still guards the account.
+const rebuildCallLimit = 1500
+
// rebuild merges added messages with the log of agent, in date order, and
// builds a new memory beside it. The caller holds the token lock. The model
// uses the original agent prompt and cache key. A failed or stopped build
// rebuild merges added messages with the log of agent, in date order, and
// builds a new memory beside it. The caller holds the token lock. The model
// uses the original agent prompt and cache key. A failed or stopped build
return "", fmt.Errorf("open rebuilt memory: %w", err)
}
return "", fmt.Errorf("open rebuilt memory: %w", err)
}
- client.LimitCalls(buildCallLimit)
+ client.LimitCalls(rebuildCallLimit)
run := BuildRun{
memory: memory,
run := BuildRun{
memory: memory,
"owner: " + owner,
fmt.Sprintf("bytes: %d (new batch text)", p.bytes),
fmt.Sprintf("messages: %d (merged log)", p.messages),
"owner: " + owner,
fmt.Sprintf("bytes: %d (new batch text)", p.bytes),
fmt.Sprintf("messages: %d (merged log)", p.messages),
- fmt.Sprintf("estimated calls: %.0f (about 1.3 per message, limit %d)", estimate, buildCallLimit),
+ fmt.Sprintf("estimated calls: %.0f (about 1.3 per message, limit %d)", estimate, rebuildCallLimit),
}
_, err = io.WriteString(out, strings.Join(lines, "\n")+"\n")
}
_, err = io.WriteString(out, strings.Join(lines, "\n")+"\n")
require.NoError(t, whatsappImport(t.Context(), []string{"-n", whatsappImportSample(t)}, &report))
require.Equal(t, before, rebuildTestSnapshot(t, agent.dir))
require.NoError(t, whatsappImport(t.Context(), []string{"-n", whatsappImportSample(t)}, &report))
require.Equal(t, before, rebuildTestSnapshot(t, agent.dir))
- for _, want := range []string{"chats: 1", "Book Club", "batches: 5", "dates: ", "cutoff: none", "bytes: ", "messages: 6", "estimated calls: 8", "owner: unknown"} {
+ for _, want := range []string{"chats: 1", "Book Club", "batches: 5", "dates: ", "cutoff: none", "bytes: ", "messages: 6", "estimated calls: 8 (about 1.3 per message, limit 1500)", "owner: unknown"} {
require.Contains(t, report.String(), want)
}
require.Contains(t, report.String(), want)
}