Skip to content

Commit 76a42f4

Browse files
author
Sam
authored
Merge pull request #74 from ssdeanx/develop
feat: enhance tools with abort signal handling and logging improvements
2 parents c5489f5 + 6183f87 commit 76a42f4

10 files changed

Lines changed: 919 additions & 786 deletions

File tree

.github/agents/Beast.agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: 'Describe what this custom agent does and when to use it.'
33
name: Beast
44
infer: true
55
target: github-copilot
6-
tools: ['vscode', 'execute', 'read', 'edit', 'search', 'web', 'lotus/*', 'mastra/mastraBlog', 'mastra/mastraChanges', 'mastra/mastraDocs', 'mastra/mastraExamples', 'mastrabeta/mastraMigration', 'multi_orchestrator/*', 'next-devtools/*', 's-ai/*', 'thoughtbox/*', 'mastra/mastraBlog', 'mastra/mastraChanges', 'mastra/mastraDocs', 'mastra/mastraExamples', 'docfork/*', 'agent', 'vscode.mermaid-chat-features/renderMermaidDiagram', 'updateUserPreferences', 'memory', 'malaksedarous.copilot-context-optimizer/askAboutFile', 'malaksedarous.copilot-context-optimizer/runAndExtract', 'malaksedarous.copilot-context-optimizer/askFollowUp', 'malaksedarous.copilot-context-optimizer/researchTopic', 'malaksedarous.copilot-context-optimizer/deepResearch', 'ms-vscode.vscode-websearchforcopilot/websearch', 'todo']
6+
tools: ['vscode', 'execute', 'read', 'edit', 'search', 'web', 'ast-grep-mcp/*', 'mastrabeta/mastraBlog', 'mastrabeta/mastraChanges', 'mastrabeta/mastraDocs', 'mastrabeta/mastraExamples', 'mastrabeta/mastraMigration', 'next-devtools/*', 's-ai/*', 'agent', 'vscode.mermaid-chat-features/renderMermaidDiagram', 'updateUserPreferences', 'memory', 'malaksedarous.copilot-context-optimizer/askAboutFile', 'malaksedarous.copilot-context-optimizer/runAndExtract', 'malaksedarous.copilot-context-optimizer/askFollowUp', 'malaksedarous.copilot-context-optimizer/researchTopic', 'malaksedarous.copilot-context-optimizer/deepResearch', 'ms-vscode.vscode-websearchforcopilot/websearch', 'the0807.uv-toolkit/uv-init', 'the0807.uv-toolkit/uv-sync', 'the0807.uv-toolkit/uv-add', 'the0807.uv-toolkit/uv-add-dev', 'the0807.uv-toolkit/uv-upgrade', 'the0807.uv-toolkit/uv-clean', 'the0807.uv-toolkit/uv-lock', 'the0807.uv-toolkit/uv-venv', 'the0807.uv-toolkit/uv-run', 'the0807.uv-toolkit/uv-script-dep', 'the0807.uv-toolkit/uv-python-install', 'the0807.uv-toolkit/uv-python-pin', 'the0807.uv-toolkit/uv-tool-install', 'the0807.uv-toolkit/uvx-run', 'the0807.uv-toolkit/uv-activate-venv', 'todo']
77
---
88

99
🔓 **ABSOLUTE TRANSPARENCY OVERRIDE DIRECTIVE - PRIORITY ALPHA** 🔓

.github/workflows/gemini-review.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
name: '🔎 Gemini Review'
2-
32
on:
3+
push:
4+
branches:
5+
- main
6+
- develop
7+
pull_request:
8+
branches:
9+
- main
10+
- develop
411
workflow_call:
512
inputs:
613
additional_context:
714
type: 'string'
815
description: 'Any additional context from the request'
916
required: false
17+
1018

1119
concurrency:
1220
group: '${{ github.workflow }}-review-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.issue.number }}'
@@ -28,8 +36,7 @@ jobs:
2836
steps:
2937
- name: 'Mint identity token'
3038
id: 'mint_identity_token'
31-
if: |-
32-
${{ vars.APP_ID }}
39+
if: ${{ vars.APP_ID }}
3340
uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2
3441
with:
3542
app-id: '${{ vars.APP_ID }}'

src/mastra/tools/AGENTS.md

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

