mirror of
https://git.mirrors.martin98.com/https://github.com/bytedance/deer-flow
synced 2025-10-04 16:06:33 +08:00
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import os
|
|
from dataclasses import dataclass, fields
|
|
from typing import Any, Optional
|
|
|
|
from langchain_core.runnables import RunnableConfig
|
|
|
|
|
|
@dataclass(kw_only=True)
|
|
class Configuration:
|
|
"""The configurable fields."""
|
|
|
|
max_plan_iterations: int = 1 # Maximum number of plan iterations
|
|
max_step_num: int = 3 # Maximum number of steps in a plan
|
|
mcp_settings: dict = None # MCP settings, including dynamic loaded tools
|
|
|
|
@classmethod
|
|
def from_runnable_config(
|
|
cls, config: Optional[RunnableConfig] = None
|
|
) -> "Configuration":
|
|
"""Create a Configuration instance from a RunnableConfig."""
|
|
configurable = (
|
|
config["configurable"] if config and "configurable" in config else {}
|
|
)
|
|
values: dict[str, Any] = {
|
|
f.name: os.environ.get(f.name.upper(), configurable.get(f.name))
|
|
for f in fields(cls)
|
|
if f.init
|
|
}
|
|
return cls(**{k: v for k, v in values.items() if v})
|