Package com.tnsai.models.agent
Class Belief
java.lang.Object
com.tnsai.models.agent.Belief
Represents a single belief that an agent holds about the world.
In the BDI (Belief-Desire-Intention) architecture, beliefs represent the agent's knowledge about its environment. Beliefs are included in the agent's system prompt to provide context for decision-making.
Enhanced Belief Properties (v2.0)
- content - The belief statement
- confidence - How certain the agent is (0.0-1.0)
- source - Where the belief came from (sensor, LLM, user, static)
- timestamp - When the belief was created
- validUntil - TTL expiration (null = never expires)
BDI Architecture Context
- Beliefs (this class) - What the agent knows about the world
Desire- What the agent wants to achieveIntention- What the agent is committed to doing
Usage Examples
// Simple belief (backward compatible)
Belief simple = new Belief("Today is December 31, 2025");
// Belief with confidence and source
Belief weather = new Belief(
"Current temperature is 18°C",
0.95,
"weather-api"
);
// Belief with TTL (expires in 5 minutes)
Belief cacheable = Belief.withTTL(
"API rate limit is at 80%",
0.99,
"rate-limiter",
Duration.ofMinutes(5)
);
// Check if belief is still valid
if (cacheable.isValid()) {
// Use the belief
}
Confidence Levels
1.0- Absolute certainty (static facts)0.9+- High confidence (verified data)0.7-0.9- Medium confidence (inferred)< 0.7- Low confidence (uncertain)
Common Sources
"static"- Hardcoded facts"user"- User-provided information"llm"- LLM-inferred knowledge"sensor"- External API or sensor data"memory"- Retrieved from memory store
This class is immutable and thread-safe.
- Author:
- TnsAI Team
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault confidence level for beliefs without explicit confidence.static final StringDefault source for beliefs without explicit source.static final StringSource constant for LLM-inferred beliefs.static final StringSource constant for memory-retrieved beliefs.static final StringSource constant for sensor/API data.static final StringSource constant for user-provided beliefs. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a belief with only content (backward compatible).Creates a belief with content, confidence, and source.Creates a fully specified belief. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new belief with extended TTL.static BeliefCreates a belief from LLM inference.static BelieffromMemory(String content, double confidence) Creates a belief from memory retrieval.static BelieffromSensor(String content, double confidence, Duration ttl) Creates a belief from sensor/API data.static BeliefCreates a belief from user input.getAge()Returns the age of this belief.Returns the remaining time before expiration.booleanhasTTL()Checks if this belief has a TTL set.booleanChecks if this belief has expired.booleanChecks if this belief is high confidence (>= 0.9).booleanChecks if this belief is low confidence (invalid input: '<' 0.7).booleanisValid()Checks if this belief is still valid (not expired).booleanmightConflictWith(Belief other) Checks if this belief conflicts with another (same topic, different content).withConfidence(double newConfidence) Creates a new belief with updated confidence.withSource(String newSource) Creates a new belief with updated source.static BeliefCreates a belief with a TTL (time-to-live).
-
Field Details
-
DEFAULT_CONFIDENCE
public static final double DEFAULT_CONFIDENCEDefault confidence level for beliefs without explicit confidence.- See Also:
-
DEFAULT_SOURCE
Default source for beliefs without explicit source.- See Also:
-
SOURCE_USER
Source constant for user-provided beliefs.- See Also:
-
SOURCE_LLM
Source constant for LLM-inferred beliefs.- See Also:
-
SOURCE_SENSOR
Source constant for sensor/API data.- See Also:
-
SOURCE_MEMORY
Source constant for memory-retrieved beliefs.- See Also:
-
-
Constructor Details
-
Belief
Creates a belief with only content (backward compatible).Uses default confidence (1.0) and source ("static").
- Parameters:
content- the belief statement- Throws:
IllegalArgumentException- if content is null or blank
-
Belief
Creates a belief with content, confidence, and source.- Parameters:
content- the belief statementconfidence- confidence level (0.0-1.0)source- where the belief came from- Throws:
IllegalArgumentException- if content is null/blank or confidence is out of range
-
Belief
Creates a fully specified belief.- Parameters:
content- the belief statementconfidence- confidence level (0.0-1.0)source- where the belief came fromvalidUntil- when the belief expires (null = never)- Throws:
IllegalArgumentException- if content is null/blank or confidence is out of range
-
-
Method Details
-
withTTL
Creates a belief with a TTL (time-to-live).- Parameters:
content- the belief statementconfidence- confidence level (0.0-1.0)source- where the belief came fromttl- how long the belief is valid- Returns:
- a new Belief that expires after the TTL
-
fromUser
Creates a belief from user input.- Parameters:
content- the belief statementconfidence- confidence level (0.0-1.0)- Returns:
- a new Belief with source "user"
-
fromLLM
Creates a belief from LLM inference.- Parameters:
content- the belief statementconfidence- confidence level (0.0-1.0)- Returns:
- a new Belief with source "llm"
-
fromSensor
Creates a belief from sensor/API data.- Parameters:
content- the belief statementconfidence- confidence level (0.0-1.0)ttl- how long the belief is valid- Returns:
- a new Belief with source "sensor" and TTL
-
fromMemory
Creates a belief from memory retrieval.- Parameters:
content- the belief statementconfidence- confidence level (0.0-1.0)- Returns:
- a new Belief with source "memory"
-
isExpired
public boolean isExpired()Checks if this belief has expired.- Returns:
- true if the belief has a validUntil and it has passed
-
isValid
public boolean isValid()Checks if this belief is still valid (not expired).- Returns:
- true if the belief has no TTL or hasn't expired yet
-
hasTTL
public boolean hasTTL()Checks if this belief has a TTL set.- Returns:
- true if validUntil is not null
-
getAge
Returns the age of this belief.- Returns:
- duration since creation
-
getRemainingTime
Returns the remaining time before expiration.- Returns:
- remaining duration, or null if no TTL
-
withConfidence
Creates a new belief with updated confidence.- Parameters:
newConfidence- the new confidence level- Returns:
- a new Belief with the same content but different confidence
-
withSource
Creates a new belief with updated source.- Parameters:
newSource- the new source- Returns:
- a new Belief with the same content but different source
-
extendTTL
Creates a new belief with extended TTL.- Parameters:
extension- how much to extend the TTL- Returns:
- a new Belief with extended validUntil
-
isHighConfidence
public boolean isHighConfidence()Checks if this belief is high confidence (>= 0.9).- Returns:
- true if confidence is 0.9 or higher
-
isLowConfidence
public boolean isLowConfidence()Checks if this belief is low confidence (invalid input: '<' 0.7).- Returns:
- true if confidence is below 0.7
-
mightConflictWith
Checks if this belief conflicts with another (same topic, different content). This is a simple string-based check; semantic conflict detection requires embedding comparison.- Parameters:
other- the other belief to compare- Returns:
- true if the beliefs might conflict
-