Package com.tnsai.context.decision
Class DecisionTrace
java.lang.Object
com.tnsai.context.decision.DecisionTrace
Complete record of a decision for auditing and explanation.
DecisionTrace captures the full lifecycle of a decision:
- What triggered it (DecisionTrigger)
- What was considered (DecisionInput)
- What rules applied (DecisionPolicy)
- How the decision was made (DecisionReasoning)
- What action was taken
- What happened (DecisionOutcome)
This follows the Foundation Capital Context Graphs model where decisions are first-class entities that can be queried, explained, and used as precedents.
Usage Example
DecisionTrace trace = DecisionTrace.builder()
.agentId("discount-approval-agent")
.contextSnapshot(contextManager.createSnapshot(SnapshotTrigger.PRE_DECISION))
.trigger(DecisionTrigger.userRequest("Approve discount", "user-123"))
.input(inputBuilder.build())
.policy(policyBuilder.build())
.reasoning(reasoningBuilder.build())
.action("APPROVE_DISCOUNT")
.outcome(outcomeBuilder.build())
.build();
// Explain the decision
String explanation = trace.explainWhy();
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic DecisionTrace.Builderbuilder()Creates a new builder.booleanGenerates a human-readable explanation of why this decision was made.doubleGets the confidence level from reasoning.Gets the execution duration if outcome has execution time.getInput()getSpec()getTags()booleanReturns true if this trace has a context snapshot.inthashCode()booleanChecks if the trace has a specific tag.booleanReturns true if this is a child decision.booleanisFailed()Returns true if the decision failed.booleanReturns true if the decision was successful.Generates a concise one-line summary.toString()
-
Method Details
-
builder
Creates a new builder. -
getTraceId
-
getAgentId
-
getTimestamp
-
getContextSnapshot
-
getTrigger
-
getInput
-
getPolicy
-
getReasoning
-
getAction
-
getOutcome
-
getSpec
-
getTags
-
getConversationId
-
getParentTraceId
-
isSuccessful
public boolean isSuccessful()Returns true if the decision was successful. -
isFailed
public boolean isFailed()Returns true if the decision failed. -
hasContextSnapshot
public boolean hasContextSnapshot()Returns true if this trace has a context snapshot. -
isChildDecision
public boolean isChildDecision()Returns true if this is a child decision. -
getExecutionDuration
Gets the execution duration if outcome has execution time.- Returns:
- Optional containing the duration
-
getConfidence
public double getConfidence()Gets the confidence level from reasoning.- Returns:
- confidence level or 0.0 if no reasoning
-
hasTag
Checks if the trace has a specific tag.- Parameters:
tag- tag to check- Returns:
- true if tag is present
-
explainWhy
Generates a human-readable explanation of why this decision was made.- Returns:
- explanation string
-
summarize
Generates a concise one-line summary.- Returns:
- summary string
-
equals
-
hashCode
public int hashCode() -
toString
-