liveBook · Manning

@Agent

As explained in Spring AI in Action

@Agent is an Embabel annotation that declares a class to be an agent and can assign it identifying metadata.

@Agent is an Embabel annotation placed on a Java class to declare that class as an agent. It can assign identifying metadata such as a name, description, and version, while the class supplies actions that Embabel can plan into workflows. section 12.3.2 section 12.3

Listing 12.7 GameInfoAgent: An Embabel agent for answering questions about board games
package com.example.embabelgamesagent;

import com.embabel.agent.api.annotation.AchievesGoal;
import com.embabel.agent.api.annotation.Action;
import com.embabel.agent.api.annotation.Agent;
import com.embabel.agent.api.common.PromptRunner;
import com.embabel.agent.domain.io.UserInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.reader.tika.TikaDocumentReader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.stringtemplate.v4.ST;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;

@Agent(
    name = "GameInfoAgent",
    description = "An agent that helps users answer questions " +
        "about board games, including mechanics and player counts.",
    version = "1.0.0")   #1
public class GameInfoAgent {

  private static final Logger LOGGER =
      LoggerFactory.getLogger(GameInfoAgent.class);

  private final String rulesFilePath;

  public GameInfoAgent(
      @Value("${boardgame.rules.path}") String rulesFilePath) {
    this.rulesFilePath = rulesFilePath;   #2
  }

  // ...action methods go here...

}

Use the complete GameInfoAgent listing to see @Agent combined with action methods, prompt handling, domain records, and Spring configuration. section 12.3.2

Configure the annotation and its surrounding class around these responsibilities:

  • Declare a concrete class with @Agent so Embabel recognizes it as an agent. section 12.3.2
  • Provide identifying metadata through the annotation's name, description, and version values. section 12.3.2
  • Add one or more @Action methods; annotate goal-ending methods with @AchievesGoal so Embabel can use them as workflow finish lines. section 12.3.2
  • Let Embabel infer paths through the actions from their preconditions and postconditions instead of explicitly defining each workflow. section 12.3

GameInfoAgent

A board-game agent can use @Agent(name = "GameInfoAgent", description = "An agent that helps users answer questions about board games, including mechanics and player counts.", version = "..."). Its action methods can derive GameMechanics and PlayerCount objects from game rules through PromptRunner.usingLlm(). section 12.3.2

How Spring AI in Action covers it

How deep it goes
Defines class recognition and identifying metadata, while deferring workflow behavior to annotated actions and Embabel planning.
Examples
Uses GameInfoAgent to derive board-game mechanics and player counts from rules with prompt templates and PromptRunner.
What it assumes
Assumes Java and Spring-based application development while demonstrating agent construction through concrete annotations and actions.
What you can do after
Build it from scratch by annotating a Java class with @Agent and adding goal-oriented @Action methods.
How it connects
Connects Java annotations with @Action, @AchievesGoal, Spring AI, and Goal-Oriented Action Planning.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.