Package akka.javasdk.agent
Record Class SessionMessage.TokenUsage
- Enclosing interface:
SessionMessage
public static record SessionMessage.TokenUsage(int inputTokens, int outputTokens, int cacheReadInputTokens, int cacheWriteInputTokens, int totalInputTokens)
extends Record
Token usage for a single
SessionMessage.AiMessage.
See Agent.TokenUsage for the meaning of each count. A totalInputTokens of 0
is replaced by inputTokens. This also applies to session memory that was written before
the field existed.
Autonomous agents report no prompt cache counts to session memory. Their messages have 0 for
both cache counts, and totalInputTokens equals inputTokens.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTokenUsage(int inputTokens, int outputTokens) A usage with no prompt cache activity.TokenUsage(int inputTokens, int outputTokens, int cacheReadInputTokens, int cacheWriteInputTokens, int totalInputTokens) Creates an instance of aTokenUsagerecord class. -
Method Summary
Modifier and TypeMethodDescriptionadd(SessionMessage.TokenUsage tokenUsage) The sum of this and another usage.intReturns the value of thecacheReadInputTokensrecord component.intReturns the value of thecacheWriteInputTokensrecord component.final booleanIndicates whether some other object is "equal to" this one.static SessionMessage.TokenUsagefrom(Agent.TokenUsage tokenUsage) The token usage of an agent reply, as stored in session memory.final inthashCode()Returns a hash code value for this object.intReturns the value of theinputTokensrecord component.intReturns the value of theoutputTokensrecord component.final StringtoString()Returns a string representation of this record class.intReturns the value of thetotalInputTokensrecord component.
-
Field Details
-
EMPTY
No tokens consumed.
-
-
Constructor Details
-
TokenUsage
public TokenUsage(int inputTokens, int outputTokens, int cacheReadInputTokens, int cacheWriteInputTokens, int totalInputTokens) Creates an instance of aTokenUsagerecord class.- Parameters:
inputTokens- the value for theinputTokensrecord componentoutputTokens- the value for theoutputTokensrecord componentcacheReadInputTokens- the value for thecacheReadInputTokensrecord componentcacheWriteInputTokens- the value for thecacheWriteInputTokensrecord componenttotalInputTokens- the value for thetotalInputTokensrecord component
-
TokenUsage
public TokenUsage(int inputTokens, int outputTokens) A usage with no prompt cache activity.
-
-
Method Details
-
from
The token usage of an agent reply, as stored in session memory. -
add
The sum of this and another usage. Each count stops atInteger.MAX_VALUEinstead of overflowing. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
inputTokens
public int inputTokens()Returns the value of theinputTokensrecord component.- Returns:
- the value of the
inputTokensrecord component
-
outputTokens
public int outputTokens()Returns the value of theoutputTokensrecord component.- Returns:
- the value of the
outputTokensrecord component
-
cacheReadInputTokens
public int cacheReadInputTokens()Returns the value of thecacheReadInputTokensrecord component.- Returns:
- the value of the
cacheReadInputTokensrecord component
-
cacheWriteInputTokens
public int cacheWriteInputTokens()Returns the value of thecacheWriteInputTokensrecord component.- Returns:
- the value of the
cacheWriteInputTokensrecord component
-
totalInputTokens
public int totalInputTokens()Returns the value of thetotalInputTokensrecord component.- Returns:
- the value of the
totalInputTokensrecord component
-