Reads PDF documents — annual reports, research papers, legal contracts — and extracts the text inside so the agent can summarise, search, or quote it. Works even for long multi-page documents.
Opens the PDF at the supplied path using Apache PDFBox and extracts the text and basic metadata. Accepts optional 'startPage' and 'endPage' parameters to read just a range — useful for large documents that would otherwise blow through the context window.
When a user asks:
Extract the first 5 pages of annual-report.pdf.
the agent calls the tool:
pdf_read(path="annual-report.pdf", startPage=1, endPage=5)and gets back: the plain-text content of those pages plus basic metadata.
Wire this tool into a SwarmAI crew. Use the YAML DSL for declarative workflows, or the Java builder API when you want full programmatic control.
YAML DSL
# document-review.yaml
name: document-review-crew
process: SEQUENTIAL
agents:
- id: analyst
role: Document Analyst
goal: Extract text from PDF documents
tools:
- pdf_read
tasks:
- id: document-review-task
agent: analyst
description: Read pages 1-5 of annual-report.pdf and summarize the opening letter.Java
import ai.intelliswarm.swarmai.agent.Agent;
import ai.intelliswarm.swarmai.task.Task;
import ai.intelliswarm.swarmai.swarm.Swarm;
import ai.intelliswarm.swarmai.swarm.SwarmOutput;
import ai.intelliswarm.swarmai.process.ProcessType;
import ai.intelliswarm.swarmai.tool.common.PDFReadTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
@Autowired ChatClient chatClient;
@Autowired PDFReadTool pDFReadTool;
Agent analyst = Agent.builder()
.role("Document Analyst")
.goal("Extract text from PDF documents")
.chatClient(chatClient)
.tool(pDFReadTool)
.build();
Task analystTask = Task.builder()
.description("Read pages 1-5 of annual-report.pdf and summarize the opening letter.")
.agent(analyst)
.build();
SwarmOutput result = Swarm.builder()
.agent(analyst)
.task(analystTask)
.process(ProcessType.SEQUENTIAL)
.build()
.kickoff();Real scenarios where agents put this tool to work.
Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/common/PDFReadTool.java in the swarm-ai repository.