MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / executeToolCall

Function executeToolCall

packages/agent-runtime/src/tools/tool-executor.ts:289–534  ·  view source on GitHub ↗
(
  params: ExecuteToolCallParams<T>,
)

Source from the content-addressed store, hash-verified

287 AgentRuntimeScopedDeps
288
289export async function executeToolCall<T extends ToolName>(
290 params: ExecuteToolCallParams<T>,
291): Promise<void> {
292 const {
293 toolName,
294 input,
295 excludeToolFromMessageHistory = false,
296 fromHandleSteps = false,
297
298 agentState,
299 agentTemplate,
300 logger,
301 previousToolCallFinished,
302 toolCalls,
303 toolCallsToAddToMessageHistory,
304 toolResults,
305 toolResultsToAddToMessageHistory,
306 userInputId,
307
308 onCostCalculated,
309 onResponseChunk,
310 requestToolCall,
311 } = params
312 const toolCallId = params.toolCallId ?? generateCompactId()
313
314 const toolCall: CodebuffToolCall<T> | ToolCallError = parseRawToolCall<T>({
315 rawToolCall: {
316 toolName,
317 toolCallId,
318 input,
319 },
320 })
321
322 // Filter out restricted tools - emit error instead of tool call/result
323 // This prevents the CLI from showing tool calls that the agent doesn't have permission to use
324 if (
325 toolCall.toolName &&
326 !agentTemplate.toolNames.includes(toolCall.toolName) &&
327 !fromHandleSteps
328 ) {
329 // Emit an error event instead of tool call/result pair
330 // The stream parser will convert this to a user message for proper API compliance
331 onResponseChunk({
332 type: 'error',
333 message: `Tool \`${toolName}\` is not currently available. Make sure to only use tools provided at the start of the conversation AND that you most recently have permission to use.`,
334 })
335 return previousToolCallFinished
336 }
337
338 if ('error' in toolCall) {
339 const formattedInput = formatValueForError(input)
340 onResponseChunk({
341 type: 'error',
342 message: `${toolCall.error}\n\nOriginal tool call input:\n${formattedInput}`,
343 })
344 logger.debug(
345 { toolCall, error: toolCall.error },
346 `${toolName} error: ${toolCall.error}`,

Callers 2

executeSingleToolCallFunction · 0.90

Calls 7

generateCompactIdFunction · 0.90
formatValueForErrorFunction · 0.90
getMatchingSpawnFunction · 0.90
getAgentTemplateFunction · 0.90
parseRawToolCallFunction · 0.85
onCostCalculatedFunction · 0.85
onResponseChunkFunction · 0.50

Tested by

no test coverage detected