Add Agent End-to-End Execution Time Metrics for Complex AI Workflows
Expected Behavior
Spring AI should provide observability metrics for measuring the total execution time of complex AI agent workflows that involve multiple components (ChatClient → Advisors → ChatModel → Tools → Vector Stores).
Proposed API:
// New observation metric
"spring.ai.agent.execution"
- Tags: agent.type, workflow.pattern, component.count, model.provider
- Metrics: execution.time.total, component.count, success.rate
Example Usage:
@Component
public class CustomerSupportAgent {
@Timed(value = "spring.ai.agent.execution", extraTags = {"agent.type", "customer-support"})
public AgentResponse processCustomerQuery(String query) {
return chatClient.prompt()
.user(query)
.advisors(memoryAdvisor, ragAdvisor, toolCallingAdvisor)
.call()
.entity(AgentResponse.class);
}
}
Expected Metrics Output:
# HELP spring_ai_agent_execution_seconds Agent workflow execution time
# TYPE spring_ai_agent_execution_seconds histogram
spring_ai_agent_execution_seconds{agent_type="customer-support",workflow_pattern="chain",component_count="4",model_provider="openai",} 2.543
spring_ai_agent_execution_seconds_count{agent_type="customer-support",workflow_pattern="chain",component_count="4",model_provider="openai",} 1.0
Current Behavior
Currently, Spring AI provides excellent individual component-level metrics:
- spring.ai.chat.client
- ChatClient execution time
- spring.ai.advisor
- Individual advisor execution time
- gen_ai.client.operation
- ChatModel execution time
- spring.ai.tool
- Tool execution time
- db.vector.client.operation
- Vector store operation time
However, there's no way to measure the total end-to-end execution time when these components work together in a complex AI agent workflow.
Current Limitation Example:
// These are measured separately:
ChatClient (0.1s) → MemoryAdvisor (0.05s) → RAGAdvisor (0.8s) → ChatModel (1.2s) → ToolCall (0.4s)
// But total workflow time (2.55s) is NOT tracked as a single metric