refactor(agent): hug/pack bracket spans in async_utils + aux_accounting, fix E305 blank lines
This commit is contained in:
@@ -18,12 +18,9 @@ _DEFAULT_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def safe_schedule_threadsafe(
|
||||
coro: Coroutine[Any, Any, Any],
|
||||
loop: Optional[asyncio.AbstractEventLoop],
|
||||
*,
|
||||
coro: Coroutine[Any, Any, Any], loop: Optional[asyncio.AbstractEventLoop], *,
|
||||
logger: Optional[logging.Logger] = None,
|
||||
log_message: str = "Failed to schedule coroutine on loop",
|
||||
log_level: int = logging.DEBUG,
|
||||
log_message: str = "Failed to schedule coroutine on loop", log_level: int = logging.DEBUG,
|
||||
) -> Optional[Future]:
|
||||
"""Schedule ``coro`` on ``loop`` from a sync context, leak-safe.
|
||||
|
||||
|
||||
@@ -43,10 +43,7 @@ def reset_accounting_context(token) -> None:
|
||||
|
||||
|
||||
def record_aux_usage(
|
||||
response: Any,
|
||||
task: Optional[str],
|
||||
*,
|
||||
provider: Optional[str] = None,
|
||||
response: Any, task: Optional[str], *, provider: Optional[str] = None,
|
||||
base_url: Optional[str] = None,
|
||||
) -> None:
|
||||
"""Record an auxiliary response's token usage against the ambient session.
|
||||
@@ -85,17 +82,10 @@ def record_aux_usage(
|
||||
except Exception:
|
||||
logger.debug("Aux usage cost estimation failed", exc_info=True)
|
||||
session_db.record_auxiliary_usage(
|
||||
session_id,
|
||||
task,
|
||||
model=model,
|
||||
billing_provider=provider,
|
||||
billing_base_url=base_url,
|
||||
input_tokens=usage.input_tokens,
|
||||
output_tokens=usage.output_tokens,
|
||||
cache_read_tokens=usage.cache_read_tokens,
|
||||
cache_write_tokens=usage.cache_write_tokens,
|
||||
reasoning_tokens=usage.reasoning_tokens,
|
||||
estimated_cost_usd=estimated_cost,
|
||||
session_id, task, model=model, billing_provider=provider, billing_base_url=base_url,
|
||||
input_tokens=usage.input_tokens, output_tokens=usage.output_tokens,
|
||||
cache_read_tokens=usage.cache_read_tokens, cache_write_tokens=usage.cache_write_tokens,
|
||||
reasoning_tokens=usage.reasoning_tokens, estimated_cost_usd=estimated_cost,
|
||||
)
|
||||
except Exception:
|
||||
logger.debug("Aux usage recording failed (non-fatal)", exc_info=True)
|
||||
|
||||
@@ -105,6 +105,7 @@ def aux_probe_mode():
|
||||
finally:
|
||||
_aux_probe_state.active = prev
|
||||
|
||||
|
||||
from agent.credential_pool import load_pool
|
||||
from agent.model_metadata import (
|
||||
MINIMUM_CONTEXT_LENGTH, get_model_context_length,
|
||||
@@ -2422,6 +2423,8 @@ def _relay_sync_stream(
|
||||
model_name=str(kwargs.get("model") or fallback_model), finalizer=dict, metadata=metadata,
|
||||
completed_response_predicate=lambda value: hasattr(value, "choices"),
|
||||
)
|
||||
|
||||
|
||||
_RUNTIME_MAIN_COMPAT_SNAPSHOT: Tuple[Any, ...] = ("", "", "", "", "", "")
|
||||
_RUNTIME_MAIN_COMPAT_LOCK = threading.Lock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user