Skip to content
Text Summarization Techniques for AI Agents: Extractive vs Abstractive Methods — Abstractive text summarization
Learn Agentic AI9 min read13 views

Text Summarization Techniques for AI Agents: Extractive vs Abstractive Methods — Abstractive text summarization

Abstractive text summarization: compare extractive and abstractive summarization methods for AI agents, learn to control summary length and quality, and implement key point extraction pipelines in Python.

Why Agents Need Summarization

AI agents frequently work with documents, conversation histories, and knowledge bases that exceed context window limits. Summarization compresses information while preserving the key points an agent needs to make decisions. A customer support agent summarizing a 50-message conversation thread, a research agent condensing a 20-page report, or a monitoring agent digesting hundreds of log entries — all rely on summarization as a core capability.

The two fundamental approaches are extractive summarization (selecting the most important sentences verbatim) and abstractive summarization (generating new sentences that capture the meaning). Each has distinct strengths for different agent use cases.

Extractive Summarization

Extractive methods score each sentence in the source text and select the top-scoring ones. They never hallucinate because every word in the summary exists in the original. This makes them ideal for agents that need factual reliability.

flowchart TD
    Q{"What matters most<br/>for your team?"}
    DIM1["Time to first<br/>production deploy"]
    DIM2["Total cost of<br/>ownership at scale"]
    DIM3["Debuggability and<br/>observability"]
    DIM4["Ecosystem and<br/>community support"]
    PICK{Score the<br/>four axes}
    A(["Pick<br/>Text Summarization<br/>Techniques for AI…"])
    B(["Pick<br/>Abstractive Methods"])
    Q --> DIM1 --> PICK
    Q --> DIM2 --> PICK
    Q --> DIM3 --> PICK
    Q --> DIM4 --> PICK
    PICK -->|Speed and ecosystem| A
    PICK -->|Control and TCO| B
    style Q fill:#4f46e5,stroke:#4338ca,color:#fff
    style PICK fill:#f59e0b,stroke:#d97706,color:#1f2937
    style A fill:#0ea5e9,stroke:#0369a1,color:#fff
    style B fill:#059669,stroke:#047857,color:#fff
from sklearn.feature_extraction.text import TfidfVectorizer
import numpy as np

def extractive_summary(text: str, num_sentences: int = 3) -> str:
    """Select the most informative sentences using TF-IDF scoring."""
    sentences = text.split(". ")
    if len(sentences) <= num_sentences:
        return text

    vectorizer = TfidfVectorizer(stop_words="english")
    tfidf_matrix = vectorizer.fit_transform(sentences)

    # Score each sentence by sum of its TF-IDF values
    scores = np.array(tfidf_matrix.sum(axis=1)).flatten()

    # Get indices of top sentences, preserving original order
    top_indices = sorted(
        np.argsort(scores)[-num_sentences:],
    )

    summary = ". ".join(sentences[i] for i in top_indices)
    return summary + "."

document = """Machine learning models require training data to learn patterns.
The quality of training data directly impacts model performance.
Data preprocessing includes cleaning, normalization, and feature engineering.
Feature selection reduces dimensionality and improves training speed.
Cross-validation helps estimate how well a model generalizes to unseen data.
Hyperparameter tuning optimizes model configuration for best results.
Ensemble methods combine multiple models to reduce variance and bias."""

print(extractive_summary(document, num_sentences=3))

Abstractive Summarization with Transformers

Abstractive models generate entirely new text, producing more natural and concise summaries. They can rephrase, merge concepts, and adjust the level of detail.

Hear it before you finish reading

Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.

Try Live Demo →
from transformers import pipeline

summarizer = pipeline(
    "summarization",
    model="facebook/bart-large-cnn",
)

def abstractive_summary(
    text: str,
    max_length: int = 130,
    min_length: int = 30,
) -> str:
    result = summarizer(
        text,
        max_length=max_length,
        min_length=min_length,
        do_sample=False,
    )
    return result[0]["summary_text"]

article = """The European Union announced new regulations for artificial
intelligence systems on Wednesday. The AI Act categorizes AI applications
by risk level, from minimal risk to unacceptable risk. High-risk systems
used in critical infrastructure, education, and law enforcement will face
strict requirements including human oversight, transparency documentation,
and regular audits. Companies that violate the regulations could face
fines of up to 35 million euros or 7 percent of global revenue."""

print(abstractive_summary(article))

Length-Controlled Summarization

Agents often need summaries of specific lengths — a one-line preview for a notification, a paragraph for a dashboard, or a page for a report. Here is a utility that handles multiple formats.

from enum import Enum

class SummaryLength(Enum):
    HEADLINE = "headline"      # ~10 words
    SHORT = "short"            # ~30 words
    MEDIUM = "medium"          # ~80 words
    DETAILED = "detailed"      # ~150 words

LENGTH_CONFIG = {
    SummaryLength.HEADLINE: {"max_length": 20, "min_length": 5},
    SummaryLength.SHORT: {"max_length": 60, "min_length": 20},
    SummaryLength.MEDIUM: {"max_length": 150, "min_length": 60},
    SummaryLength.DETAILED: {"max_length": 300, "min_length": 100},
}

def summarize(text: str, length: SummaryLength) -> str:
    config = LENGTH_CONFIG[length]
    result = summarizer(
        text,
        max_length=config["max_length"],
        min_length=config["min_length"],
        do_sample=False,
    )
    return result[0]["summary_text"]

Key Point Extraction

Sometimes an agent does not need a flowing summary but a list of discrete key points. This hybrid approach extracts and then reformulates.

import openai

