Package com.tnsai.schema
Class ToolSchemaGenerator
java.lang.Object
com.tnsai.schema.ToolSchemaGenerator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerateToolSchema(ActionMetadata action) Generates tool schema for a single action.generateToolSchemas(List<Role> roles) Generates tool schemas for all roles' actions.generateToolsDescription(List<Role> roles) Generates a human-readable description of available tools.withExamples(boolean includeExamples) Sets whether to include examples in generated schemas.
-
Constructor Details
-
ToolSchemaGenerator
public ToolSchemaGenerator()
-
-
Method Details
-
generateToolSchemas
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
Sets whether to include examples in generated schemas.- Parameters:
includeExamples- true to include examples- Returns:
- this generator for chaining
-
generateToolSchema
Generates tool schema for a single action.- Parameters:
action- the action metadata- Returns:
- tool schema map
-
generateToolsDescription
Generates a human-readable description of available tools. Useful for including in system prompts.
-