feat: unify history tools and improve execution reliability
This commit is contained in:
1 parent
d23a4f6472
commit
2fea9865ee
116 files changed
+8291
-2503
No files matched your search
@@ -33,6 +33,7 @@ This module never raises into the LLM call path and makes no decisions.
|
||||
import threading
|
||||
from typing import Any
|
||||
|
||||
from artemis.data_engine.context_vars import CURRENT_NODE_NAME
|
||||
from artemis.utils.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -40,6 +41,16 @@ logger = get_logger(__name__)
|
||||
_LOCK = threading.Lock()
|
||||
_METERS: dict[str, "SessionTokenMeter"] = {}
|
||||
|
||||
# Size of the model context window the live Operator/FlashRunner prompt is
|
||||
# measured against when the UI reports "context used". The prompt size of the
|
||||
# last executor call (``context_base_tokens`` on its ``llm_usage`` trace) is
|
||||
# the numerator; this is the denominator.
|
||||
OPERATOR_CONTEXT_WINDOW_TOKENS = 1_000_000
|
||||
|
||||
# Traced node names whose LLM calls carry the live executor context. Both the
|
||||
# Pro Operator and the Flash runner are "the operator" from the user's view.
|
||||
OPERATOR_NODE_NAMES = frozenset({"operator", "flashrunner"})
|
||||
|
||||
|
||||
def extract_usage(response: Any) -> dict[str, int] | None:
|
||||
"""Extracts unified token usage from an LLM response message, best-effort.
|
||||
@@ -184,6 +195,9 @@ def record_llm_usage(
|
||||
}
|
||||
if source:
|
||||
payload["source"] = source
|
||||
node = CURRENT_NODE_NAME.get()
|
||||
if node:
|
||||
payload["node"] = str(node)
|
||||
|
||||
engine.record_trace(
|
||||
type="llm_call",
|
||||
|
||||
Reference in new issue
Block a user