crewx 0.3.0 → 0.4.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/bin/crewx.js +6 -0
  2. package/package.json +9 -107
  3. package/LICENSE +0 -201
  4. package/README.md +0 -234
  5. package/crewx.yaml +0 -2069
  6. package/dist/agent.types.d.ts +0 -117
  7. package/dist/agent.types.js +0 -16
  8. package/dist/agent.types.js.map +0 -1
  9. package/dist/ai-provider.service.d.ts +0 -36
  10. package/dist/ai-provider.service.js +0 -191
  11. package/dist/ai-provider.service.js.map +0 -1
  12. package/dist/ai.service.d.ts +0 -57
  13. package/dist/ai.service.js +0 -629
  14. package/dist/ai.service.js.map +0 -1
  15. package/dist/app.module.d.ts +0 -5
  16. package/dist/app.module.js +0 -103
  17. package/dist/app.module.js.map +0 -1
  18. package/dist/cli/agent.handler.d.ts +0 -2
  19. package/dist/cli/agent.handler.js +0 -140
  20. package/dist/cli/agent.handler.js.map +0 -1
  21. package/dist/cli/chat.handler.d.ts +0 -19
  22. package/dist/cli/chat.handler.js +0 -431
  23. package/dist/cli/chat.handler.js.map +0 -1
  24. package/dist/cli/cli.handler.d.ts +0 -4
  25. package/dist/cli/cli.handler.js +0 -97
  26. package/dist/cli/cli.handler.js.map +0 -1
  27. package/dist/cli/doctor.handler.d.ts +0 -36
  28. package/dist/cli/doctor.handler.js +0 -382
  29. package/dist/cli/doctor.handler.js.map +0 -1
  30. package/dist/cli/execute.handler.d.ts +0 -2
  31. package/dist/cli/execute.handler.js +0 -319
  32. package/dist/cli/execute.handler.js.map +0 -1
  33. package/dist/cli/help.handler.d.ts +0 -2
  34. package/dist/cli/help.handler.js +0 -10
  35. package/dist/cli/help.handler.js.map +0 -1
  36. package/dist/cli/init.handler.d.ts +0 -26
  37. package/dist/cli/init.handler.js +0 -450
  38. package/dist/cli/init.handler.js.map +0 -1
  39. package/dist/cli/mcp.handler.d.ts +0 -3
  40. package/dist/cli/mcp.handler.js +0 -121
  41. package/dist/cli/mcp.handler.js.map +0 -1
  42. package/dist/cli/query.handler.d.ts +0 -2
  43. package/dist/cli/query.handler.js +0 -380
  44. package/dist/cli/query.handler.js.map +0 -1
  45. package/dist/cli/templates.handler.d.ts +0 -2
  46. package/dist/cli/templates.handler.js +0 -100
  47. package/dist/cli/templates.handler.js.map +0 -1
  48. package/dist/cli-options.d.ts +0 -29
  49. package/dist/cli-options.js +0 -234
  50. package/dist/cli-options.js.map +0 -1
  51. package/dist/config/timeout.config.d.ts +0 -14
  52. package/dist/config/timeout.config.js +0 -34
  53. package/dist/config/timeout.config.js.map +0 -1
  54. package/dist/constants.d.ts +0 -4
  55. package/dist/constants.js +0 -8
  56. package/dist/constants.js.map +0 -1
  57. package/dist/conversation/base-conversation-history.provider.d.ts +0 -12
  58. package/dist/conversation/base-conversation-history.provider.js +0 -45
  59. package/dist/conversation/base-conversation-history.provider.js.map +0 -1
  60. package/dist/conversation/cli-conversation-history.provider.d.ts +0 -16
  61. package/dist/conversation/cli-conversation-history.provider.js +0 -111
  62. package/dist/conversation/cli-conversation-history.provider.js.map +0 -1
  63. package/dist/conversation/conversation-config.d.ts +0 -9
  64. package/dist/conversation/conversation-config.js +0 -25
  65. package/dist/conversation/conversation-config.js.map +0 -1
  66. package/dist/conversation/conversation-history.interface.d.ts +0 -25
  67. package/dist/conversation/conversation-history.interface.js +0 -3
  68. package/dist/conversation/conversation-history.interface.js.map +0 -1
  69. package/dist/conversation/conversation-provider.factory.d.ts +0 -10
  70. package/dist/conversation/conversation-provider.factory.js +0 -50
  71. package/dist/conversation/conversation-provider.factory.js.map +0 -1
  72. package/dist/conversation/conversation-storage.service.d.ts +0 -16
  73. package/dist/conversation/conversation-storage.service.js +0 -220
  74. package/dist/conversation/conversation-storage.service.js.map +0 -1
  75. package/dist/conversation/index.d.ts +0 -7
  76. package/dist/conversation/index.js +0 -24
  77. package/dist/conversation/index.js.map +0 -1
  78. package/dist/conversation/slack-conversation-history.provider.d.ts +0 -28
  79. package/dist/conversation/slack-conversation-history.provider.js +0 -278
  80. package/dist/conversation/slack-conversation-history.provider.js.map +0 -1
  81. package/dist/crewx.tool.d.ts +0 -332
  82. package/dist/crewx.tool.js +0 -1463
  83. package/dist/crewx.tool.js.map +0 -1
  84. package/dist/guards/bearer-auth.guard.d.ts +0 -7
  85. package/dist/guards/bearer-auth.guard.js +0 -44
  86. package/dist/guards/bearer-auth.guard.js.map +0 -1
  87. package/dist/health.controller.d.ts +0 -6
  88. package/dist/health.controller.js +0 -32
  89. package/dist/health.controller.js.map +0 -1
  90. package/dist/knowledge/DocumentManager.d.ts +0 -4
  91. package/dist/knowledge/DocumentManager.js +0 -119
  92. package/dist/knowledge/DocumentManager.js.map +0 -1
  93. package/dist/main.d.ts +0 -1
  94. package/dist/main.js +0 -268
  95. package/dist/main.js.map +0 -1
  96. package/dist/mcp.controller.d.ts +0 -8
  97. package/dist/mcp.controller.js +0 -62
  98. package/dist/mcp.controller.js.map +0 -1
  99. package/dist/project.service.d.ts +0 -44
  100. package/dist/project.service.js +0 -299
  101. package/dist/project.service.js.map +0 -1
  102. package/dist/providers/ai-provider.interface.d.ts +0 -50
  103. package/dist/providers/ai-provider.interface.js +0 -23
  104. package/dist/providers/ai-provider.interface.js.map +0 -1
  105. package/dist/providers/base-ai.provider.d.ts +0 -50
  106. package/dist/providers/base-ai.provider.js +0 -624
  107. package/dist/providers/base-ai.provider.js.map +0 -1
  108. package/dist/providers/claude.provider.d.ts +0 -25
  109. package/dist/providers/claude.provider.js +0 -362
  110. package/dist/providers/claude.provider.js.map +0 -1
  111. package/dist/providers/codex.provider.d.ts +0 -17
  112. package/dist/providers/codex.provider.js +0 -99
  113. package/dist/providers/codex.provider.js.map +0 -1
  114. package/dist/providers/copilot.provider.d.ts +0 -25
  115. package/dist/providers/copilot.provider.js +0 -266
  116. package/dist/providers/copilot.provider.js.map +0 -1
  117. package/dist/providers/dynamic-provider.factory.d.ts +0 -55
  118. package/dist/providers/dynamic-provider.factory.js +0 -587
  119. package/dist/providers/dynamic-provider.factory.js.map +0 -1
  120. package/dist/providers/gemini.provider.d.ts +0 -22
  121. package/dist/providers/gemini.provider.js +0 -147
  122. package/dist/providers/gemini.provider.js.map +0 -1
  123. package/dist/services/agent-loader.service.d.ts +0 -29
  124. package/dist/services/agent-loader.service.js +0 -370
  125. package/dist/services/agent-loader.service.js.map +0 -1
  126. package/dist/services/auth.service.d.ts +0 -9
  127. package/dist/services/auth.service.js +0 -47
  128. package/dist/services/auth.service.js.map +0 -1
  129. package/dist/services/config-validator.service.d.ts +0 -28
  130. package/dist/services/config-validator.service.js +0 -467
  131. package/dist/services/config-validator.service.js.map +0 -1
  132. package/dist/services/config.service.d.ts +0 -45
  133. package/dist/services/config.service.js +0 -180
  134. package/dist/services/config.service.js.map +0 -1
  135. package/dist/services/context-enhancement.service.d.ts +0 -13
  136. package/dist/services/context-enhancement.service.js +0 -169
  137. package/dist/services/context-enhancement.service.js.map +0 -1
  138. package/dist/services/document-loader.service.d.ts +0 -16
  139. package/dist/services/document-loader.service.js +0 -137
  140. package/dist/services/document-loader.service.js.map +0 -1
  141. package/dist/services/help.service.d.ts +0 -5
  142. package/dist/services/help.service.js +0 -117
  143. package/dist/services/help.service.js.map +0 -1
  144. package/dist/services/intelligent-compression.service.d.ts +0 -20
  145. package/dist/services/intelligent-compression.service.js +0 -179
  146. package/dist/services/intelligent-compression.service.js.map +0 -1
  147. package/dist/services/mcp-client.service.d.ts +0 -26
  148. package/dist/services/mcp-client.service.js +0 -81
  149. package/dist/services/mcp-client.service.js.map +0 -1
  150. package/dist/services/parallel-processing.service.d.ts +0 -108
  151. package/dist/services/parallel-processing.service.js +0 -268
  152. package/dist/services/parallel-processing.service.js.map +0 -1
  153. package/dist/services/remote-agent.service.d.ts +0 -49
  154. package/dist/services/remote-agent.service.js +0 -215
  155. package/dist/services/remote-agent.service.js.map +0 -1
  156. package/dist/services/result-formatter.service.d.ts +0 -27
  157. package/dist/services/result-formatter.service.js +0 -126
  158. package/dist/services/result-formatter.service.js.map +0 -1
  159. package/dist/services/task-management.service.d.ts +0 -63
  160. package/dist/services/task-management.service.js +0 -272
  161. package/dist/services/task-management.service.js.map +0 -1
  162. package/dist/services/template.service.d.ts +0 -36
  163. package/dist/services/template.service.js +0 -195
  164. package/dist/services/template.service.js.map +0 -1
  165. package/dist/services/tool-call.service.d.ts +0 -53
  166. package/dist/services/tool-call.service.js +0 -1061
  167. package/dist/services/tool-call.service.js.map +0 -1
  168. package/dist/slack/formatters/message.formatter.d.ts +0 -25
  169. package/dist/slack/formatters/message.formatter.js +0 -246
  170. package/dist/slack/formatters/message.formatter.js.map +0 -1
  171. package/dist/slack/slack-bot.d.ts +0 -24
  172. package/dist/slack/slack-bot.js +0 -467
  173. package/dist/slack/slack-bot.js.map +0 -1
  174. package/dist/stderr.logger.d.ts +0 -8
  175. package/dist/stderr.logger.js +0 -26
  176. package/dist/stderr.logger.js.map +0 -1
  177. package/dist/tsconfig.tsbuildinfo +0 -1
  178. package/dist/utils/config-utils.d.ts +0 -15
  179. package/dist/utils/config-utils.js +0 -69
  180. package/dist/utils/config-utils.js.map +0 -1
  181. package/dist/utils/error-utils.d.ts +0 -3
  182. package/dist/utils/error-utils.js +0 -27
  183. package/dist/utils/error-utils.js.map +0 -1
  184. package/dist/utils/math-utils.d.ts +0 -3
  185. package/dist/utils/math-utils.js +0 -10
  186. package/dist/utils/math-utils.js.map +0 -1
  187. package/dist/utils/mcp-installer.d.ts +0 -20
  188. package/dist/utils/mcp-installer.js +0 -199
  189. package/dist/utils/mcp-installer.js.map +0 -1
  190. package/dist/utils/mention-parser.d.ts +0 -18
  191. package/dist/utils/mention-parser.js +0 -136
  192. package/dist/utils/mention-parser.js.map +0 -1
  193. package/dist/utils/simple-security.d.ts +0 -3
  194. package/dist/utils/simple-security.js +0 -20
  195. package/dist/utils/simple-security.js.map +0 -1
  196. package/dist/utils/stdin-utils.d.ts +0 -27
  197. package/dist/utils/stdin-utils.js +0 -130
  198. package/dist/utils/stdin-utils.js.map +0 -1
  199. package/dist/utils/string-utils.d.ts +0 -1
  200. package/dist/utils/string-utils.js +0 -10
  201. package/dist/utils/string-utils.js.map +0 -1
  202. package/dist/utils/template-processor.d.ts +0 -32
  203. package/dist/utils/template-processor.js +0 -202
  204. package/dist/utils/template-processor.js.map +0 -1
  205. package/dist/version.d.ts +0 -1
  206. package/dist/version.js +0 -17
  207. package/dist/version.js.map +0 -1
  208. package/docs/CLA.md +0 -88
  209. package/docs/agent-configuration.md +0 -364
  210. package/docs/agent-registry-strategy.md +0 -348
  211. package/docs/branding-decision-crewx.md +0 -395
  212. package/docs/claude-code-docker-guide.md +0 -264
  213. package/docs/cli-guide.md +0 -439
  214. package/docs/development.md +0 -595
  215. package/docs/diagram1.svg +0 -1
  216. package/docs/guides/agent-best-practices.md +0 -97
  217. package/docs/guides/bug-management.md +0 -600
  218. package/docs/guides/git-bug-reference.md +0 -366
  219. package/docs/mcp-integration.md +0 -187
  220. package/docs/process/development-workflow.md +0 -84
  221. package/docs/remote-agents.md +0 -555
  222. package/docs/roadmap.md +0 -528
  223. package/docs/rules/branch-protection.md +0 -40
  224. package/docs/standards/rc-versioning.md +0 -60
  225. package/docs/standards/report-structure.md +0 -67
  226. package/docs/template-variables.md +0 -382
  227. package/docs/templates.md +0 -517
  228. package/docs/tools.md +0 -583
  229. package/docs/troubleshooting.md +0 -611
  230. package/templates/agents/default.yaml +0 -938
  231. package/templates/agents/minimal.yaml +0 -25
  232. package/templates/documents/crewcode-manual.md +0 -292
  233. package/templates/versions.json +0 -19
