|
69 | 69 | ;; Tool conversion |
70 | 70 |
|
71 | 71 | (defn- adapt-tool-fn |
72 | | - "Adapts clojure-mcp callback-style tool to langchain4clj return style." |
| 72 | + "Adapts clojure-mcp callback-style tool to langchain4clj return style. |
| 73 | + Includes a 5-minute timeout to prevent indefinite blocking." |
73 | 74 | [callback-style-fn] |
74 | 75 | (fn [args] |
75 | 76 | (let [result-promise (promise)] |
|
83 | 84 | (if (sequential? result) |
84 | 85 | (string/join "\n\n" result) |
85 | 86 | (str result)))))) |
86 | | - @result-promise))) |
| 87 | + (let [result (deref result-promise 300000 ::timeout)] |
| 88 | + (if (= result ::timeout) |
| 89 | + "Tool Error: Execution timed out after 5 minutes" |
| 90 | + result))))) |
87 | 91 |
|
88 | 92 | (defn- registration-map->tool-map |
89 | 93 | "Converts clojure-mcp tool registration map to langchain4clj tool map format." |
|
127 | 131 |
|
128 | 132 | ;; Assistant creation |
129 | 133 |
|
130 | | -(defn create-assistant-fn [{:keys [model memory tools system-message]}] |
| 134 | +(defn create-assistant-fn |
| 135 | + "Creates an assistant function with the given configuration. |
| 136 | + |
| 137 | + Options: |
| 138 | + - :model - The LLM model to use |
| 139 | + - :memory - Chat memory instance |
| 140 | + - :tools - Sequence of tool registration maps |
| 141 | + - :system-message - System message for the assistant |
| 142 | + - :max-iterations - Maximum tool iterations (default: 10)" |
| 143 | + [{:keys [model memory tools system-message max-iterations] |
| 144 | + :or {max-iterations 10}}] |
131 | 145 | (assistant/create-assistant |
132 | 146 | {:model model |
133 | 147 | :memory memory |
134 | 148 | :tools (when (seq tools) (convert-tools tools)) |
135 | 149 | :system-message system-message |
136 | | - :max-iterations 10})) |
| 150 | + :max-iterations max-iterations})) |
137 | 151 |
|
138 | 152 | ;; Message helpers |
139 | 153 |
|
|
143 | 157 | (defn system-message [text] |
144 | 158 | (messages/edn->message {:type :system :text text})) |
145 | 159 |
|
146 | | -(defn user-message-with-contents [content-items] |
147 | | - (let [text (string/join "\n" (map #(.text %) content-items))] |
148 | | - (messages/edn->message {:type :user :text text}))) |
| 160 | + |
0 commit comments