51 lines
2.5 KiB
Clojure
51 lines
2.5 KiB
Clojure
(ns tbd.agent.instructions-test
|
|
(:require [clojure.string :as str]
|
|
[clojure.test :refer [deftest is]]
|
|
[tbd.agent.instructions :as instructions]
|
|
[tbd.agent.prompt :as prompt]))
|
|
|
|
(defn- flat
|
|
"`text` on one line: the prompts are wrapped in the source, where they wrap is not the point."
|
|
[text]
|
|
(str/replace text #"\s+" " "))
|
|
|
|
(deftest chat-and-guide-share-the-instructions
|
|
(doseq [text (map flat [(instructions/chat) prompt/guide])]
|
|
(is (str/includes? text "Act, don't offer"))
|
|
(is (str/includes? text "in this same turn"))
|
|
(is (str/includes? text "Work it out yourself:"))
|
|
(is (str/includes? text "Say something was done only if a tool result says it was"))
|
|
(is (str/includes? text "Tic-tac-toe: check whose turn it is"))
|
|
(is (str/includes? text "Examples: "))))
|
|
|
|
(deftest chat-is-framed-as-the-in-page-chatbot
|
|
(let [text (instructions/chat)]
|
|
(is (str/includes? text "under your message"))
|
|
(is (str/includes? text "Chain calls without stopping"))
|
|
(is (str/includes? text "navigate there, then") "the chatbot's tools follow the page it is on")
|
|
(is (str/includes? (flat text) "\"Current state of the page\" below")
|
|
"it's told where to find what a read tool used to be for")
|
|
(is (not (str/includes? text "list_todos")) "it has no list_todos: the state has that")
|
|
(is (not (str/includes? text "get_tic_tac_toe")) "nor get_tic_tac_toe")))
|
|
|
|
(deftest chat-system-message-adds-page-and-tools
|
|
(is (= (instructions/chat) (instructions/chat-system-message nil nil nil)))
|
|
(let [text (instructions/chat-system-message "todos" [{:name "create_todo"} {:name "list_todos"}] nil)]
|
|
(is (str/includes? text "on the \"todos\" page"))
|
|
(is (str/includes? text "Its tools: create_todo, list_todos"))))
|
|
|
|
(deftest chat-system-message-adds-state
|
|
(is (= (instructions/chat) (instructions/chat-system-message nil nil {})) "empty state adds nothing")
|
|
(let [text (instructions/chat-system-message nil nil {:todos [{:title "milk" :done false}]})]
|
|
(is (str/includes? text "Current state of the page"))
|
|
(is (str/includes? text "never call a tool just to read it"))
|
|
(is (str/includes? text "\"title\":\"milk\""))))
|
|
|
|
(deftest a2a-has-no-in-page-framing
|
|
(let [text (instructions/a2a)]
|
|
(is (str/includes? text "Act, don't offer"))
|
|
(is (str/includes? text "Agent2Agent protocol"))
|
|
(is (str/includes? text "no page open"))
|
|
(is (not (str/includes? text "under your message")))
|
|
(is (str/includes? text "list_todos -> set_todo_done") "it has no state either: it reads first, like WebMCP's guide")))
|