package/docs/tools.md DELETED
@@ -1,583 +0,0 @@
1
- # Tool System Guide
2
-
3
- Complete guide for the CrewX tool system, including creating custom tools and template integration.
4
-
5
- ## Table of Contents
6
-
7
- - [Overview](#overview)
8
- - [Architecture](#architecture)
9
- - [Creating Custom Tools](#creating-custom-tools)
10
- - [Built-in Tools](#built-in-tools)
11
- - [Template Integration](#template-integration)
12
- - [Best Practices](#best-practices)
13
-
14
- ## Overview
15
-
16
- CrewX's tool system is designed to be compatible with the Mastra framework, enabling AI agents to safely and efficiently execute external tools.
17
-
18
- **Key Features:**
19
- - Mastra-compatible tool definitions
20
- - Type-safe execution context
21
- - Standardized result format
22
- - Template integration for dynamic tool documentation
23
- - Automatic tool registration
24
-
25
- ## Architecture
26
-
27
- ### Tool Definition
28
-
29
- Tools are defined using this structure:
30
-
31
- ```typescript
32
- interface Tool {
33
- name: string; // Unique tool identifier
34
- description: string; // Description for AI agent selection
35
- input_schema: { // Input parameter definition
36
- type: 'object';
37
- properties: Record<string, any>;
38
- required?: string[];
39
- };
40
- output_schema?: { // Output structure (optional)
41
- type: 'object';
42
- properties: Record<string, any>;
43
- required?: string[];
44
- };
45
- }
46
- ```
47
-
48
- ### Execution Context
49
-
50
- Tools receive rich context information during execution:
51
-
52
- ```typescript
53
- interface ToolExecutionContext {
54
- input: Record<string, any>; // Tool input parameters
55
- runId?: string; // Execution tracking ID
56
- threadId?: string; // Conversation thread ID
57
- resourceId?: string; // Resource/user identifier
58
- agentId?: string; // Calling agent ID
59
- tracingContext?: { // Tracing/logging context
60
- taskId?: string;
61
- parentSpan?: string;
62
- };
63
- }
64
- ```
65
-
66
- ### Execution Result
67
-
68
- Standardized execution result format:
69
-
70
- ```typescript
71
- interface ToolExecutionResult<T = any> {
72
- success: boolean; // Execution success status
73
- data?: T; // Result data
74
- error?: string; // Error message
75
- metadata?: { // Metadata
76
- executionTime?: number;
77
- toolName?: string;
78
- runId?: string;
79
- };
80
- }
81
- ```
82
-
83
- ## Creating Custom Tools
84
-
85
- ### Basic Example
86
-
87
- ```typescript
88
- import { ToolCallService, Tool, ToolExecutor, ToolExecutionContext, ToolExecutionResult } from '@/services/tool-call.service';
89
-
90
- // 1. Define the tool
91
- const calculatorTool: Tool = {
92
- name: 'calculator',
93
- description: 'Perform basic arithmetic operations',
94
- input_schema: {
95
- type: 'object',
96
- properties: {
97
- operation: {
98
- type: 'string',
99
- enum: ['add', 'subtract', 'multiply', 'divide'],
100
- description: 'The arithmetic operation to perform'
101
- },
102
- a: {
103
- type: 'number',
104
- description: 'First number'
105
- },
106
- b: {
107
- type: 'number',
108
- description: 'Second number'
109
- }
110
- },
111
- required: ['operation', 'a', 'b']
112
- }
113
- };
114
-
115
- // 2. Implement the executor
116
- const calculatorExecutor: ToolExecutor = {
117
- execute: async (context: ToolExecutionContext): Promise<ToolExecutionResult> => {
118
- const startTime = Date.now();
119
-
120
- try {
121
- const { operation, a, b } = context.input;
122
-
123
- // Validate input
124
- if (typeof a !== 'number' || typeof b !== 'number') {
125
- return {
126
- success: false,
127
- error: 'Both a and b must be numbers'
128
- };
129
- }
130
-
131
- // Perform calculation
132
- let result: number;
133
- switch (operation) {
134
- case 'add':
135
- result = a + b;
136
- break;
137
- case 'subtract':
138
- result = a - b;
139
- break;
140
- case 'multiply':
141
- result = a * b;
142
- break;
143
- case 'divide':
144
- if (b === 0) {
145
- return { success: false, error: 'Division by zero' };
146
- }
147
- result = a / b;
148
- break;
149
- default:
150
- return { success: false, error: `Unknown operation: ${operation}` };
151
- }
152
-
153
- return {
154
- success: true,
155
- data: { result, operation },
156
- metadata: {
157
- executionTime: Date.now() - startTime,
158
- toolName: 'calculator'
159
- }
160
- };
161
- } catch (error: any) {
162
- return {
163
- success: false,
164
- error: `Execution failed: ${error.message}`
165
- };
166
- }
167
- }
168
- };
169
-
170
- // 3. Register the tool
171
- @Injectable()
172
- export class CustomToolsService {
173
- constructor(private readonly toolCallService: ToolCallService) {
174
- this.registerTools();
175
- }
176
-
177
- private registerTools(): void {
178
- this.toolCallService.register(calculatorTool, calculatorExecutor);
179
- }
180
- }
181
- ```
182
-
183
- ### Advanced Example with External API
184
-
185
- ```typescript
186
- const weatherTool: Tool = {
187
- name: 'get_weather',
188
- description: 'Get current weather information for a location',
189
- input_schema: {
190
- type: 'object',
191
- properties: {
192
- location: {
193
- type: 'string',
194
- description: 'City name or location'
195
- },
196
- units: {
197
- type: 'string',
198
- enum: ['celsius', 'fahrenheit'],
199
- description: 'Temperature units',
200
- default: 'celsius'
201
- }
202
- },
203
- required: ['location']
204
- }
205
- };
206
-
207
- const weatherExecutor: ToolExecutor = {
208
- execute: async (context: ToolExecutionContext): Promise<ToolExecutionResult> => {
209
- const startTime = Date.now();
210
-
211
- try {
212
- const { location, units = 'celsius' } = context.input;
213
-
214
- // Call external weather API
215
- const response = await fetch(
216
- `https://api.weatherapi.com/v1/current.json?key=YOUR_API_KEY&q=${encodeURIComponent(location)}`
217
- );
218
-
219
- if (!response.ok) {
220
- return {
221
- success: false,
222
- error: `Weather API error: ${response.statusText}`
223
- };
224
- }
225
-
226
- const data = await response.json();
227
-
228
- return {
229
- success: true,
230
- data: {
231
- temperature: units === 'celsius' ? data.current.temp_c : data.current.temp_f,
232
- humidity: data.current.humidity,
233
- conditions: data.current.condition.text,
234
- location: data.location.name
235
- },
236
- metadata: {
237
- executionTime: Date.now() - startTime,
238
- toolName: 'get_weather'
239
- }
240
- };
241
- } catch (error: any) {
242
- return {
243
- success: false,
244
- error: `Failed to fetch weather: ${error.message}`
245
- };
246
- }
247
- }
248
- };
249
- ```
250
-
251
- ## Built-in Tools
252
-
253
- ### read_file
254
-
255
- Reads file contents from the filesystem.
256
-
257
- **Input:**
258
- ```json
259
- {
260
- "path": "string" // File path to read
261
- }
262
- ```
263
-
264
- **Output:**
265
- ```json
266
- {
267
- "content": "string" // File contents
268
- }
269
- ```
270
-
271
- **Usage Example:**
272
- ```bash
273
- crewx query "@gemini README.md 파일을 읽고 요약해줘"
274
- ```
275
-
276
- ## Template Integration
277
-
278
- ### Using Tools in Agent Prompts
279
-
280
- Tools registered at runtime are automatically available in agent templates via the `tools` variable.
281
-
282
- #### Template Variables
283
-
284
- ```yaml
285
- {{#if tools}}
286
- # Tools are available
287
- {{tools.count}} # Number of available tools
288
- {{{tools.json}}} # All tools as formatted JSON
289
- {{#each tools.list}} # Iterate through tools
290
- {{this.name}}
291
- {{this.description}}
292
- {{/each}}
293
- {{else}}
294
- # No tools available
295
- {{/if}}
296
- ```
297
-
298
- #### Tools Object Structure
299
-
300
- ```typescript
301
- tools: {
302
- count: number; // Number of available tools
303
- json: string; // JSON string of tool definitions
304
- list: Array<{ // Array of tool definitions
305
- name: string;
306
- description: string;
307
- input_schema: object;
308
- output_schema?: object;
309
- }>;
310
- }
311
- ```
312
-
313
- ### Usage Examples
314
-
315
- #### Example 1: Basic Tool Awareness
316
-
317
- ```yaml
318
- agents:
319
- - id: "my_agent"
320
- inline:
321
- system_prompt: |
322
- You are an AI assistant.
323
-
324
- {{#if tools}}
325
- You have access to {{tools.count}} tool(s).
326
- Use them when appropriate to provide accurate information.
327
- {{else}}
328
- Respond based on your knowledge without tools.
329
- {{/if}}
330
- ```
331
-
332
- #### Example 2: Detailed Tool Instructions
333
-
334
- ```yaml
335
- agents:
336
- - id: "tool_expert"
337
- inline:
338
- system_prompt: |
339
- You are a helpful AI assistant.
340
-
341
- {{#if tools}}
342
- ## Available Tools
343
-
344
- You have {{tools.count}} tool(s) at your disposal:
345
-
346
- <tools>
347
- {{{tools.json}}}
348
- </tools>
349
-
350
- **Instructions:**
351
- 1. Analyze user requests carefully
352
- 2. Use tools when they provide accurate, real-time data
353
- 3. Explain what tool you're using and why
354
- 4. Always validate tool results before responding
355
- {{/if}}
356
-
357
- ## Your Task
358
- Answer questions clearly and use tools effectively.
359
- ```
360
-
361
- #### Example 3: Conditional Tool Guidance
362
-
363
- ```yaml
364
- agents:
365
- - id: "smart_agent"
366
- inline:
367
- system_prompt: |
368
- You are an AI assistant.
369
-
370
- {{#if tools}}
371
- {{#if (eq tools.count 1)}}
372
- You have access to 1 tool. Use it wisely.
373
- {{else}}
374
- You have access to {{tools.count}} tools. Choose the most appropriate one.
375
- {{/if}}
376
-
377
- <available-tools>
378
- {{{tools.json}}}
379
- </available-tools>
380
- {{else}}
381
- Note: No tools are currently available.
382
- {{/if}}
383
- ```
384
-
385
- #### Example 4: Custom Tool List Formatting
386
-
387
- ```yaml
388
- agents:
389
- - id: "custom_format_agent"
390
- inline:
391
- system_prompt: |
392
- You are an AI assistant with tool capabilities.
393
-
394
- {{#if tools}}
395
- ## Your Toolkit ({{tools.count}} tools)
396
-
397
- {{#each tools.list}}
398
- ### {{this.name}}
399
- - **Description:** {{this.description}}
400
- - **Required Parameters:** {{#each this.input_schema.required}}{{this}}, {{/each}}
401
-
402
- {{/each}}
403
-
404
- Use these tools to enhance your responses.
405
- {{/if}}
406
- ```
407
-
408
- ### Dynamic Tool Registration
409
-
410
- Tools registered at runtime are automatically included in template context:
411
-
412
- ```typescript
413
- // In your custom service
414
- toolCallService.register(
415
- {
416
- name: 'custom_tool',
417
- description: 'My custom tool',
418
- input_schema: { /* ... */ }
419
- },
420
- {
421
- execute: async (context) => { /* ... */ }
422
- }
423
- );
424
-
425
- // Agent templates automatically see this new tool
426
- // No need to update agent configs!
427
- ```
428
-
429
- ## Best Practices
430
-
431
- ### 1. Always Validate Input
432
-
433
- ```typescript
434
- execute: async (context: ToolExecutionContext): Promise<ToolExecutionResult> => {
435
- const { input } = context;
436
-
437
- // Validate required fields
438
- if (!input.field1 || !input.field2) {
439
- return {
440
- success: false,
441
- error: 'Missing required fields: field1, field2'
442
- };
443
- }
444
-
445
- // Validate types
446
- if (typeof input.field1 !== 'string') {
447
- return {
448
- success: false,
449
- error: 'field1 must be a string'
450
- };
451
- }
452
-
453
- // Continue with execution...
454
- }
455
- ```
456
-
457
- ### 2. Handle Errors Gracefully
458
-
459
- ```typescript
460
- execute: async (context: ToolExecutionContext): Promise<ToolExecutionResult> => {
461
- try {
462
- // Tool logic
463
- return { success: true, data: result };
464
- } catch (error: any) {
465
- return {
466
- success: false,
467
- error: `Tool execution failed: ${error.message}`,
468
- metadata: {
469
- toolName: 'my_tool',
470
- runId: context.runId,
471
- }
472
- };
473
- }
474
- }
475
- ```
476
-
477
- ### 3. Provide Execution Metadata
478
-
479
- ```typescript
480
- const startTime = Date.now();
481
-
482
- return {
483
- success: true,
484
- data: result,
485
- metadata: {
486
- executionTime: Date.now() - startTime,
487
- toolName: 'my_tool',
488
- runId: context.runId,
489
- }
490
- };
491
- ```
492
-
493
- ### 4. Use Descriptive Tool Names and Descriptions
494
-
495
- ```typescript
496
- {
497
- name: 'search_database', // Clear, action-oriented
498
- description: 'Search the product database by name, category, or SKU. Returns matching products with details.', // Detailed for AI understanding
499
- }
500
- ```
501
-
502
- ### 5. Check Tool Availability in Templates
503
-
504
- ```yaml
505
- {{#if tools}}
506
- # Tool-specific instructions
507
- {{else}}
508
- # Fallback behavior
509
- {{/if}}
510
- ```
511
-
512
- ### 6. Provide Clear Tool Usage Guidelines
513
-
514
- ```yaml
515
- {{#if tools}}
516
- **When to use tools:**
517
- - For reading files: use read_file
518
- - For calculations: use calculator
519
- - For API calls: use http_request
520
-
521
- **When NOT to use tools:**
522
- - For general knowledge questions
523
- - For creative writing
524
- - For mathematical proofs (unless calculation needed)
525
- {{/if}}
526
- ```
527
-
528
- ## Tool Execution Flow
529
-
530
- 1. **Tool Registration**: Tool registered with ToolCallService at service startup
531
- 2. **AI Request**: AI agent analyzes user request
532
- 3. **Tool Selection**: AI selects appropriate tool
533
- 4. **Input Validation**: Tool input parameters validated
534
- 5. **Execution**: Tool executor runs
535
- 6. **Result Formatting**: Structured result returned
536
- 7. **AI Response**: AI uses tool result to generate response
537
-
538
- ## Debugging Tools
539
-
540
- ### View Available Tools
541
-
542
- ```typescript
543
- const tools = toolCallService.list();
544
- console.log('Available tools:', tools.map(t => t.name));
545
- ```
546
-
547
- ### Check Tool Existence
548
-
549
- ```typescript
550
- if (toolCallService.has('my_tool')) {
551
- console.log('Tool is registered');
552
- }
553
- ```
554
-
555
- ### Direct Tool Execution
556
-
557
- ```typescript
558
- const result = await toolCallService.execute('calculator', {
559
- operation: 'add',
560
- a: 5,
561
- b: 3
562
- }, {
563
- runId: 'test-run-123',
564
- agentId: 'test-agent'
565
- });
566
-
567
- console.log('Result:', result);
568
- ```
569
-
570
- ## Benefits
571
-
572
- ✅ **Mastra Compatible** - Works with Mastra framework
573
- ✅ **Type Safe** - Full TypeScript support
574
- ✅ **Template Integration** - Automatic tool documentation in agent prompts
575
- ✅ **Dynamic Registration** - Tools added at runtime appear in templates
576
- ✅ **Standardized Results** - Consistent success/error handling
577
- ✅ **Rich Context** - Execution tracking and tracing support
578
-
579
- ## See Also
580
-
581
- - [Agent Configuration Guide](agent-configuration.md) - Agent setup
582
- - [Template System Guide](templates.md) - Template integration
583
- - [CLI Guide](cli-guide.md) - Command-line usage