Annotation Interface FunctionTool


@Target(METHOD) @Retention(RUNTIME) @Documented public @interface FunctionTool
Annotation to expose methods as function tools that can be invoked by AI agents.

Methods annotated with @FunctionTool become available as tools that the AI model can choose to invoke based on the task requirements. The LLM determines which tools to call and with which parameters based on the tool descriptions and the user's request.

Tool Discovery: Function tools can be defined in two ways:

  • Agent-defined: Methods within the agent class itself (can be private)
  • External tools: Methods in separate classes registered via effects().tools()

Best Practices:

  • Provide clear, descriptive tool descriptions
  • Use Description annotations on parameters to help the LLM understand usage
  • Use Optional parameters for non-required arguments
  • Keep tool functions focused on a single, well-defined task

Tool Execution: The agent automatically handles the tool execution loop: the LLM requests tool calls, the agent executes them, incorporates results into the session context, and continues until the LLM no longer needs to invoke tools.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
     
  • Element Details

    • name

      String name
      Default:
      ""
    • description

      String description