def extract_key_points(text: str, max_points: int = 5) -> list[str]:
    """Extract key points from text using an LLM."""
    response = openai.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{
            "role": "user",
            "content": f"""Extract up to {max_points} key points from this text.
Return each point on a new line, prefixed with a dash.
Be concise — each point should be one sentence.

Text: {text}""",
        }],
        temperature=0,
    )

    lines = response.choices[0].message.content.strip().split("\n")
    return [line.lstrip("- ").strip() for line in lines if line.strip()]

Measuring Summary Quality

Agents that summarize autonomously need quality guardrails. The ROUGE metric family measures overlap between generated and reference summaries.

from rouge_score import rouge_scorer

def evaluate_summary(generated: str, reference: str) -> dict:
    """Compute ROUGE scores between generated and reference summaries."""
    scorer = rouge_scorer.RougeScorer(
        ["rouge1", "rouge2", "rougeL"],
        use_stemmer=True,
    )
    scores = scorer.score(reference, generated)
    return {
        metric: {
            "precision": round(score.precision, 3),
            "recall": round(score.recall, 3),
            "f1": round(score.fmeasure, 3),
        }
        for metric, score in scores.items()
    }

reference = "The EU introduced risk-based AI regulations with fines."
generated = "New EU rules classify AI by risk level, with penalties up to 35M euros."
print(evaluate_summary(generated, reference))

ROUGE-1 measures unigram overlap, ROUGE-2 measures bigram overlap, and ROUGE-L measures the longest common subsequence. For agent summarization, ROUGE-L above 0.4 typically indicates adequate quality for downstream decision making.

FAQ

When should an agent use extractive versus abstractive summarization?

Use extractive summarization when factual accuracy is paramount and hallucination is unacceptable — legal documents, medical records, or financial reports. Use abstractive summarization when you need concise, natural-sounding text and the source material is long or repetitive. Many production systems use a hybrid approach: extractive selection first to narrow the source text, then abstractive rewriting for the final summary.

Still reading? Stop comparing — try CallSphere live.

CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.

How do I handle summarizing text that exceeds the model's context window?

Split the document into chunks that fit within the model's maximum input length, summarize each chunk independently, then summarize the intermediate summaries. This is called hierarchical or recursive summarization. For very long documents, use a sliding window with overlap to avoid losing information at chunk boundaries.

How can I detect when a summary contains hallucinated information?

Compare named entities and numerical values in the summary against the source text. If the summary mentions a person, date, or number not present in the original, flag it as a potential hallucination. You can also use NLI (Natural Language Inference) models to check whether each summary sentence is entailed by the source document.


#TextSummarization #NLP #Extractive #Abstractive #AIAgents #Python #AgenticAI #LearnAI #AIEngineering

Background and Key Concepts: Abstractive text summarization

This guide is written for engineers and operators evaluating abstractive text summarization in real production systems. Abstractive text summarization sits alongside attention mechanisms, encoder decoder model, extractive text summarization, input text, original text in the daily work of teams shipping production AI. The notes below give a plain-language reference for terms used throughout the article.

  • attention mechanisms — referenced in this guide when discussing abstractive text summarization.
  • encoder decoder model — referenced in this guide when discussing abstractive text summarization.
  • extractive text summarization — referenced in this guide when discussing abstractive text summarization.
  • input text — referenced in this guide when discussing abstractive text summarization.
  • original text — referenced in this guide when discussing abstractive text summarization.
  • pre trained — referenced in this guide when discussing abstractive text summarization.
  • sequence to sequence — referenced in this guide when discussing abstractive text summarization.
  • summarization models — referenced in this guide when discussing abstractive text summarization.
  • text to text format — referenced in this guide when discussing abstractive text summarization.
  • trained models — referenced in this guide when discussing abstractive text summarization.
  • transformer model — referenced in this guide when discussing abstractive text summarization.

For teams that want to ship abstractive text summarization in voice and chat agents this quarter, CallSphere runs 37 agents and 90+ function tools across 6 verticals on a single dashboard. Start a 14-day trial, see live demo agents, or compare tiers on /pricing.

Share

Try CallSphere AI Voice Agents

See how AI voice agents work for your industry. Live demo available -- no signup required.

Related Articles You May Like

AI Agents

Personal AI Assistant: How to Pick One for Business in 2026

A founder's guide to the personal AI assistant market: best AI assistant apps, business-grade options, and how CallSphere's voice agent fits in.

AI Agents

Free AI Agents in 2026: When Free Wins and When It Costs You

A founder's guide to free AI agents, low-code AI agent builders, and how to know when you should pay for a real platform like CallSphere.

Agentic AI

Graphiti: How Temporal Knowledge Graphs Give AI Voice Agents Persistent Memory (2026 Guide)

Graphiti is the open-source temporal knowledge graph for AI agents in 2026. Learn how bi-temporal memory beats vector RAG for voice agents and long-running LLMs.

AI Agents

Chatbot App vs ChatGPT: What's the Difference, and Which Do I Need?

Chatbot app vs ChatGPT in 2026: a founder's clear take on the difference, when to use which, and how a real AI chatbot app development works.

HVAC

Building an HVAC After-Hours Emergency Escalation System: A Complete Engineering Guide

How we built a fault-tolerant HVAC emergency triage and tech-dispatch platform on Kubernetes — three-tier CQRS, 11 micro-agents on the OpenAI Agents SDK + LangGraph, NATS JetStream, DTMF/SMS/WebSocket acceptance, circuit breakers, and an evaluation pipeline that catches regressions before they wake a tech at 3 AM.

Enterprise AI

OpenAI Frontier vs Anthropic Managed Agents: 2026 Comparison

Head-to-head: OpenAI Frontier and Anthropic's managed agent stack — strengths, fit, and what each means for enterprise AI voice and chat deployment.