← All tools

Data & Analysis

Spring Data Repository

Invoke Spring Data repositories as agent tools.

repo_query

Overview

Lets the agent call your existing Spring Data repositories directly — the methods your team already wrote (findByEmail, countActive, …) become tools the agent can invoke. Write methods are refused unless you explicitly allow them.

How it works

Reflectively exposes every Spring Data Repository bean in the application context (JpaRepository, CrudRepository, etc.) as an agent-callable tool. Three operations: 'list_repositories' enumerates beans; 'list_methods' shows each repository's query methods; 'invoke' calls one with JSON-coerced arguments. Write methods (save/delete/update) are refused unless allow_writes=true.

Example

When a user asks:

Find all active customers whose email ends in @acme.com.

the agent calls the tool:

repo_query(operation="invoke", repository="CustomerRepository", method="findByEmailEndingAndStatus", args=["@acme.com","ACTIVE"])

and gets back: the list of matching Customer entities returned by the repository method.

Configuration

Set these before calling the tool. Values marked required must be present or the tool call will fail.

allow_writes optional

Per-call flag that permits save/delete/update methods. Defaults to false — write methods are refused unless explicitly enabled.

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

# customer-lookup.yaml
name: customer-lookup-crew
process: SEQUENTIAL

agents:
  - id: lookup
    role: Customer Lookup Agent
    goal: Query customer data through existing Spring Data repositories
    tools:
      - repo_query

tasks:
  - id: customer-lookup-task
    agent: lookup
    description: Use CustomerRepository.findByStatus('ACTIVE') to list all currently active customers.

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

@Autowired ChatClient chatClient;
@Autowired SpringDataRepositoryTool springDataRepositoryTool;

Agent lookup = Agent.builder()
    .role("Customer Lookup Agent")
    .goal("Query customer data through existing Spring Data repositories")
    .chatClient(chatClient)
    .tool(springDataRepositoryTool)
    .build();

Task lookupTask = Task.builder()
    .description("Use CustomerRepository.findByStatus('ACTIVE') to list all currently active customers.")
    .agent(lookup)
    .build();

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

What it's good for

Real scenarios where agents put this tool to work.

Let an agent query existing domain repositories without writing new SQL tools
Build read-only investigative agents on top of an existing Spring Boot app
Reuse hand-tuned finder methods (findBy…, countBy…) the team already maintains
Prototype CRUD workflows against a dev database with allow_writes enabled

Source

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

Open repo_query on GitHub →