@@ -147,17 +147,19 @@ Mastra tools support **lifecycle hooks** that allow monitoring and reacting to d
147147### Available Hooks
148148
149149- ** ` onInputStart ` ** - Called when tool call input streaming begins
150+ - ** ` onInputDelta ` ** - Called for each incremental chunk of input text as it streams in
150151- ** ` onInputAvailable ` ** - Called when complete tool input is available and parsed
151152- ** ` onOutput ` ** - Called after tool execution completes successfully
152153
153154### Hook Execution Order
154155
155- For a typical tool call:
156+ For a typical streaming tool call, the hooks are invoked in this order :
156157
1571581 . ` onInputStart ` → Input streaming begins
158- 2 . ` onInputAvailable ` → Complete input is parsed and validated
159- 3 . Tool's ` execute ` function runs
160- 4 . ` onOutput ` → Tool has completed successfully
159+ 2 . ` onInputDelta ` → Called multiple times as chunks arrive
160+ 3 . ` onInputAvailable ` → Complete input is parsed and validated
161+ 4 . Tool's ` execute ` function runs
162+ 5 . ` onOutput ` → Tool has completed successfully
161163
162164### Implementation Pattern
163165
@@ -179,14 +181,25 @@ export const exampleTool = createTool({
179181 log .info (' Tool input streaming started' , {
180182 toolCallId ,
181183 messageCount: messages .length ,
184+ abortSignal: abortSignal ?.aborted ,
182185 hook: ' onInputStart' ,
183186 })
184187 },
188+ onInputDelta : ({ inputTextDelta , toolCallId , messages , abortSignal }) => {
189+ log .info (' Tool received input chunk' , {
190+ toolCallId ,
191+ inputTextDelta ,
192+ messageCount: messages .length ,
193+ abortSignal: abortSignal ?.aborted ,
194+ hook: ' onInputDelta' ,
195+ })
196+ },
185197 onInputAvailable : ({ input , toolCallId , messages , abortSignal }) => {
186198 log .info (' Tool received input' , {
187199 toolCallId ,
188200 messageCount: messages .length ,
189201 inputData: { param: input .param },
202+ abortSignal: abortSignal ?.aborted ,
190203 hook: ' onInputAvailable' ,
191204 })
192205 },
@@ -195,6 +208,7 @@ export const exampleTool = createTool({
195208 toolCallId ,
196209 toolName ,
197210 outputData: { result: output .result },
211+ abortSignal: abortSignal ?.aborted ,
198212 hook: ' onOutput' ,
199213 })
200214 },
@@ -214,7 +228,8 @@ All hooks receive a parameter object with:
214228
215229Additional parameters vary by hook:
216230
217- - ` onInputStart ` , ` onInputAvailable ` : ` messages ` (array): The conversation messages at the time of the tool call
231+ - ` onInputStart ` , ` onInputDelta ` , ` onInputAvailable ` : ` messages ` (array): The conversation messages at the time of the tool call
232+ - ` onInputDelta ` : ` inputTextDelta ` (string): The incremental text chunk
218233- ` onInputAvailable ` : ` input ` : The validated input data (typed according to ` inputSchema ` )
219234- ` onOutput ` : ` output ` : The tool's return value (typed according to ` outputSchema ` ) and ` toolName ` (string)
220235
@@ -226,25 +241,25 @@ Hook errors are caught and logged automatically, but do not prevent tool executi
226241
227242Lifecycle hooks have been implemented in the following tools:
228243
229- | Tool | Hooks Implemented | Purpose |
230- | -------------------------------- | ------------------------------------------------- | -------------------------------- |
231- | ` weather-tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Weather data monitoring |
232- | ` github.ts ` (listRepositories) | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Repository listing analytics |
233- | ` code-search.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Search analytics |
234- | ` csv-to-json.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Data conversion monitoring |
235- | ` web-scraper-tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Scraping analytics |
236- | ` jwt-auth.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Security monitoring |
237- | ` alpha-vantage.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Financial data monitoring |
238- | ` fs.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | File system operation monitoring |
239- | ` json-to-csv.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Data conversion monitoring |
240- | ` serpapi-search.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Search query analytics |
241- | ` find-symbol.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Symbol search analytics |
242- | ` polygon-tools.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Financial market data monitoring |
243- | ` arxiv.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Academic paper search analytics |
244- | ` browser-tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Browser automation monitoring |
245- | ` serpapi-academic-local.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Google Scholar search analytics |
246- | ` serpapi-news-trends.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Google News search analytics |
247- | ` calendar-tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Calendar events monitoring |
244+ | Tool | Hooks Implemented | Purpose |
245+ | -------------------------------- | ------------------------------------------------------------------ | -------------------------------- |
246+ | ` weather-tool.ts ` | ✅ ` onInputStart ` , ` onInputDelta ` , ` onInputAvailable ` , ` onOutput ` | Weather data monitoring |
247+ | ` github.ts ` (listRepositories) | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Repository listing analytics |
248+ | ` code-search.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Search analytics |
249+ | ` csv-to-json.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Data conversion monitoring |
250+ | ` web-scraper-tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Scraping analytics |
251+ | ` jwt-auth.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Security monitoring |
252+ | ` alpha-vantage.tool.ts ` | ✅ ` onInputStart ` , ` onInputDelta ` , ` onInputAvailable ` , ` onOutput ` | Financial data monitoring |
253+ | ` fs.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | File system operation monitoring |
254+ | ` json-to-csv.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Data conversion monitoring |
255+ | ` serpapi-search.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Search query analytics |
256+ | ` find-symbol.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Symbol search analytics |
257+ | ` polygon-tools.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Financial market data monitoring |
258+ | ` arxiv.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Academic paper search analytics |
259+ | ` browser-tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Browser automation monitoring |
260+ | ` serpapi-academic-local.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Google Scholar search analytics |
261+ | ` serpapi-news-trends.tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Google News search analytics |
262+ | ` calendar-tool.ts ` | ✅ ` onInputStart ` , ` onInputAvailable ` , ` onOutput ` | Calendar events monitoring |
248263
249264### Benefits
250265
@@ -278,7 +293,8 @@ onInputAvailable: ({ input, toolCallId, messages, abortSignal }) => {
278293 inputField1: input.inputField1,
279294 inputField2: input.inputField2
280295 },
281- hook: ' onInputAvailable'
296+ abortSignal: abortSignal? .aborted,
297+ hook: ' onInputAvailable' ,
282298 });
283299},
284300onOutput: ({ output, toolCallId, toolName, abortSignal }) => {
@@ -288,6 +304,7 @@ onOutput: ({ output, toolCallId, toolName, abortSignal }) => {
288304 outputData: {
289305 // Add output fields here
290306 },
307+ abortSignal: abortSignal? .aborted,
291308 hook: ' onOutput'
292309 });
293310},
0 commit comments