Spaces:
Sleeping
Sleeping
File size: 1,600 Bytes
560d5c2 | 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 | """Define the configurable parameters for the agent."""
from __future__ import annotations
from dataclasses import dataclass, field, fields
from typing import Annotated
from app.agent import prompts
from langchain_core.runnables import ensure_config
from langgraph.config import get_config
@dataclass(kw_only=True)
class Configuration:
"""The configuration 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="openai/gpt-4o",
metadata={
"description": "The name of the language model to use for the agent's main interactions. "
"Should be in the form: provider/model-name."
},
)
max_search_results: int = field(
default=10,
metadata={"description": "The maximum number of search results to return for each search query."},
)
@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})
|