← All tools

File I/O

File Read

Read files with optional line ranges.

file_read

Overview

Opens a file on the computer and reads what's inside. Supports plain text, JSON, CSV, YAML, and XML files — so agents can pick up configuration, logs, or work saved from an earlier step.

How it works

Opens the file at the supplied path and returns its contents as text, detecting the format from the extension (txt, json, csv, yaml, xml) for appropriate handling. Accepts optional 'offset' and 'limit' parameters to read just a line range — useful for large log files that would otherwise blow through the context window.

Example

When a user asks:

Read the first 50 lines of /var/log/app.log.

the agent calls the tool:

file_read(path="/var/log/app.log", limit=50)

and gets back: the first 50 lines of the log file.

Use it in a workflow

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

# log-inspection.yaml
name: log-inspection-crew
process: SEQUENTIAL

agents:
  - id: reader
    role: Log Reader
    goal: Pick up prior state from local files
    tools:
      - file_read

tasks:
  - id: log-inspection-task
    agent: reader
    description: Read the first 50 lines of /var/log/app.log.

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.FileReadTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;

@Autowired ChatClient chatClient;
@Autowired FileReadTool fileReadTool;

Agent reader = Agent.builder()
    .role("Log Reader")
    .goal("Pick up prior state from local files")
    .chatClient(chatClient)
    .tool(fileReadTool)
    .build();

Task readerTask = Task.builder()
    .description("Read the first 50 lines of /var/log/app.log.")
    .agent(reader)
    .build();

SwarmOutput result = Swarm.builder()
    .agent(reader)
    .task(readerTask)
    .process(ProcessType.SEQUENTIAL)
    .build()
    .kickoff();

What it's good for

Real scenarios where agents put this tool to work.

Loading local datasets or configs into agents
Reading previously generated artifacts between crew steps
Ranged reads for large log or text files
Inspecting YAML/JSON configuration in DevOps demos

Source

Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/common/FileReadTool.java in the swarm-ai repository.

Open file_read on GitHub →