Package com.google.genkit.ai
Class Agent
java.lang.Object
com.google.genkit.ai.Agent
Represents an agent that can be used as a tool in multi-agent systems.
An Agent wraps an AgentConfig and provides a Tool interface for delegation. When the model calls an agent as a tool, the agent's configuration (system prompt, model, tools) is applied to the conversation, effectively "transferring" control to the specialized agent.
Example usage:
// Define a specialized agent
Agent reservationAgent = genkit
.defineAgent(AgentConfig.builder().name("reservationAgent").description("Handles restaurant reservations")
.system("You are a reservation specialist...").tools(List.of(reservationTool)).build());
// Use in a parent agent
Agent triageAgent = genkit.defineAgent(AgentConfig.builder().name("triageAgent").description("Routes requests")
.system("Route customer requests to specialists").agents(List.of(reservationAgent.getConfig())).build());
// Start chat with triage agent
Chat chat = genkit.chat(triageAgent);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of an agent transfer. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasTool()Returns this agent as a tool that can be used by other agents.Gets the sub-agents.getAllTools(Map<String, Agent> agentRegistry) Gets all tools including sub-agent tools for handoff pattern.Gets the agent configuration.Gets the agent description.getModel()Gets the model name.getName()Gets the agent name.Gets the system prompt.Gets the tool definition for this agent.getTools()Gets the tools available to this agent.toString()
-
Constructor Details
-
Agent
Creates a new Agent.- Parameters:
config- the agent configuration
-
-
Method Details
-
getConfig
Gets the agent configuration.- Returns:
- the config
-
getName
Gets the agent name.- Returns:
- the name
-
getDescription
Gets the agent description.- Returns:
- the description
-
getSystem
Gets the system prompt.- Returns:
- the system prompt
-
getModel
Gets the model name.- Returns:
- the model name
-
getTools
Gets the tools available to this agent.- Returns:
- the tools
-
getAgents
Gets the sub-agents.- Returns:
- the sub-agents
-
getAllTools
Gets all tools including sub-agent tools for handoff pattern.This method collects all tools that should be available to the agent, including the agent's own tools and sub-agents as tools (for handoff). When a sub-agent tool is called, the Chat will handle the handoff by switching context to that agent.
- Parameters:
agentRegistry- map of agent name to Agent instance- Returns:
- combined list of all tools from this agent and sub-agents as tools
-
asTool
Returns this agent as a tool that can be used by other agents.- Returns:
- the agent as a tool
-
getToolDefinition
Gets the tool definition for this agent.- Returns:
- the tool definition
-
toString
-