diff --git a/flexus_simple_bots/karen/karen_bot.py b/flexus_simple_bots/karen/karen_bot.py index a7798410..59230ec6 100644 --- a/flexus_simple_bots/karen/karen_bot.py +++ b/flexus_simple_bots/karen/karen_bot.py @@ -183,6 +183,16 @@ "sentiment_notes": {"type": "string", "order": 4, "title": "Sentiment Notes"}, }, }, + "section05-costs": { + "type": "object", + "title": "Token Costs", + "properties": { + "total_coins": {"type": "integer", "order": 0, "title": "Total Coins"}, + "conversations_count": {"type": "integer", "order": 1, "title": "Conversations"}, + "avg_coins_per_conversation": {"type": "integer", "order": 2, "title": "Avg Coins/Conversation"}, + "budget_utilization_pct": {"type": "number", "order": 3, "title": "Budget Utilization %"}, + }, + }, } REPORT_TOOL = ckit_cloudtool.CloudTool( @@ -342,8 +352,13 @@ async def handle_report( refunds = await ckit_erp.erp_table_data(http, "com_refund", ws_id, erp_schema.ComRefund, filters=f"refund_created_ts:>=:{ts0}", limit=1000) refund_amount = float(sum(r.refund_amount for r in refunds)) + # XXX bad idea: + # - there are infinite tasks here + # - model already asks kanban about all the counters all_tasks = await ckit_kanban.bot_get_all_tasks(http, pid) done_tasks = [t for t in all_tasks if t.ktask_done_ts >= ts0] + total_coins = sum(t.ktask_coins for t in done_tasks) + total_budget = sum(t.ktask_budget for t in done_tasks) by_code = {} for t in done_tasks: c = (t.ktask_resolution_code or "UNKNOWN").upper() @@ -379,6 +394,12 @@ async def handle_report( "resolved_escalated": by_code.get("ESCALATED", 0), "sentiment_notes": "", }, + "section05-costs": { + "total_coins": total_coins, + "conversations_count": len(done_tasks), + "avg_coins_per_conversation": total_coins // max(len(done_tasks), 1), + "budget_utilization_pct": round(total_coins / max(total_budget, 1) * 100, 1), + }, } date_str = now.strftime("%Y%m%d")