Interface AgentListener

All Known Implementing Classes:
AgentMonitor, ComposedAgentListener

public interface AgentListener
Listener interface for monitoring agent invocations.
  • Method Details

    • beforeAgentInvocation

      default void beforeAgentInvocation(AgentRequest agentRequest)
    • afterAgentInvocation

      default void afterAgentInvocation(AgentResponse agentResponse)
    • onAgentInvocationError

      default void onAgentInvocationError(AgentInvocationError agentInvocationError)
    • onAgentSkipped

      default void onAgentSkipped(AgentSkipped agentSkipped)
      Called when an agent is skipped instead of being invoked, because its activation condition is false or because it is optional and one of its arguments is missing. A skipped agent is not followed by any other callback.
    • afterAgenticScopeCreated

      default void afterAgenticScopeCreated(AgenticScope agenticScope)
    • beforeAgenticScopeDestroyed

      default void beforeAgenticScopeDestroyed(AgenticScope agenticScope)
    • onAgenticSystemSuspended

      default void onAgenticSystemSuspended(AgenticScope agenticScope)
    • beforeAgentToolExecution

      default void beforeAgentToolExecution(BeforeAgentToolExecution beforeAgentToolExecution)
    • afterAgentToolExecution

      default void afterAgentToolExecution(AfterAgentToolExecution afterAgentToolExecution)
    • onAgentAiServiceEvent

      default void onAgentAiServiceEvent(AgentAiServiceEvent agentAiServiceEvent)
      Called for each event fired by the AI Service of an LLM-based agent while it is invoked, from the AiServiceStartedEvent to the completion, error or cancellation of the AI Service invocation, including the requests sent to the model, the responses received from it and the tool executions. It is not called for the AiServiceInvocationSummaryEvent, which only aggregates these same events.
    • onPlannerModelResponse

      default void onPlannerModelResponse(PlannerModelResponse plannerModelResponse)
      Called each time the planner of an agent, like a supervisor, a decision router or a custom Planner, receives the response of a model that it called itself to decide what to do, as reported by the planner through the reportChatModelResponse or reportDecisionModelResponse method of its PlanningContext. The notification carries the token usage and the model name of that response. The model calls of the subagents are not notified here, but by their own invocations. It is called on the thread running the planner, before the planner acts on the response, so also when the invocation of the agent later fails.
    • inheritedBySubagents

      default boolean inheritedBySubagents()
      Indicates whether this listener should be used only to the agent where it is registered (default) or also inherited by its subagents.
      Returns:
      true if the listener should be inherited by sub-agents, false otherwise
    • forAiServiceListeners

      static AgentListener forAiServiceListeners(boolean inheritedBySubagents, AiServiceListener<?>... aiServiceListeners)
      Creates an AgentListener that notifies the given AiServiceListeners of the AI Service events of the agent it is registered on, so that listeners written for AI Services can be reused for agents. As an AI Service does, it notifies each listener only of the events of its event class, and a listener that throws is logged without preventing the others from being notified.
      Parameters:
      inheritedBySubagents - whether the listener is also inherited by the subagents of the agent it is registered on, see inheritedBySubagents()
      aiServiceListeners - the listeners to notify, none of them listening to the AiServiceInvocationSummaryEvent, which is not notified to agent listeners
      Returns:
      the agent listener
      Throws:
      IllegalArgumentException - if one of the listeners listens to the AiServiceInvocationSummaryEvent