rtm_generate_ensemble
Create a statistical ensemble of Random Trees to model population-level recall from narrative text, configurable by ensemble size, branching factor, and recall depth.
Instructions
Generate a statistical ensemble of Random Trees to model population-level recall
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ensembleSize | No | Number of trees to generate in the ensemble | |
| maxBranchingFactor | No | Maximum number of child nodes (K parameter) | |
| maxRecallDepth | No | Maximum depth for recall (D parameter) | |
| text | Yes | The narrative text to analyze | |
| title | Yes | Title of the narrative |
Implementation Reference
- src/tools/generateEnsemble.ts:14-69 (handler)The handler function for 'rtm_generate_ensemble' tool. It creates a narrative tree from input text, generates an ensemble of Random Tree Models (RTM), analyzes variance and scale invariance, and returns statistics.export default async function generateEnsemble(params: GenerateEnsembleParams) { try { // Create narrative from text const narrative = createNarrative(params.text, params.title); // Create RTM parameters const parameters = { ...createDefaultParameters(), maxBranchingFactor: params.maxBranchingFactor || 4, maxRecallDepth: params.maxRecallDepth || 6 }; // Generate ensemble const generator = new RTMEnsembleGenerator(parameters); const ensemble = await generator.generateEnsemble( narrative, params.ensembleSize || 100 ); // Analyze variance const variance = generator.analyzeEnsembleVariance(ensemble); // Test for scale invariance const scaleInvariance = generator.testScaleInvariance(ensemble); return { content: [{ type: "text", text: JSON.stringify({ success: true, ensembleId: `ensemble_${narrative.id}`, narrativeId: narrative.id, statistics: { ensembleSize: ensemble.trees.length, meanRecallLength: ensemble.statistics.meanRecallLength, stdRecallLength: ensemble.statistics.stdRecallLength, scalingExponent: ensemble.statistics.scalingExponent, variance: variance, scaleInvariance: scaleInvariance }, message: `Generated ensemble of ${ensemble.trees.length} trees with mean recall length ${ensemble.statistics.meanRecallLength.toFixed(2)} ± ${ensemble.statistics.stdRecallLength.toFixed(2)}` }, null, 2) }], }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : "Unknown error occurred" }, null, 2) }], }; } }
- Zod input schema for the 'rtm_generate_ensemble' tool defining parameters like text, title, ensembleSize, etc.export const generateEnsembleSchema = z.object({ text: z.string().describe('The narrative text to analyze'), title: z.string().describe('Title of the narrative'), ensembleSize: z.number().default(100).describe('Number of trees to generate in the ensemble'), maxBranchingFactor: z.number().default(4).describe('Maximum number of child nodes (K parameter)'), maxRecallDepth: z.number().default(6).describe('Maximum depth for recall (D parameter)'), });
- src/index.ts:47-52 (registration)Registers the generateEnsemble handler under the key 'rtm_generate_ensemble' in the tools object used for tool execution.const tools = { rtm_create_narrative_tree: createNarrativeTree, rtm_generate_ensemble: generateEnsemble, rtm_traverse_narrative: traverseNarrative, rtm_find_optimal_depth: findOptimalDepth, };
- src/index.ts:61-65 (registration)Registers the tool definition including name, description, and input schema for ListTools response.{ name: 'rtm_generate_ensemble', description: 'Generate a statistical ensemble of Random Trees to model population-level recall', inputSchema: generateEnsembleSchema, },