- harness/es.py: append-only event store + проекции (образец — кооп-портал) - harness/levels.py: уровни 1с/1м/1ч/1д, контекст ∝ масштабу - harness/scheduler.py: уровневые потоки, идемпотентные тики, absorbed-стабы - harness/isolated_runner.py + _llm_worker.py: LLM-тик в сабпроцессе (глобальный asyncio-рантайм Strands не переживает 2+ create_harness) - cli.py: init/task/tasks/status/events + requeue (написан самим минутным агентом) - 9router: отдельный ключ sk-simbiot, модель auto (glm-5.3 первым)
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
# Copyright The OpenTelemetry Authors
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
from __future__ import annotations
|
|
|
|
from contextvars import ContextVar, Token
|
|
|
|
from opentelemetry.context.context import Context, _RuntimeContext
|
|
|
|
|
|
class ContextVarsRuntimeContext(_RuntimeContext):
|
|
"""An implementation of the RuntimeContext interface which wraps ContextVar under
|
|
the hood. This is the preferred implementation for usage with Python 3.5+
|
|
"""
|
|
|
|
_CONTEXT_KEY = "current_context"
|
|
|
|
def __init__(self) -> None:
|
|
self._current_context = ContextVar(self._CONTEXT_KEY, default=Context())
|
|
|
|
def attach(self, context: Context) -> Token[Context]:
|
|
"""Sets the current `Context` object. Returns a
|
|
token that can be used to reset to the previous `Context`.
|
|
|
|
Args:
|
|
context: The Context to set.
|
|
"""
|
|
return self._current_context.set(context)
|
|
|
|
def get_current(self) -> Context:
|
|
"""Returns the current `Context` object."""
|
|
return self._current_context.get()
|
|
|
|
def detach(self, token: Token[Context]) -> None:
|
|
"""Resets Context to a previous value
|
|
|
|
Args:
|
|
token: A reference to a previous Context.
|
|
"""
|
|
self._current_context.reset(token)
|
|
|
|
|
|
__all__ = ["ContextVarsRuntimeContext"]
|