Skip to main content
Glama
structured-argumentation.ts11.5 kB
/** * Structured Argumentation Operation * * Builds and analyzes structured arguments using formal reasoning principles */ import { BaseOperation, type OperationContext, type OperationResult } from '../base.js'; export class StructuredArgumentationOperation extends BaseOperation { name = 'structured_argumentation'; category = 'collaborative'; async execute(context: OperationContext): Promise<OperationResult> { const { sessionState, prompt, parameters } = context; // Extract argumentation parameters const argumentType = this.getParam(parameters, 'argumentType', 'deductive'); const premises = (parameters.premises as string[]) || []; const conclusion = this.getParam(parameters, 'conclusion', ''); const counterarguments = (parameters.counterarguments as any[]) || []; const rebuttals = (parameters.rebuttals as any[]) || []; const evidenceStrength = this.getParam(parameters, 'evidenceStrength', 'moderate'); // Generate premises if not provided const generatedPremises = premises.length === 0 ? this.generatePremises(prompt, argumentType) : premises; // Generate conclusion if not provided const generatedConclusion = conclusion || this.generateConclusion(generatedPremises, argumentType); // Validate argument structure const validity = this.validateArgument(generatedPremises, generatedConclusion, argumentType); // Generate counterarguments if not provided const generatedCounterarguments = counterarguments.length === 0 ? this.generateCounterarguments(generatedPremises, generatedConclusion) : counterarguments; // Generate rebuttals if not provided const generatedRebuttals = rebuttals.length === 0 ? this.generateRebuttals(generatedCounterarguments) : rebuttals; // Assess overall argument strength const argumentStrength = this.assessArgumentStrength( validity, generatedCounterarguments, generatedRebuttals, evidenceStrength ); const argumentationData = { topic: prompt, argumentType, premises: generatedPremises, conclusion: generatedConclusion, validity, counterarguments: generatedCounterarguments, rebuttals: generatedRebuttals, argumentStrength, evidenceStrength, logicalForm: this.extractLogicalForm(generatedPremises, generatedConclusion, argumentType), sessionId: `argument-${Date.now()}`, timestamp: new Date().toISOString(), }; // Update session metrics sessionState.updateKPI('argument_premises', generatedPremises.length); sessionState.updateKPI('counterarguments_addressed', generatedCounterarguments.length); return this.createResult({ ...argumentationData, sessionContext: { sessionId: sessionState.sessionId, stats: sessionState.getStats(), }, }); } private generatePremises(topic: string, argumentType: string): string[] { const templates = { deductive: [ `All instances of ${topic} share certain characteristics`, `The current case exhibits these characteristics`, `Therefore, logical conclusions follow`, ], inductive: [ `Multiple observed cases of ${topic} show a pattern`, `This pattern appears consistent across contexts`, `Similar cases likely follow the same pattern`, ], abductive: [ `We observe certain phenomena related to ${topic}`, `A specific explanation would account for these phenomena`, `No alternative explanation is as plausible`, ], analogical: [ `${topic} is similar to a known case in relevant ways`, `The known case has certain properties`, `The similarities are significant enough to transfer properties`, ], }; return templates[argumentType as keyof typeof templates] || templates.deductive; } private generateConclusion(premises: string[], argumentType: string): string { const conclusionTemplates = { deductive: 'Therefore, the conclusion follows necessarily from the premises', inductive: 'Therefore, this pattern likely holds in general', abductive: 'Therefore, this explanation is most likely correct', analogical: 'Therefore, the same properties apply to this case', }; return conclusionTemplates[argumentType as keyof typeof conclusionTemplates] || 'Therefore, the conclusion follows from the premises'; } private validateArgument(premises: string[], conclusion: string, argumentType: string): any { const validity = { isValid: true, strength: 'strong', issues: [] as string[], type: argumentType, }; // Basic validation checks if (premises.length < 2) { validity.isValid = false; validity.strength = 'weak'; validity.issues.push('Insufficient premises for strong argument'); } if (!conclusion || conclusion.length < 10) { validity.isValid = false; validity.strength = 'weak'; validity.issues.push('Conclusion is too vague or missing'); } // Type-specific validation switch (argumentType) { case 'deductive': if (!this.hasLogicalConnection(premises, conclusion)) { validity.issues.push('Premises do not logically entail conclusion'); validity.strength = 'moderate'; } break; case 'inductive': if (premises.length < 3) { validity.issues.push('Inductive arguments need more evidence'); validity.strength = 'moderate'; } break; case 'abductive': validity.issues.push('Abductive reasoning requires comparison of explanations'); validity.strength = 'moderate'; break; case 'analogical': validity.issues.push('Analogical arguments depend on similarity strength'); validity.strength = 'moderate'; break; } return validity; } private hasLogicalConnection(premises: string[], conclusion: string): boolean { // Simple heuristic: check for common logical connectors const logicalWords = ['therefore', 'thus', 'hence', 'follows', 'implies']; return logicalWords.some(word => conclusion.toLowerCase().includes(word) || premises.some(premise => premise.toLowerCase().includes(word)) ); } private generateCounterarguments(premises: string[], conclusion: string): any[] { return [ { type: 'premise_challenge', argument: 'One or more premises may be false or unsupported', target: 'premises', strength: 'moderate', description: 'Challenges the truth of the underlying premises', }, { type: 'alternative_explanation', argument: 'Alternative explanations may better account for the evidence', target: 'conclusion', strength: 'moderate', description: 'Proposes competing explanations for the same evidence', }, { type: 'scope_limitation', argument: 'The argument may not apply broadly or may have exceptions', target: 'generalization', strength: 'weak', description: 'Questions the scope or universality of the conclusion', }, ]; } private generateRebuttals(counterarguments: any[]): any[] { return counterarguments.map((counter, index) => ({ targets: counter.type, rebuttal: this.generateSpecificRebuttal(counter.type), strength: this.calculateRebuttalStrength(counter.strength), evidence: `Supporting evidence for rebuttal ${index + 1}`, effectiveness: Math.random() * 0.4 + 0.6, // 0.6-1.0 })); } private generateSpecificRebuttal(counterType: string): string { const rebuttals = { premise_challenge: 'The premises are well-supported by multiple independent sources', alternative_explanation: 'Alternative explanations lack the explanatory power of the original', scope_limitation: 'The argument applies within clearly defined scope parameters', }; return rebuttals[counterType as keyof typeof rebuttals] || 'This counterargument does not significantly weaken the original argument'; } private calculateRebuttalStrength(counterStrength: string): string { const strengthMap = { 'weak': 'strong', 'moderate': 'moderate', 'strong': 'weak', }; return strengthMap[counterStrength as keyof typeof strengthMap] || 'moderate'; } private assessArgumentStrength( validity: any, counterarguments: any[], rebuttals: any[], evidenceStrength: string ): any { let baseScore = validity.isValid ? 0.7 : 0.3; // Adjust for validity strength const strengthMultiplier = { 'weak': 0.8, 'moderate': 1.0, 'strong': 1.2, }; baseScore *= strengthMultiplier[validity.strength as keyof typeof strengthMultiplier] || 1.0; // Adjust for counterarguments and rebuttals const counterargumentPenalty = counterarguments.length * 0.1; const rebuttalBonus = rebuttals.length * 0.05; const finalScore = Math.max(0.1, Math.min(1.0, baseScore - counterargumentPenalty + rebuttalBonus)); return { overall: finalScore, category: finalScore > 0.8 ? 'strong' : finalScore > 0.6 ? 'moderate' : 'weak', factors: { validity: validity.strength, evidence: evidenceStrength, counterarguments: counterarguments.length, rebuttals: rebuttals.length, }, confidence: Math.round(finalScore * 100), }; } private extractLogicalForm(premises: string[], conclusion: string, argumentType: string): any { // Simplified logical form extraction const form = { type: argumentType, structure: this.getArgumentStructure(argumentType), premises: premises.map((premise, index) => ({ id: `P${index + 1}`, statement: premise, role: this.identifyPremiseRole(premise, index), })), conclusion: { id: 'C', statement: conclusion, follows_from: premises.map((_, index) => `P${index + 1}`), }, validity: this.assessLogicalValidity(argumentType), }; return form; } private getArgumentStructure(argumentType: string): string { const structures = { deductive: 'If P1 and P2, then C', inductive: 'P1, P2, P3... suggest C', abductive: 'C best explains P1, P2, P3...', analogical: 'P1 is like P2, P2 has property X, therefore P1 has property X', }; return structures[argumentType as keyof typeof structures] || 'P1, P2... therefore C'; } private identifyPremiseRole(premise: string, index: number): string { if (index === 0) return 'major'; if (premise.toLowerCase().includes('current') || premise.toLowerCase().includes('this')) { return 'minor'; } return 'supporting'; } private assessLogicalValidity(argumentType: string): string { // Simplified validity assessment const validityTypes = { deductive: 'necessarily_valid', inductive: 'probably_valid', abductive: 'plausibly_valid', analogical: 'conditionally_valid', }; return validityTypes[argumentType as keyof typeof validityTypes] || 'conditionally_valid'; } } export default new StructuredArgumentationOperation();

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/waldzellai/clearthought-onepointfive'

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