@melaya/runner 1.0.112 → 1.0.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assistantHost.py +23 -4
- package/package.json +1 -1
package/dist/assistantHost.py
CHANGED
|
@@ -79,10 +79,29 @@ def _emit_usage(agent, turn_id: str) -> None:
|
|
|
79
79
|
spans (Overview dashboard); the live in/out counter stays cloud-only for now."""
|
|
80
80
|
try:
|
|
81
81
|
mem = _agent_memory(agent)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
if mem is None:
|
|
83
|
+
return
|
|
84
|
+
budget = int(getattr(mem, "max_tokens", 0) or 0)
|
|
85
|
+
# Real context fullness = current retained-content tokens (NOT the rehydration
|
|
86
|
+
# watermark, which reads ~0). Falls back to 0 on an old shared bundle without
|
|
87
|
+
# current_tokens() — the gauge just won't move until the bundle updates.
|
|
88
|
+
used = int(mem.current_tokens()) if hasattr(mem, "current_tokens") else 0
|
|
89
|
+
# Live in/out tokens for THIS turn: force-flush the pending trace spans, then
|
|
90
|
+
# drain the exporter's accumulator (the SAME tokens that land in agents.spans).
|
|
91
|
+
# The BatchSpanProcessor exports asynchronously, so flush first or the turn's
|
|
92
|
+
# spans may not have been counted yet. Best-effort; 0 on an old shared bundle.
|
|
93
|
+
in_tok = out_tok = 0
|
|
94
|
+
try:
|
|
95
|
+
from opentelemetry import trace as _ot
|
|
96
|
+
tp = _ot.get_tracer_provider()
|
|
97
|
+
if hasattr(tp, "force_flush"):
|
|
98
|
+
tp.force_flush()
|
|
99
|
+
from shared.runtime.tracing_exporter import drain_token_totals
|
|
100
|
+
in_tok, out_tok = drain_token_totals()
|
|
101
|
+
except Exception:
|
|
102
|
+
pass
|
|
103
|
+
if budget > 0 or in_tok or out_tok:
|
|
104
|
+
_emit(turn_id, "usage", turnInTok=int(in_tok), turnOutTok=int(out_tok), ctxUsed=used, ctxBudget=budget)
|
|
86
105
|
except Exception:
|
|
87
106
|
pass
|
|
88
107
|
|