AbstractAgent
TheAbstractAgent class provides the foundation for agent implementations. It handles event stream processing, state management, and message history. Extend it and implement protected void run(RunAgentInput input, IEventStream<BaseEvent> stream).
Example Implementation
Configuration
Constructors take:agentId, description, threadId, initialMessages, state, debug.
Core Methods
CompletableFuture<Void> runAgent(RunAgentParameters parameters, AgentSubscriber subscriber)— orchestrates an async run and event distributionSubscription subscribe(AgentSubscriber subscriber)— persistent subscriber registrationvoid addMessage(BaseMessage message)/void addMessages(List<BaseMessage>)void setMessages(List<BaseMessage>)void setState(State state)/State getState()
Protected Methods
protected abstract void run(RunAgentInput input, IEventStream<BaseEvent> stream)— emit events intostreamprotected RunAgentInput prepareRunAgentInput(RunAgentParameters parameters)protected void onInitialize(RunAgentInput input, List<AgentSubscriber> subscribers)protected void handleEvent(BaseEvent event, List<AgentSubscriber> subscribers, AtomicReference<IEventStream<BaseEvent>> streamRef)protected void handleComplete(List<AgentSubscriber> subscribers, RunAgentInput input, CompletableFuture<Void> future)protected void handleError(Throwable error, List<AgentSubscriber> subscribers, CompletableFuture<Void> future)
Text Message Helpers
handleTextMessageStart, handleTextMessageContent, handleTextMessageChunk, handleTextMessageEnd integrate with MessageFactory to assemble streamed messages and notify subscribers.