Skip to main content

Overview

This example demonstrates a sentiment analysis agent that goes beyond simple positive/negative classification. It tracks epistemic confidence, separates factual observations from subjective interpretations, and provides multi-dimensional sentiment scores.

Use Case

Analyze text sentiment to:
  • Classify overall sentiment (positive, negative, neutral)
  • Provide quantified sentiment scores (-1.0 to 1.0)
  • Identify emotional tone and intensity
  • Separate factual content from opinion
  • Track confidence in sentiment assessment
  • Handle ambiguous or mixed sentiment

Complete Code

sentiment_analysis.axon

Key Components

Persona: SentimentAnalyst

Defines an expert in:
  • Natural Language Processing: Technical understanding of text analysis
  • Psychology: Understanding of emotional expression
  • Linguistics: Language structure and meaning
  • Analytical tone: Objective, systematic approach

Context: AnalysisMode

Configures for consistent analysis:
  • Memory: No memory (stateless analysis)
  • Depth: Moderate analysis (not shallow, not exhaustive)
  • Temperature: Low (0.2) for consistent classifications

Custom Types

Range-constrained sentiment score:
  • -1.0 = Very negative
  • 0.0 = Neutral
  • 1.0 = Very positive
Captures emotional characteristics:
  • primary: Primary emotion (joy, anger, sadness, etc.)
  • intensity: How strong the emotion is
  • confidence: How confident we are in the assessment
Comprehensive analysis output:
  • overall_score: Quantified sentiment
  • classification: Category (positive, negative, neutral)
  • emotional_tone: Detailed emotional assessment
  • factual_content: Factual statements found
  • opinions: Opinion statements found
  • ambiguity_score: How unclear the sentiment is
  • confidence: Overall confidence in the analysis
Separating factual_content and opinions prevents conflating objective statements with subjective sentiment.

Flow: AnalyzeSentiment

Three-step cognitive pipeline with validation: Step 1: ExtractContent
Separates:
  • Factual statements (objective)
  • Opinions (subjective)
  • Emotional language (sentiment-bearing)
Step 2: ClassifySentiment
Determines:
  • Overall sentiment polarity
  • Primary sentiment category
  • Sentiment score
Step 3: EmotionalAssessment (Reasoning)
Uses explicit reasoning to:
  • Identify primary emotion
  • Assess intensity
  • Consider context
Validation
Ensures quality:
  • Refines if confidence too low
  • Warns on ambiguous sentiment
Synthesis
Combines all analyses into comprehensive output.

Usage

Validate and Run

Example Input

Example Output

Advanced Patterns

Aspect-Based Sentiment

Analyze sentiment for specific aspects:

Comparative Sentiment

Compare sentiment across multiple texts:

Temporal Sentiment Tracking

Track sentiment changes over time:

Multi-Language Sentiment

Handle multiple languages:

Best Practices

1. Separate Facts from Opinions

2. Use Range-Constrained Scores

3. Track Confidence

4. Handle Ambiguity

5. Use Low Temperature

Contract Analyzer

Legal contract analysis with risk assessment

Data Extraction

Extract structured data from unstructured text

Multi-Step Reasoning

Complex reasoning with chain-of-thought
  • Types — Epistemic type system
  • Flow — Cognitive pipelines
  • Persona — Agent identities
  • Anchor — Hard constraints