Class GuidanceFunctionTools
- All Implemented Interfaces:
FunctionTools
This class registers tools for:
- Scanning project directories to find files annotated with guidance tags
- Processing those files using a configured model, either synchronously or asynchronously
- Retrieving the results of asynchronous processing by process ID
- Supplying prompt templates for guidance tag processing
This implementation integrates with the ProcessProvider provider and supports
both custom and built-in project workflows. It manages asynchronous execution
and result retrieval using temporary files and process IDs. Methods in this
class are typically invoked by an AI provider or workflow engine to enable
dynamic, tool-augmented project automation involving guidance tags.
Asynchronous reports are serialized below the application temporary directory
and can be retrieved with the process identifier returned when processing
starts.
- Author:
- Viktor Tovstyi
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDirectory below the runtime temporary directory that stores guidance results.private static final org.slf4j.LoggerLogger used to report asynchronous guidance-processing failures.(package private) final ResourceBundleResource bundle that supplies prompt templates exposed throughPromptmethods in this tool provider.private static final StringResponse-map key for an asynchronous guidance execution identifier.private static final StringResponse-map key for an asynchronous guidance execution status. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a guidance function-tools provider using the default prompt resource bundle. -
Method Summary
Modifier and TypeMethodDescriptiongetGuidancePrompt(String path, File projectDir) Provides the prompt template used to process files containing guidance tags.getGuidanceTaggedFiles(String path, File projectDir, Configurator configurator) Scans the specified directory and its subdirectories for files annotated with guidance tags, returning a mapping of project directories to the files that contain such tags.getProcessGuidanceTagFilesResult(String processId) Retrieves the result of a previously started guidance tag file processing by its process identifier.processGuidanceTagFiles(String instructions, Map<String, String> properties, String path, boolean async, File projectDir, Configurator config) Asynchronously processes files with guidance tags using the configured model.private voidsaveGuidanceResult(GuidanceProcessor processor, File projectDir, String path, File tempFile) Runs guidance processing in the background and persists its report.private voidSerializes a guidance-processing report to its temporary result file.
-
Field Details
-
logger
private static final org.slf4j.Logger loggerLogger used to report asynchronous guidance-processing failures. -
GUIDANCE_FOLDER
Directory below the runtime temporary directory that stores guidance results.- See Also:
-
PROCESS_ID_KEY
Response-map key for an asynchronous guidance execution identifier.- See Also:
-
STATUS_KEY
Response-map key for an asynchronous guidance execution status.- See Also:
-
mcpPromptBundle
Resource bundle that supplies prompt templates exposed throughPromptmethods in this tool provider.
-
-
Constructor Details
-
GuidanceFunctionTools
public GuidanceFunctionTools()Creates a guidance function-tools provider using the default prompt resource bundle.
-
-
Method Details
-
getGuidanceTaggedFiles
public Map<File,List<File>> getGuidanceTaggedFiles(String path, File projectDir, Configurator configurator) throws IOException Scans the specified directory and its subdirectories for files annotated with guidance tags, returning a mapping of project directories to the files that contain such tags.The scan is performed relative to the provided root directory and can be filtered using a path or pattern (such as glob or regex). Each discovered file with a guidance tag is grouped under its corresponding project directory in the returned map.
- Parameters:
path- Specifies the scanning path or pattern. Use a relative path with respect to the current project directory. If an absolute path is provided, it must be located within the root project directory. Supported patterns: raw directory names, glob patterns (e.g., "glob:*.java"), or regex patterns (e.g., "regex:^.java$"). Default: "glob:*.*"projectDir- The absolute path to the root project directory or a folder containing multiple projects. All scanning operations are performed relative to this directory.configurator- The configuration object used to resolve the configured model for scanning operations.- Returns:
- A map where each key is a project directory and each value is a list of files with guidance tags found in that directory.
- Throws:
IOException- if an I/O error occurs during scanning.
-
saveGuidanceResult
private void saveGuidanceResult(GuidanceProcessor processor, File projectDir, String path, File tempFile) Runs guidance processing in the background and persists its report.Any failure is logged because this method runs outside the caller's execution context; callers observe an unavailable result until a report is written.
- Parameters:
processor- configured guidance processorprojectDir- project directory to scanpath- scan path or patterntempFile- file that receives the serialized report
-
writeGuidanceResult
Serializes a guidance-processing report to its temporary result file.- Parameters:
tempFile- destination temporary file; its parent directory must existresult- report to serialize, including the outcome for every processed file- Throws:
IOException- if the report cannot be written
-
processGuidanceTagFiles
public Object processGuidanceTagFiles(String instructions, Map<String, String> properties, String path, boolean async, File projectDir, Configurator config) throws IOExceptionAsynchronously processes files with guidance tags using the configured model.Scans the files in the specified
project_dir(and optionally matching the givenpathpattern) and applies guidance processing to each file found. The processing is performed in a background thread. The method returns immediately with a response containing a unique process ID and a status of "processing". The actual result is serialized to a temporary file for later retrieval using the process ID.- Parameters:
properties- Optional map of Act properties, such as configuration overrides or parameters for the guidance processing. Ifnull, only the main configuration is used.path- Specifies the scanning path or pattern. Use a relative path with respect to the current project directory. If an absolute path is provided, it must be located within the root project directory. Supported patterns: raw directory names, glob patterns (e.g., "glob:**.java"), or regex patterns (e.g., "regex:^.[^/]+\\.java$"). Default: "${project_dir}".projectDir- The project directory in which to scan for files. The directory must be readable by the process.config- The configuration object for property resolution and default values. It is layered with the supplied properties.- Returns:
- In asynchronous mode, a map containing the unique
process_idand astatusof"processing"; in synchronous mode, the complete guidance-processing report. - Throws:
IOException- If there is an error scanning files or initializing the processing configuration.
-
getProcessGuidanceTagFilesResult
Retrieves the result of a previously started guidance tag file processing by its process identifier.This method reconstructs the path to the temporary file where the result was stored, using the provided process identifier and the system's temporary directory. If the result file exists, it reads and returns the result. If the file does not exist, it returns a status indicating that the result is still processing or unavailable.
- Parameters:
processId- The process identifier returned when processing was started; used to identify the result file.- Returns:
- A map containing the provided
process_id, astatus, and either the completedresultor amessagewhen the result is not yet available. - Throws:
IOException- If there is an error reading the result from the temp file.
-
getGuidancePrompt
Provides the prompt template used to process files containing guidance tags.The returned template is resolved from the
mcp-promptsresource bundle and is intended for use by the guidance-tag processing workflow.- Parameters:
path- The scanning path or pattern used to select files. The value is accepted for the prompt contract and is resolved by its caller.projectDir- The root folder of the project, or the parent folder containing projects to scan. The value is accepted for the prompt contract and is resolved by its caller.- Returns:
- The prompt template for processing files with guidance tags.
-