File size: 1,106 Bytes
1e49a59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Text summarization tool."""

from langchain_core.tools import tool


@tool
def summarize_text(text: str, max_sentences: int = 3) -> str:
    """
    Summarize the given text into a concise summary.
    
    This tool takes a longer text and creates a brief summary by extracting
    the most important sentences or creating a condensed version.
    
    Args:
        text: The text to summarize
        max_sentences: Maximum number of sentences in the summary (default: 3)
        
    Returns:
        A concise summary of the input text
    """
    # Simple summarization: split into sentences and take first N
    # In a real implementation, you might use more sophisticated NLP
    sentences = [s.strip() for s in text.split('.') if s.strip()]
    
    if len(sentences) <= max_sentences:
        return text
    
    # Take the first max_sentences sentences
    summary_sentences = sentences[:max_sentences]
    summary = '. '.join(summary_sentences)
    
    # Add ellipsis if we truncated
    if len(sentences) > max_sentences:
        summary += '...'
    
    return summary

# Made with Bob