Spaces:
Sleeping
Sleeping
File size: 2,081 Bytes
01aa6b9 |
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 |
"""Define the configurable parameters for the agent."""
from __future__ import annotations
from dataclasses import dataclass, field, fields
from typing import Annotated
from langchain_core.runnables import ensure_config
from langgraph.config import get_config
from src.prompts import SYSTEM_PROMPT
@dataclass(kw_only=True)
class Configuration:
"""The configuration for the agent."""
system_prompt: str = field(
default=SYSTEM_PROMPT,
metadata={
"description": "The system prompt to use for the agent's interactions. "
"This prompt sets the context and behavior for the agent."
},
)
google_model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
default="gemini-2.0-flash",
metadata={
"description": "The name of the Google AI language model to use for the agent's main interactions. "
"Should be in the form: model-name."
},
)
max_iter: int = field(
default=5,
metadata={
"description": "The maximum number of iterations to run."
},
)
max_search_results: int = field(
default=5,
metadata={
"description": "The maximum number of search results to return for each search query."
},
)
temperature: float = field(
default=0.2,
metadata={
"description": "The temperature to use for the model's responses. "
"Higher values result in more random outputs, while lower values make the output more deterministic."
},
)
@classmethod
def from_context(cls) -> Configuration:
"""Create a Configuration instance from a RunnableConfig object."""
try:
config = get_config()
except RuntimeError:
config = None
config = ensure_config(config)
configurable = config.get("configurable") or {}
_fields = {f.name for f in fields(cls) if f.init}
return cls(**{k: v for k, v in configurable.items() if k in _fields}) |