Package ai.mindconnect.common
Class LoggingContext
java.lang.Object
ai.mindconnect.common.LoggingContext
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMDC key for the currently running agent's display name.static final StringMDC key for the conversation UUID.static final StringMDC key for the agent session UUID.static final StringMDC key for a sub-agent that was invoked from inside the current agent.static final StringMDC key for the stateless task name (e.g.static final StringMDC key for the current tool being executed. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static LoggingContextSets sessionId, conversationId and agentName for the duration of the block.static LoggingContextSets the subAgent + task slot.static LoggingContextSets the tool slot for the duration of one tool invocation.
-
Field Details
-
SESSION_ID
MDC key for the agent session UUID.- See Also:
-
CONVERSATION_ID
MDC key for the conversation UUID.- See Also:
-
AGENT_NAME
MDC key for the currently running agent's display name.- See Also:
-
SUB_AGENT
MDC key for a sub-agent that was invoked from inside the current agent.- See Also:
-
TASK
MDC key for the stateless task name (e.g. "answer-relevance-checker").- See Also:
-
TOOL
MDC key for the current tool being executed.- See Also:
-
-
Method Details
-
session
Sets sessionId, conversationId and agentName for the duration of the block. -
subagent
Sets the subAgent + task slot. The parent agentName stays untouched. -
tool
Sets the tool slot for the duration of one tool invocation. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-