Class ComposedAgentListener
java.lang.Object
dev.langchain4j.agentic.observability.ComposedAgentListener
- All Implemented Interfaces:
AgentListener
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(AgentListener listener) voidafterAgenticScopeCreated(AgenticScope agenticScope) voidafterAgentInvocation(AgentResponse agentResponse) voidafterAgentToolExecution(AfterAgentToolExecution afterAgentToolExecution) voidbeforeAgenticScopeDestroyed(AgenticScope agenticScope) voidbeforeAgentInvocation(AgentRequest agentRequest) voidbeforeAgentToolExecution(BeforeAgentToolExecution beforeAgentToolExecution) static AgentListenercompose(AgentListener existingListener, AgentListener newListener) Composes a newly registered listener with the existing one, if any.static AgentListenercomposeWithInherited(AgentListener localListener, AgentListener parentListener) booleancontains(AgentListener listener) booleanIndicates whether this listener should be used only to the agent where it is registered (default) or also inherited by its subagents.static <T extends AgentListener>
TlistenerOfType(AgentListener rootListener, Class<T> listenerType) 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.voidonAgenticSystemSuspended(AgenticScope agenticScope) voidonAgentInvocationError(AgentInvocationError agentInvocationError) 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.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.
-
Constructor Details
-
ComposedAgentListener
-
-
Method Details
-
addListener
-
listeners
-
beforeAgentInvocation
- Specified by:
beforeAgentInvocationin interfaceAgentListener
-
afterAgentInvocation
- Specified by:
afterAgentInvocationin interfaceAgentListener
-
onAgentInvocationError
- Specified by:
onAgentInvocationErrorin interfaceAgentListener
-
onAgentSkipped
Description copied from interface:AgentListenerCalled 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.- Specified by:
onAgentSkippedin interfaceAgentListener
-
afterAgentToolExecution
- Specified by:
afterAgentToolExecutionin interfaceAgentListener
-
beforeAgentToolExecution
- Specified by:
beforeAgentToolExecutionin interfaceAgentListener
-
onAgentAiServiceEvent
Description copied from interface:AgentListenerCalled 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.- Specified by:
onAgentAiServiceEventin interfaceAgentListener
-
onPlannerModelResponse
Description copied from interface:AgentListenerCalled 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.- Specified by:
onPlannerModelResponsein interfaceAgentListener
-
afterAgenticScopeCreated
- Specified by:
afterAgenticScopeCreatedin interfaceAgentListener
-
beforeAgenticScopeDestroyed
- Specified by:
beforeAgenticScopeDestroyedin interfaceAgentListener
-
onAgenticSystemSuspended
- Specified by:
onAgenticSystemSuspendedin interfaceAgentListener
-
contains
-
inheritedBySubagents
public boolean inheritedBySubagents()Description copied from interface:AgentListenerIndicates whether this listener should be used only to the agent where it is registered (default) or also inherited by its subagents.- Specified by:
inheritedBySubagentsin interfaceAgentListener- Returns:
- true if the listener should be inherited by sub-agents, false otherwise
-
compose
Composes a newly registered listener with the existing one, if any. When the existing listener is already aComposedAgentListener, the new listener is added to it.- Returns:
- the listener to be used in place of the existing one
-
composeWithInherited
public static AgentListener composeWithInherited(AgentListener localListener, AgentListener parentListener) -
listenerOfType
public static <T extends AgentListener> T listenerOfType(AgentListener rootListener, Class<T> listenerType)
-