Class Agent
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
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An Effect is a description of what the runtime needs to do after the command is handled.static interface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final AgentContext
context()
Additional context and metadata for a command handler.final Agent.Effect.Builder
effects()
-
Constructor Details
-
Agent
public Agent()
-
-
Method Details
-
context
Additional context and metadata for a command handler.It will throw an exception if accessed from constructor.
-
effects
-
streamEffects
-