Class ToolSchemaGenerator

java.lang.Object
com.tnsai.schema.ToolSchemaGenerator

public class ToolSchemaGenerator extends Object
Generates tool/function schemas for LLM function calling. Extracts schema generation logic from Agent class (SRP - Single Responsibility Principle).

Supports:

  • OpenAI function calling format
  • Gemini function declarations
  • Generic tool definitions

Usage:

 ToolSchemaGenerator generator = new ToolSchemaGenerator();

 // Generate schemas for all roles
 List<Map<String, Object>> tools = generator.generateToolSchemas(roles);

 // Generate schema for single action
 Map<String, Object> toolSchema = generator.generateToolSchema(action);
 
  • Constructor Details

    • ToolSchemaGenerator

      public ToolSchemaGenerator()
  • Method Details

    • generateToolSchemas

      public List<Map<String,Object>> generateToolSchemas(List<Role> roles)
      Generates tool schemas for all roles' actions. Excludes LLM and LLM action types.
      Parameters:
      roles - the list of roles
      Returns:
      list of tool schema maps
    • withExamples

      public ToolSchemaGenerator withExamples(boolean includeExamples)
      Sets whether to include examples in generated schemas.
      Parameters:
      includeExamples - true to include examples
      Returns:
      this generator for chaining
    • generateToolSchema

      public Map<String,Object> generateToolSchema(ActionMetadata action)
      Generates tool schema for a single action.
      Parameters:
      action - the action metadata
      Returns:
      tool schema map
    • generateToolsDescription

      public String generateToolsDescription(List<Role> roles)
      Generates a human-readable description of available tools. Useful for including in system prompts.