Spaces:
Sleeping
Sleeping
"""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 | |
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." | |
}, | |
) | |
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}) |