feat(workflows): integrate handleSubagentChatCredits into runAgentWorkflow
AH
5mo ago+485+485+012345678901234567890123456789-0-0-0123456789
- Added the handleSubagentChatCredits function to manage credit handling for subagents.
- Updated runAgentWorkflow to call handleSubagentChatCredits with appropriate parameters, including accountId, responseMessage, and previousResponseMessage.
- Enhanced tests for runAgentWorkflow to verify the correct invocation of handleSubagentChatCredits under various scenarios, including when resuming a turn with an in-progress assistant message.
- Updated handleChatCredits to support agentType and toolCallCount for better credit tracking.
Summary by cubic
Adds subagent credit attribution to the agent workflow by billing per task tool invocation and aggregating usage by subagent model. Prevents double-billing when resuming a turn and records agentType and toolCallCount for better spend analytics.
-
New Features
runAgentWorkflownow callshandleSubagentChatCreditswithaccountId,responseMessage, optionalpreviousResponseMessage(for resume), fallbackmodelId, andsource.- Per-invocation tracking: extracts
tasktool usage, diffs against a baseline on resume, aggregates by model, and counts tool calls. - Extended
handleChatCreditsto acceptagentType: "subagent"andtoolCallCount; added tests for aggregation, event collection/diffing, subagent billing, and workflow resume paths.
-
Refactors
- Simplified imports in
collectTaskToolUsageEvents.ts(no functional changes).
- Simplified imports in
Summary by CodeRabbit
- New Features
- Subagent tool usage is now tracked and recorded for accurate credit deduction, ensuring billing reflects all agent activity within workflows.