-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathconfiguration.py
More file actions
67 lines (54 loc) · 1.94 KB
/
configuration.py
File metadata and controls
67 lines (54 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
from pydantic import BaseModel, Field
from typing import Any, Optional
from langchain_core.runnables import RunnableConfig
class Configuration(BaseModel):
"""The configuration for the agent."""
query_generator_model: str = Field(
default="gemini-2.0-flash",
metadata={
"description": "The name of the language model to use for the agent's query generation."
},
)
reflection_model: str = Field(
default="gemini-2.5-flash",
metadata={
"description": "The name of the language model to use for the agent's reflection."
},
)
answer_model: str = Field(
default="gemini-2.5-pro",
metadata={
"description": "The name of the language model to use for the agent's answer."
},
)
number_of_initial_queries: int = Field(
default=3,
metadata={"description": "The number of initial search queries to generate."},
)
max_research_loops: int = Field(
default=2,
metadata={"description": "The maximum number of research loops to perform."},
)
track_token_usage: bool = Field(
default=True,
metadata={
"description": "Enable token usage tracking for cost monitoring and optimization."
},
)
@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 {}
)
# Get raw values from environment or config
raw_values: dict[str, Any] = {
name: os.environ.get(name.upper(), configurable.get(name))
for name in cls.model_fields.keys()
}
# Filter out None values
values = {k: v for k, v in raw_values.items() if v is not None}
return cls(**values)