|
178 | 178 | (into []))] |
179 | 179 | (map (comp merge-role renderer fs/file) prompts))) |
180 | 180 |
|
| 181 | +(declare conversation-loop) |
| 182 | + |
181 | 183 | (defn function-handler |
182 | 184 | "call function |
183 | 185 | params |
|
207 | 209 | (resolve pty-output) |
208 | 210 | (fail (format "call exited with non-zero code (%d): %s" exit-code pty-output)))) |
209 | 211 | (= "prompt" (:type definition)) ;; asynchronous call to another agent |
210 | | - (do |
211 | | - ;; TODO use the assistant here |
212 | | - (resolve "This is an NPM project."))) |
| 212 | + (let [{:keys [messages _finish-reason] :as m} |
| 213 | + (async/<!! (conversation-loop |
| 214 | + (:host-dir opts) |
| 215 | + user |
| 216 | + (:host-dir opts) |
| 217 | + (:ref definition)))] |
| 218 | + (jsonrpc/notify :message {:debug (with-out-str (pprint m))}) |
| 219 | + (resolve (->> messages |
| 220 | + (filter #(= "assistant" (:role %))) |
| 221 | + (last) |
| 222 | + :content)))) |
213 | 223 | (catch Throwable t |
214 | 224 | (fail (format "system failure %s" t)))) |
215 | 225 | (fail "no function found"))) |
|
240 | 250 | [& args] |
241 | 251 | (async/go-loop |
242 | 252 | [prompts (apply get-prompts args)] |
243 | | - (let [{:keys [messages finish-reason] :as m} (async/<!! (apply run-prompts prompts args))] |
| 253 | + (let [{:keys [messages finish-reason] :as m} |
| 254 | + (async/<!! (apply run-prompts prompts args))] |
244 | 255 | (if (= "tool_calls" finish-reason) |
245 | 256 | (do |
246 | 257 | (jsonrpc/notify :message {:debug (with-out-str (pprint m))}) |
247 | 258 | (recur (concat prompts messages))) |
248 | 259 | (do |
249 | 260 | (jsonrpc/notify :message {:debug (with-out-str (pprint m))}) |
250 | | - {:done finish-reason}))))) |
| 261 | + {:messages (concat prompts messages) :done finish-reason}))))) |
251 | 262 |
|
252 | 263 | (defn- -run-command |
253 | 264 | [& args] |
|
276 | 287 | (update-in m [:prompts] (fn [coll] (remove (fn [{:keys [type]}] (= type (second args))) coll))))) |
277 | 288 |
|
278 | 289 | (= "run" (first args)) |
279 | | - (async/<!! (apply conversation-loop (rest args))) |
| 290 | + (select-keys |
| 291 | + (async/<!! (apply conversation-loop (rest args))) |
| 292 | + [:done]) |
280 | 293 |
|
281 | 294 | :else |
282 | 295 | (apply get-prompts args))) |
|
0 commit comments