Strands Agents Typescript SDK
    Preparing search index...

    Class FunctionTool

    A Tool implementation that wraps a callback function and handles all ToolResultBlock conversion.

    FunctionTool allows creating tools from existing functions without needing to manually handle ToolResultBlock formatting or error handling. It supports multiple callback patterns:

    • Async generators for streaming responses
    • Promises for async operations
    • Synchronous functions for immediate results

    All return values are automatically wrapped in ToolResultBlock, and errors are caught and returned as error ToolResultBlocks.

    // Create a tool with streaming
    const streamingTool = new FunctionTool({
    name: 'processor',
    description: 'Processes data with progress updates',
    inputSchema: { type: 'object', properties: { data: { type: 'string' } } },
    callback: async function* (input: any) {
    yield 'Starting processing...'
    // Do some work
    yield 'Halfway done...'
    // More work
    return 'Processing complete!'
    }
    })

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Creates a new FunctionTool instance.

      Parameters

      • config: FunctionToolConfig

        Configuration object for the tool

      Returns FunctionTool

      // Tool with input schema
      const greetTool = new FunctionTool({
      name: 'greeter',
      description: 'Greets a person by name',
      inputSchema: {
      type: 'object',
      properties: { name: { type: 'string' } },
      required: ['name']
      },
      callback: (input: any) => `Hello, ${input.name}!`
      })

      // Tool without input (no parameters)
      const statusTool = new FunctionTool({
      name: 'getStatus',
      description: 'Gets system status',
      callback: () => ({ status: 'operational' })
      })

    Properties

    name: string

    The unique name of the tool.

    description: string

    Human-readable description of what the tool does.

    toolSpec: ToolSpec

    OpenAPI JSON specification for the tool.

    Methods