@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