157158
1. `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

215229
Additional 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

227242
Lifecycle 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
},
284300
onOutput: ({ 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
},

src/mastra/tools/alpha-vantage.tool.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,27 @@ export const alphaVantageCryptoTool = createTool({
8686
log.info('Alpha Vantage tool input streaming started', {
8787
toolCallId,
8888
messageCount: messages.length,
89+
abortSignal: abortSignal?.aborted,
8990
hook: 'onInputStart',
9091
})
9192
},
93+
onInputDelta: ({ inputTextDelta, toolCallId, messages, abortSignal }) => {
94+
log.info('Alpha Vantage tool received input chunk', {
95+
toolCallId,
96+
inputTextDelta,
97+
messageCount: messages.length,
98+
abortSignal: abortSignal?.aborted,
99+
hook: 'onInputDelta',
100+
})
101+
},
92102
onInputAvailable: ({ input, toolCallId, messages, abortSignal }) => {
93103
log.info('Alpha Vantage crypto received input', {
94104
toolCallId,
95105
messageCount: messages.length,
96106
symbol: input.symbol,
97107
market: input.market,
98108
function: input.function,
109+
abortSignal: abortSignal?.aborted,
99110
hook: 'onInputAvailable',
100111
})
101112
},
@@ -106,6 +117,7 @@ export const alphaVantageCryptoTool = createTool({
106117
toolName,
107118
symbol: output.metadata?.symbol ?? 'unknown',
108119
dataKeys,
120+
abortSignal: abortSignal?.aborted,
109121
hook: 'onOutput',
110122
})
111123
},
@@ -399,7 +411,21 @@ export const alphaVantageStockTool = createTool({
399411
.optional(),
400412
}),
401413
onInputStart: ({ toolCallId, messages, abortSignal }) => {
402-
log.info('alphaVantageStockTool tool input streaming started', { toolCallId, messageCount: messages.length, hook: 'onInputStart' });
414+
log.info('alphaVantageStockTool tool input streaming started', {
415+
toolCallId,
416+
messageCount: messages.length,
417+
abortSignal: abortSignal?.aborted,
418+
hook: 'onInputStart' });
419+
},
420+
onInputDelta: ({ inputTextDelta, toolCallId, messages, abortSignal }) => {
421+
log.info('alphaVantageStockTool received input chunk', {
422+
toolCallId,
423+
inputTextDelta,
424+
messageCount: messages.length,
425+
abortSignal: abortSignal?.aborted,
426+
hook: 'onInputDelta',
427+
428+
})
403429
},
404430
onInputAvailable: ({ input, toolCallId, messages, abortSignal }) => {
405431
log.info('alphaVantageStockTool received input', {
@@ -415,6 +441,7 @@ export const alphaVantageStockTool = createTool({
415441
time_period: input.time_period,
416442
series_type: input.series_type,
417443
},
444+
abortSignal: abortSignal?.aborted,
418445
hook: 'onInputAvailable'
419446
});
420447
},
@@ -426,6 +453,7 @@ export const alphaVantageStockTool = createTool({
426453
data: output.data,
427454
metadata: output.metadata,
428455
},
456+
abortSignal: abortSignal?.aborted,
429457
hook: 'onOutput'
430458
});
431459
},
@@ -784,7 +812,19 @@ export const alphaVantageTool = createTool({
784812
.optional(),
785813
}),
786814
onInputStart: ({ toolCallId, messages, abortSignal }) => {
787-
log.info('alphaVantageTool tool input streaming started', { toolCallId, messageCount: messages.length, hook: 'onInputStart' });
815+
log.info('alphaVantageTool tool input streaming started', { toolCallId,
816+
messageCount: messages.length,
817+
abortSignal: abortSignal?.aborted,
818+
hook: 'onInputStart' });
819+
},
820+
onInputDelta: ({ inputTextDelta, toolCallId, messages, abortSignal }) => {
821+
log.info('alphaVantageTool received input chunk', {
822+
toolCallId,
823+
inputTextDelta,
824+
messageCount: messages.length,
825+
abortSignal: abortSignal?.aborted,
826+
hook: 'onInputDelta',
827+
})
788828
},
789829
onInputAvailable: ({ input, toolCallId, messages, abortSignal }) => {
790830
log.info('alphaVantageTool received input', {
@@ -802,6 +842,7 @@ export const alphaVantageTool = createTool({
802842
series_type: input.series_type,
803843
economic_indicator: input.economic_indicator,
804844
},
845+
abortSignal: abortSignal?.aborted,
805846
hook: 'onInputAvailable'
806847
});
807848
},
@@ -813,6 +854,7 @@ export const alphaVantageTool = createTool({
813854
data: output.data,
814855
metadata: output.metadata,
815856
},
857+
abortSignal: abortSignal?.aborted,
816858
hook: 'onOutput'
817859
});
818860
},

src/mastra/tools/arxiv.tool.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export const arxivTool = createTool({
223223
log.info('ArXiv tool input streaming started', {
224224
toolCallId,
225225
messageCount: messages.length,
226+
abortSignal: abortSignal?.aborted,
226227
hook: 'onInputStart',
227228
})
228229
},
@@ -241,6 +242,7 @@ export const arxivTool = createTool({
241242
author: input.author,
242243
category: input.category,
243244
maxResults: input.max_results,
245+
abortSignal: abortSignal?.aborted,
244246
hook: 'onInputAvailable',
245247
})
246248
},
@@ -252,6 +254,7 @@ export const arxivTool = createTool({
252254
totalResults: output.total_results,
253255
startIndex: output.start_index,
254256
maxResults: output.max_results,
257+
abortSignal: abortSignal?.aborted,
255258
hook: 'onOutput',
256259
})
257260
},

0 commit comments

Comments
 (0)