Skip to content

Commit 641d534

Browse files
Optimize agent context engineering to reduce cost and support smart searches (#274)
1 parent a816213 commit 641d534

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

src/yetibot/core/commands/agent.clj

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,12 @@
358358
"the missing detail. NEVER invent work or report an unrelated summary like "
359359
"\"checked all repos, everything green\".\n"
360360
"- If you need more background context than what is provided in the thread "
361-
"context, you are highly encouraged to search the entire channel's history "
362-
"using the `yetibot` tool with the `history` command (e.g., `history` or "
363-
"`history | grep keyword`). It is your job as an autonomous agent to "
364-
"perform this extra search when needed!\n\n"
361+
"context (which is kept short for efficient context engineering and low cost), "
362+
"you are highly encouraged to search the channel's history using smart "
363+
"Discord/SQL search queries via the `yetibot` tool and the `history` command "
364+
"(e.g., `history | grep keyword`). This executes efficient, targeted database queries "
365+
"and minimizes prompt costs! It is your job as an autonomous agent to perform "
366+
"this extra search when needed.\n\n"
365367
"The codebase (so you can go straight to the right place — don't rediscover "
366368
"it). The org is `yetibot`:\n"
367369
"- `yetibot/core` — the library: chat commands, adapters, and most logic.\n"
@@ -576,16 +578,13 @@
576578
(catch Exception e (debug "delete-msg! failed:" (.getMessage e)))))
577579

578580
(defn- all-channel-messages
579-
"Every message in a channel/thread, paginating past Discord's 100-per-call cap
580-
(bounded for safety). Discord returns newest-first; callers sort as needed."
581+
"The most recent messages in a channel/thread (bounded to 20 for cost efficiency)."
581582
[channel-id]
582-
(loop [before nil acc []]
583-
(let [opts (concat [:limit 100] (when before [:before before]))
584-
batch (vec @(apply discord/get-channel-messages! (rest-conn) channel-id opts))
585-
acc' (into acc batch)]
586-
(if (or (< (count batch) 100) (>= (count acc') 500))
587-
acc'
588-
(recur (:id (peek batch)) acc')))))
583+
(try
584+
(vec @(discord/get-channel-messages! (rest-conn) channel-id :limit 20))
585+
(catch Exception e
586+
(debug "all-channel-messages failed:" (.getMessage e))
587+
[])))
589588

590589
(defn- thread-context
591590
"The full thread conversation, oldest-first, prefixed with the thread topic —

test/yetibot/core/test/commands/agent.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
(agent/build-agent-prompt "do x" nil nil) => (contains "Yetibot"))
5454
(fact "tells gemini to use yetibot tool to run yetibot commands"
5555
(agent/build-agent-prompt "do x" nil nil) => (contains "yetibot"))
56-
(fact "encourages searching entire channel if needed"
57-
(agent/build-agent-prompt "do x" nil nil) => (contains "search the entire channel's history")))
56+
(fact "encourages searching channel history if needed"
57+
(agent/build-agent-prompt "do x" nil nil) => (contains "search the channel's history")))
5858

5959
(facts "about parse-json-response"
6060
(fact "pulls the response field"

0 commit comments

Comments
 (0)