Class Agent

Object
akka.javasdk.agent.Agent

public abstract class Agent extends Object
An AI agent component that interacts with an AI model, such as a large language model (LLM), to perform specific tasks.

An Agent is typically backed by a large language model and maintains contextual history in a session memory, which may be shared between multiple agents collaborating on the same goal. It can provide function tools and call them as requested by the model.

Key Features:

  • Session-based: Participates in a session with contextual memory
  • Memory Management: Automatically stores user and AI messages for context
  • Function Tools: Can be extended with custom tools for the model to invoke
  • Model Integration: Supports multiple AI model providers (OpenAI, Anthropic, etc.)
  • Streaming Support: Can stream responses token by token for real-time UX

Session Memory: The agent maintains contextual history in session memory, identified by a session id accessible via context(). This memory is persistent and shared between agents using the same session id.

Component Identification: The agent must be annotated with ComponentId to provide a unique identifier for the component class. For multi-agent systems, use AgentDescription to provide metadata for the AgentRegistry.

Calling Agents: Agents are typically called from workflows, endpoints, or consumers using the ComponentClient:


 String response = componentClient
     .forAgent()
     .inSession(sessionId)
     .method(MyAgent::query)
     .invoke("What is the weather like?");
 

For reliable execution with error handling and retries, consider calling agents from a Workflow.

  • Constructor Details

    • Agent

      public Agent()
  • Method Details