diff --git a/core/llm_context.py b/core/llm_context.py index 6ffa211..d8c7de6 100644 --- a/core/llm_context.py +++ b/core/llm_context.py @@ -38,6 +38,9 @@ def set_context_provider( provider: Optional["LLMProvider"], ) -> Token[Optional["LLMProvider"]]: + """Set the provider for the current context (request). Returns a Token + that MUST be passed to reset_context_provider when the request ends - + see api/dependencies for the yield-dependency that does this.""" """Set the provider for the current context (request). Returns a Token that MUST be passed to reset_context_provider() @@ -48,6 +51,11 @@ def set_context_provider( def reset_context_provider(token: Token[Optional["LLMProvider"]]) -> None: + """Undo a prior set_context_provider call. The Token is typed to this + ContextVar's value type, so a Token from a different ContextVar is a + type error, not a silent cross-context reset. Always call this in a + `finally` block paired with the `set_context_provider` that produced + `token`, so a provider never outlives the request that set it.""" """Undo a prior set_context_provider call. Always call this in a `finally` block paired with the