feat(copilot): replace LangGraph config with request-scoped context variables

- Refactor `llm_call` and `generate_title` nodes to retrieve `llm_config` from request-scoped context variable instead of LangGraph config
- Remove `jwt_token` and `llm_config` from LangGraph configurable parameters in `AgentService.stream`
- Add `set_current_llm_config` and `get_current_llm_config` functions to `connector_factory` and export them in `__init__.py`
- Update `tool_node` to no longer extract `jwt_token` from config as it is now handled via context variable
- Improves thread safety and decouples configuration from LangGraph's state management
This commit is contained in:
YueGuobin committed 2026-03-04 13:49:17 +08:00
1 parent b05e6a71b4
commit eec4ebe3fd
4 files changed
+43 -20

No files matched your search

@@ -27,6 +27,8 @@ from .connector_factory import (
get_llm_config,
set_current_jwt_token,
get_current_jwt_token,
set_current_llm_config,
get_current_llm_config,
)
from .custom_gns3fy import (
CONSOLE_TYPES,
@@ -66,4 +68,6 @@ __all__ = [
"get_llm_config",
"set_current_jwt_token",
"get_current_jwt_token",
"set_current_llm_config",
"get_current_llm_config",
]
@@ -30,9 +30,10 @@ import logging
from typing import Optional
from contextvars import ContextVar
# Context variable for request-scoped jwt_token
# Context variables for request-scoped data
# Automatically cleaned up when request context ends
_jwt_token_context: ContextVar[Optional[str]] = ContextVar("_jwt_token_context", default=None)
_llm_config_context: ContextVar[Optional[dict]] = ContextVar("_llm_config_context", default=None)
def set_current_jwt_token(token: str) -> None:
@@ -43,6 +44,16 @@ def set_current_jwt_token(token: str) -> None:
def get_current_jwt_token() -> Optional[str]:
"""Get the JWT token for the current request context."""
return _jwt_token_context.get()
def set_current_llm_config(config: dict) -> None:
"""Set the LLM config for the current request context."""
_llm_config_context.set(config)
def get_current_llm_config() -> Optional[dict]:
"""Get the LLM config for the current request context."""
return _llm_config_context.get()
from uuid import UUID
from gns3server.agent.gns3_copilot.gns3_client.custom_gns3fy import Gns3Connector