Class AgentMonitor
java.lang.Object
dev.langchain4j.agentic.observability.AgentMonitor
- All Implemented Interfaces:
AgentListener
Monitors agent executions and provides observability for the LangChain4j Agentic system.
Generates a self-contained HTML report visualizing the static topology of an agentic system
and the dynamic execution traces.
The report includes:
- A visual tree chart of the agent hierarchy showing topology types, names, and properties
- A waterfall timeline of execution traces grouped by memory/session ID
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAgentInvocation(AgentResponse agentResponse) voidafterAgentToolExecution(AfterAgentToolExecution afterAgentToolExecution) allExecutionsFor(AgenticScope agenticScope) Returns all executions (successful, failed, and ongoing) for a given memory ID.allExecutionsFor(Object memoryId) Returns all executions (successful, failed, and ongoing) for a given memory ID.Returns the set of all memory IDs that have been tracked by this monitor, including successful, failed, and ongoing executions.voidbeforeAgentInvocation(AgentRequest agentRequest) voidclear()Removes all retained successful and failed executions.failedExecutionsFor(AgenticScope agenticScope) failedExecutionsFor(Object memoryId) booleanIndicates whether this listener should be used only to the agent where it is registered (default) or also inherited by its subagents.voidonAgentInvocationError(AgentInvocationError agentInvocationError) ongoingExecutionFor(AgenticScope agenticScope) ongoingExecutionFor(Object memoryId) voidsetMaxRetainedSessions(int maxRetainedSessions) Sets the maximum number of sessions (distinct memory IDs, per outcome: successful or failed) retained by this monitor.voidsetRootAgent(AgentInstance rootAgent) successfulExecutionsFor(AgenticScope agenticScope) successfulExecutionsFor(Object memoryId) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AgentListener
afterAgenticScopeCreated, beforeAgenticScopeDestroyed, beforeAgentToolExecution
-
Constructor Details
-
AgentMonitor
public AgentMonitor()
-
-
Method Details
-
setMaxRetainedSessions
public void setMaxRetainedSessions(int maxRetainedSessions) Sets the maximum number of sessions (distinct memory IDs, per outcome: successful or failed) retained by this monitor. When the limit is exceeded, the oldest sessions are evicted automatically. If the new limit is lower than the current number of retained sessions, excess entries are evicted immediately.Defaults to 100.
- Parameters:
maxRetainedSessions- the maximum number of retained sessions per outcome, must be ≥ 0- Throws:
IllegalArgumentException- ifmaxRetainedSessionsis negative
-
clear
public void clear()Removes all retained successful and failed executions. Ongoing executions are not affected. -
setRootAgent
-
beforeAgentInvocation
- Specified by:
beforeAgentInvocationin interfaceAgentListener
-
afterAgentInvocation
- Specified by:
afterAgentInvocationin interfaceAgentListener
-
onAgentInvocationError
- Specified by:
onAgentInvocationErrorin interfaceAgentListener
-
afterAgentToolExecution
- Specified by:
afterAgentToolExecutionin interfaceAgentListener
-
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
-
ongoingExecutions
-
ongoingExecutionFor
-
ongoingExecutionFor
-
successfulExecutions
-
successfulExecutionsFor
-
successfulExecutionsFor
-
failedExecutions
-
failedExecutionsFor
-
failedExecutionsFor
-
allMemoryIds
-
allExecutionsFor
Returns all executions (successful, failed, and ongoing) for a given memory ID. -
allExecutionsFor
Returns all executions (successful, failed, and ongoing) for a given memory ID.
-