forked from langchain-ai/react-agent
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathcontext.py
More file actions
70 lines (57 loc) · 2.4 KB
/
context.py
File metadata and controls
70 lines (57 loc) · 2.4 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
68
69
70
"""Define the configurable parameters for the agent."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Annotated
from . import prompts
@dataclass(kw_only=True)
class Context:
"""The context for the agent."""
system_prompt: str = field(
default=prompts.SYSTEM_PROMPT,
metadata={
"description": "The system prompt to use for the agent's interactions. "
"This prompt sets the context and behavior for the agent.",
},
)
model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
default="qwen:qwen-flash",
metadata={
"description": "The name of the language model to use for the agent's main interactions. "
"Should be in the form: provider:model-name.",
"json_schema_extra": {"langgraph_nodes": ["call_model"]},
},
)
max_search_results: int = field(
default=5,
metadata={
"description": "The maximum number of search results to return for each search query.",
"json_schema_extra": {"langgraph_nodes": ["tools"]},
},
)
enable_deepwiki: bool = field(
default=False,
metadata={
"description": "Whether to enable the DeepWiki MCP tool for accessing open source project documentation.",
"json_schema_extra": {"langgraph_nodes": ["tools"]},
},
)
def __post_init__(self) -> None:
"""Fetch env vars for attributes that were not passed as args."""
import os
from dataclasses import fields
for f in fields(self):
if not f.init:
continue
current_value = getattr(self, f.name)
default_value = f.default
env_var_name = f.name.upper()
env_value = os.environ.get(env_var_name)
# Only override with environment variable if current value equals default
# This preserves explicit configuration from LangGraph configurable
if current_value == default_value and env_value is not None:
if isinstance(default_value, bool):
# Handle boolean environment variables
env_bool_value = env_value.lower() in ("true", "1", "yes", "on")
setattr(self, f.name, env_bool_value)
else:
setattr(self, f.name, env_value)