Interface AgentListener
- All Known Implementing Classes:
AgentMonitor, ComposedAgentListener
public interface AgentListener
Listener interface for monitoring agent invocations.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidafterAgenticScopeCreated(AgenticScope agenticScope) default voidafterAgentInvocation(AgentResponse agentResponse) default voidafterAgentToolExecution(AfterAgentToolExecution afterAgentToolExecution) default voidbeforeAgenticScopeDestroyed(AgenticScope agenticScope) default voidbeforeAgentInvocation(AgentRequest agentRequest) default voidbeforeAgentToolExecution(BeforeAgentToolExecution beforeAgentToolExecution) static AgentListenerforAiServiceListeners(boolean inheritedBySubagents, AiServiceListener<?>... aiServiceListeners) Creates anAgentListenerthat notifies the givenAiServiceListeners of the AI Service events of the agent it is registered on, so that listeners written for AI Services can be reused for agents.default booleanIndicates whether this listener should be used only to the agent where it is registered (default) or also inherited by its subagents.default voidonAgentAiServiceEvent(AgentAiServiceEvent agentAiServiceEvent) Called for each event fired by the AI Service of an LLM-based agent while it is invoked, from theAiServiceStartedEventto 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.default voidonAgenticSystemSuspended(AgenticScope agenticScope) default voidonAgentInvocationError(AgentInvocationError agentInvocationError) default voidonAgentSkipped(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.default voidonPlannerModelResponse(PlannerModelResponse plannerModelResponse) Called each time the planner of an agent, like a supervisor, a decision router or a customPlanner, receives the response of a model that it called itself to decide what to do, as reported by the planner through thereportChatModelResponseorreportDecisionModelResponsemethod of itsPlanningContext.
-
Method Details
-
beforeAgentInvocation
-
afterAgentInvocation
-
onAgentInvocationError
-
onAgentSkipped
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
-
beforeAgenticScopeDestroyed
-
onAgenticSystemSuspended
-
beforeAgentToolExecution
-
afterAgentToolExecution
-
onAgentAiServiceEvent
Called for each event fired by the AI Service of an LLM-based agent while it is invoked, from theAiServiceStartedEventto 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 theAiServiceInvocationSummaryEvent, which only aggregates these same events. -
onPlannerModelResponse
Called each time the planner of an agent, like a supervisor, a decision router or a customPlanner, receives the response of a model that it called itself to decide what to do, as reported by the planner through thereportChatModelResponseorreportDecisionModelResponsemethod of itsPlanningContext. 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 anAgentListenerthat notifies the givenAiServiceListeners 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 itsevent 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, seeinheritedBySubagents()aiServiceListeners- the listeners to notify, none of them listening to theAiServiceInvocationSummaryEvent, which is not notified to agent listeners- Returns:
- the agent listener
- Throws:
IllegalArgumentException- if one of the listeners listens to theAiServiceInvocationSummaryEvent
-