Skip to main content
Glama
agentic.ts8.85 kB
import { z } from "zod"; /** * Agentic & Synaptic Tools - Higher-order cognitive functions * Simulates advanced reasoning, association, and autonomous behavior. */ // ============================================ // Decision Matrix Tool // ============================================ export const decisionMatrixSchema = { name: "decision_matrix", description: "Evaluates options using weighted criteria to make data-driven decisions", inputSchema: z.object({ problem: z.string().describe("The decision to be made"), options: z.array(z.string()).describe("List of available options"), criteria: z.array(z.object({ name: z.string(), weight: z.number().min(0).max(10).describe("Importance weight (1-10)"), })).describe("Evaluation criteria"), evaluations: z.array(z.object({ optionIndex: z.number(), scores: z.array(z.number().min(0).max(10)).describe("Score for each criteria (in order)") })).optional().describe("Optional pre-filled scores") }) }; export function decisionMatrixHandler(args: { problem: string; options: string[]; criteria: Array<{ name: string; weight: number }>; evaluations?: Array<{ optionIndex: number; scores: number[] }>; }) { const { problem, options, criteria, evaluations } = args; // If no evaluations provided, return the template structure to fill if (!evaluations) { return { content: [{ type: "text", text: `# Decision Matrix Setup for: ${problem}\n\nPlease analyze the options and provide scores (0-10) for each criteria.\n\nCritera:\n${criteria.map((c, i) => `${i + 1}. ${c.name} (Weight: ${c.weight})`).join('\n')}\n\nOptions:\n${options.map((o, i) => `${i + 1}. ${o}`).join('\n')}` }] }; } // Calculate weighted scores const results = evaluations.map(evalItem => { const option = options[evalItem.optionIndex]; let totalScore = 0; let weightedScore = 0; let maxPossibleWeighted = 0; evalItem.scores.forEach((score, i) => { const weight = criteria[i].weight; totalScore += score; weightedScore += score * weight; maxPossibleWeighted += 10 * weight; }); const percent = Math.round((weightedScore / maxPossibleWeighted) * 100); return { option, rawResults: evalItem.scores.map((s, i) => `${criteria[i].name}: ${s}`).join(', '), totalScore, weightedScore, percent }; }); results.sort((a, b) => b.weightedScore - a.weightedScore); const winner = results[0]; return { content: [{ type: "text", text: `# Decision Analysis: ${problem}\n\n## 🏆 Winner: **${winner.option}** (${winner.percent}%)\n\n## Details\n${results.map((r, i) => `### ${i + 1}. ${r.option}\n- **Score**: ${r.weightedScore} / ${r.percent}%\n- Breakdown: ${r.rawResults}`).join('\n\n')}` }] }; } // ============================================ // Consequence Analysis Tool // ============================================ export const consequenceAnalysisSchema = { name: "consequence_analysis", description: "Analyzes 2nd and 3rd order consequences of a decision or action (Ripple Effect)", inputSchema: z.object({ action: z.string().describe("The action or change being proposed"), stakeholders: z.array(z.string()).describe("Who/what is affected (Users, DB, specific modules)"), timeframes: z.array(z.enum(["immediate", "short_term", "medium_term", "long_term"])).describe("Time horizons to analyze") }) }; export function consequenceAnalysisHandler(args: { action: string; stakeholders: string[]; timeframes: string[] }) { const { action, stakeholders, timeframes } = args; // In a real agent, this would query a knowledge base. // Here we provide a structured template for the LLM to fill or for the user to reflect on. return { content: [{ type: "text", text: `# Consequence Analysis (Ripple Effect)\n**Action**: ${action}\n\n## Impact Matrix\n\n${timeframes.map(time => { return `### ⏱️ ${time.replace('_', ' ').toUpperCase()}\n${stakeholders.map(s => `- **${s}**: [Analyze impact on ${s}]`).join('\n')}`; }).join('\n\n')}\n\n## ⚠️ Risks & Mitigations\n- [Identify major risks]\n- [Propose mitigations]` }] }; } // ============================================ // Concept Association (Synaptic) Tool // ============================================ export const conceptAssociationSchema = { name: "concept_association", description: "Links concepts to build a knowledge graph and identify hidden connections", inputSchema: z.object({ concept: z.string().describe("The central concept to analyze"), domains: z.array(z.string()).optional().describe("Domains to look for associations in (e.g. 'security', 'performance', 'business')"), depth: z.enum(["shallow", "deep", "abstract"]).optional().default("shallow") }) }; export function conceptAssociationHandler(args: { concept: string; domains?: string[]; depth?: string }) { const { concept, domains = ["general"], depth } = args; const prompts = { shallow: "Direct dependencies, immediate parents/children, explicit references.", deep: "Indirect dependencies, shared resources, race conditions, architectural patterns.", abstract: "Metaphorical similarities, design philosophy, structural parallels, anti-patterns." }; return { content: [{ type: "text", text: `# Synaptic Association: ${concept}\n\n**Mode**: ${depth} (${prompts[depth as keyof typeof prompts]})\n**Domains**: ${domains.join(", ")}\n\n## Associations Map\n\n1. **Direct Links**\n - [Link 1]\n - [Link 2]\n\n2. **Conceptual Parallels**\n - [Concept A] is like [Concept B] because...\n\n3. **Hidden Implications**\n - If ${concept} changes, then...\n\n4. **Pattern Recognition**\n - This resembles the [Pattern Name] pattern.` }] }; } // ============================================ // Derive Patterns Tool // ============================================ export const derivePatternsSchema = { name: "derive_patterns", description: "Identifies repeating code or architectural patterns to suggest refactoring or standardization", inputSchema: z.object({ sourcePaths: z.array(z.string()).describe("File paths or components to analyze"), focus: z.enum(["code_duplication", "architectural_style", "naming_conventions", "error_handling"]).describe("Aspect to analyze") }) }; export function derivePatternsHandler(args: { sourcePaths: string[]; focus: string }) { const { sourcePaths, focus } = args; return { content: [{ type: "text", text: `# Pattern Recognition: ${focus}\n\nAnalyzing: ${sourcePaths.length} sources\n\n## Observed Patterns\n\n1. **Pattern A**\n - Frequency: [High/Med/Low]\n - Description: ...\n - Example: ...\n\n2. **Pattern B**\n - Frequency: [High/Med/Low]\n - Description: ...\n - Example: ...\n\n## Recommendations\n\n- [Standardization suggestion]\n- [Refactoring opportunity]` }] }; } // ============================================ // Research Synthesis Tool // ============================================ export const researchSynthesisSchema = { name: "research_synthesis", description: "Aggregates and synthesizes information from multiple sources to answer a complex question", inputSchema: z.object({ topic: z.string().describe("The topic to research"), sources: z.array(z.string()).describe("List of provided information/code snippets"), goal: z.string().describe("The specific question or output needed") }) }; export function researchSynthesisHandler(args: { topic: string; sources: string[]; goal: string }) { const { topic, sources, goal } = args; return { content: [{ type: "text", text: `# Research Synthesis: ${topic}\n\n## Goal\n${goal}\n\n## Key Findings (Synthesized from ${sources.length} sources)\n\n1. **Insight 1**\n - Source support: [Reference]\n\n2. **Insight 2**\n - Source support: [Reference]\n\n3. **Contradictions/Caps**\n - [Note any conflicting info]\n\n## Conclusion/Answer\n[Final synthesized answer]` }] }; } // Export all export const agenticTools = { decisionMatrixSchema, decisionMatrixHandler, consequenceAnalysisSchema, consequenceAnalysisHandler, conceptAssociationSchema, conceptAssociationHandler, derivePatternsSchema, derivePatternsHandler, researchSynthesisSchema, researchSynthesisHandler };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/millsydotdev/Code-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server