Class LoggingContext

java.lang.Object
ai.mindconnect.common.LoggingContext
All Implemented Interfaces:
AutoCloseable

public final class LoggingContext extends Object implements AutoCloseable
Helper for setting SLF4J/MDC fields scoped to a single agent invocation.

Use as a try-with-resources block — the MDC slots are reset to whatever was there before the call ended (so nested invocations stack correctly):


 try (var ctx = LoggingContext.session(sessionId, conversationId, agentName)) {
     // every log line in this block has sessionId/agentName in its MDC
     ...
     try (var sub = LoggingContext.subagent("answer-relevance-checker")) {
         // sub-agent block — agentName stays, subAgent is set
         ...
     }
     // sub-agent slot cleared again here
 }
 

The Logback pattern in logback-spring.xml can read these via %X{sessionId}, %X{agentName}, %X{subAgent} etc.

  • Field Details

  • Method Details

    • session

      public static LoggingContext session(UUID sessionId, UUID conversationId, String agentName)
      Sets sessionId, conversationId and agentName for the duration of the block.
    • subagent

      public static LoggingContext subagent(String subAgentName, String task)
      Sets the subAgent + task slot. The parent agentName stays untouched.
    • tool

      public static LoggingContext tool(String toolName)
      Sets the tool slot for the duration of one tool invocation.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable