mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-30 03:39:38 +02:00
enforce config injection
This commit is contained in:
@@ -132,7 +132,13 @@ ASYNCIO_ACCEPTS_CONTEXT = sys.version_info >= (3, 11)
|
||||
KWARGS_CONFIG_KEYS: tuple[tuple[str, tuple[Any, ...], str, Any], ...] = (
|
||||
(
|
||||
"config",
|
||||
(RunnableConfig, "RunnableConfig", inspect.Parameter.empty),
|
||||
(
|
||||
RunnableConfig,
|
||||
"RunnableConfig",
|
||||
Optional[RunnableConfig],
|
||||
"Optional[RunnableConfig]",
|
||||
inspect.Parameter.empty,
|
||||
),
|
||||
# for now, use config directly, eventually, will pop off of Runtime
|
||||
"N/A",
|
||||
inspect.Parameter.empty,
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
from typing import Any, Optional
|
||||
|
||||
import pytest
|
||||
from langchain_core.runnables.config import RunnableConfig
|
||||
|
||||
from langgraph._internal._runnable import RunnableCallable
|
||||
from langgraph.runtime import Runtime
|
||||
@@ -370,3 +371,26 @@ async def test_runnable_callable_injectable_arguments_async() -> None:
|
||||
)
|
||||
== "success"
|
||||
)
|
||||
|
||||
|
||||
def test_config_injection() -> None:
|
||||
def func(x: Any, config: RunnableConfig) -> list[str]:
|
||||
return config.get("tags", [])
|
||||
|
||||
assert RunnableCallable(func).invoke(
|
||||
"test", config={"tags": ["test"], "configurable": {}}
|
||||
) == ["test"]
|
||||
|
||||
def func_optional(x: Any, config: Optional[RunnableConfig]) -> list[str]:
|
||||
return config.get("tags", []) if config else []
|
||||
|
||||
assert RunnableCallable(func_optional).invoke(
|
||||
"test", config={"tags": ["test"], "configurable": {}}
|
||||
) == ["test"]
|
||||
|
||||
def func_untyped(x: Any, config) -> list[str]:
|
||||
return config.get("tags", [])
|
||||
|
||||
assert RunnableCallable(func_untyped).invoke(
|
||||
"test", config={"tags": ["test"], "configurable": {}}
|
||||
) == ["test"]
|
||||
|
||||
Reference in New Issue
Block a user