Class AgentCostByModelQueryResultMapper
java.lang.Object
com.flowable.platform.service.dashboard.resultmapper.extractor.AgentCostByModelQueryResultMapper
- All Implemented Interfaces:
DashboardComponentQueryResultMapper
public class AgentCostByModelQueryResultMapper
extends Object
implements DashboardComponentQueryResultMapper
Computes the total cost per LLM model by combining the input/output/cached token sums from the
_flowable_AgentInvocationTokensByModelByTypeQuery query result with the model prices stored in the
configuration store for the tenant.
The query produces three groupByNestedFieldFilteredWithSumField aggregations (inputTokens,
outputTokens, cachedTokens). Each is structured as
/aggregations/{aggName}/{aggName}_filtered/{aggName}_inner/buckets, where the bucket key is the
model name and the summed token count lives at {aggName}_sum/value.
Cost is tokens / 1_000_000 * price per token type, using the longest model-prefix match from the
effective price list. Models with no matching price are skipped.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AgentModelPricingServiceprotected static final Stringprotected static final Stringprotected static final Stringprotected static final BigDecimalstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionAgentCostByModelQueryResultMapper(AgentModelPricingService agentModelPricingService) -
Method Summary
Modifier and TypeMethodDescriptionprotected static doublecomputeCost(double inputTokens, double outputTokens, double cachedTokens, AgentModelPrice price) Computes the cost for a single model.protected static BigDecimalcostFor(double tokens, BigDecimal pricePerUnit) getType()map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult) map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult, String tenantId) protected static AgentModelPricematchPrice(String model, List<AgentModelPrice> prices) Returns the price whosemodelPrefixis the longest prefix of the given model name, ornullwhen no configured prefix matches.protected voidreadSummedTokens(tools.jackson.databind.JsonNode queryResult, String aggregationName, Map<String, AgentCostByModelQueryResultMapper.ModelTokens> tokensByModel, AgentCostByModelQueryResultMapper.TokenAssigner assigner) Reads the summed token count per model for the given nested-filtered aggregation and applies it to the accumulatedAgentCostByModelQueryResultMapper.ModelTokensfor that model.
-
Field Details
-
TYPE
- See Also:
-
TOKENS_PER_PRICE_UNIT
-
INPUT_TOKENS_AGGREGATION
- See Also:
-
OUTPUT_TOKENS_AGGREGATION
- See Also:
-
CACHED_TOKENS_AGGREGATION
- See Also:
-
agentModelPricingService
-
-
Constructor Details
-
AgentCostByModelQueryResultMapper
-
-
Method Details
-
getType
- Specified by:
getTypein interfaceDashboardComponentQueryResultMapper
-
map
public DashboardComponentData map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult) - Specified by:
mapin interfaceDashboardComponentQueryResultMapper
-
map
public DashboardComponentData map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult, String tenantId) - Specified by:
mapin interfaceDashboardComponentQueryResultMapper
-
readSummedTokens
protected void readSummedTokens(tools.jackson.databind.JsonNode queryResult, String aggregationName, Map<String, AgentCostByModelQueryResultMapper.ModelTokens> tokensByModel, AgentCostByModelQueryResultMapper.TokenAssigner assigner) Reads the summed token count per model for the given nested-filtered aggregation and applies it to the accumulatedAgentCostByModelQueryResultMapper.ModelTokensfor that model. MirrorsgroupByNestedFieldFilteredWithSumField's result structure. -
computeCost
protected static double computeCost(double inputTokens, double outputTokens, double cachedTokens, AgentModelPrice price) Computes the cost for a single model. Each token type is priced per 1,000,000 tokens; a null price for a token type contributes zero. -
costFor
-
matchPrice
Returns the price whosemodelPrefixis the longest prefix of the given model name, ornullwhen no configured prefix matches.
-