bpm-agent / tools /summarize.py
limonad's picture
Upload 24 files
1e49a59 verified
"""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