Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fix MCP OAuth credentials cache not invalidating when the server URL changes.
- Add `isSubagent` condition variable for chat system instructions

## 0.112.0

Expand Down
22 changes: 13 additions & 9 deletions src/eca/features/prompt.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,21 @@
(str "\n<additionalContext from=\"chatStart\">\n" startup-ctx "\n</additionalContext>\n\n"))
"</contexts>"))

(defn ^:private ->base-selmer-ctx [all-tools db]
(merge
{:workspaceRoots (shared/workspaces-as-str db)}
(reduce
(fn [m tool]
(assoc m (keyword (str "toolEnabled_" (:full-name tool))) true))
{}
all-tools)))
(defn ^:private ->base-selmer-ctx
([all-tools db]
(->base-selmer-ctx all-tools nil db))
([all-tools chat-id db]
(merge
{:workspaceRoots (shared/workspaces-as-str db)
:isSubagent (boolean (get-in db [:chats chat-id :subagent]))}
(reduce
(fn [m tool]
(assoc m (keyword (str "toolEnabled_" (:full-name tool))) true))
{}
all-tools))))

(defn build-chat-instructions [refined-contexts rules skills repo-map* agent-name config chat-id all-tools db]
(let [selmer-ctx (->base-selmer-ctx all-tools db)]
(let [selmer-ctx (->base-selmer-ctx all-tools chat-id db)]
(multi-str
(selmer/render (eca-chat-prompt agent-name config) selmer-ctx)
(when (seq rules)
Expand Down
14 changes: 14 additions & 0 deletions test/eca/features/prompt_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@
(is (string/includes? result "<resource uri=\"custom://my-resource\">some-cool-content</resource>"))
(is (string/includes? result "</contexts>"))
(is (string? result)))))

(deftest build-instructions-subagent-condition-test
(let [config {:prompts {:chat "{% if isSubagent %}SUBAGENT{% endif %}{% if not isSubagent %}MAIN{% endif %}"}}]
(testing "renders subagent-only content for subagent chats"
(let [db (assoc-in (h/db) [:chats "sub-chat" :subagent] {:name "explorer"})
result (prompt/build-chat-instructions [] [] [] (delay "TREE") "code" config "sub-chat" [] db)]
(is (string/includes? result "SUBAGENT"))
(is (not (string/includes? result "MAIN")))))

(testing "renders main-agent-only content for non-subagent chats"
(let [db (assoc-in (h/db) [:chats "main-chat"] {:id "main-chat"})
result (prompt/build-chat-instructions [] [] [] (delay "TREE") "code" config "main-chat" [] db)]
(is (string/includes? result "MAIN"))
(is (not (string/includes? result "SUBAGENT")))))))
Loading