SurfSense/surfsense_backend/app/agents/researcher/qna_agent/configuration.py

32 lines
1.1 KiB
Python
Raw Normal View History

2025-06-03 00:10:35 -07:00
"""Define the configurable parameters for the agent."""
from __future__ import annotations
from dataclasses import dataclass, fields
from typing import Any
2025-06-03 00:10:35 -07:00
from langchain_core.runnables import RunnableConfig
@dataclass(kw_only=True)
class Configuration:
"""The configuration for the Q&A agent."""
# Configuration parameters for the Q&A agent
user_query: str # The user's question to answer
2025-06-05 23:52:34 -07:00
reformulated_query: str # The reformulated query
relevant_documents: list[
Any
] # Documents provided directly to the agent for answering
2025-06-03 00:10:35 -07:00
search_space_id: int # Search space identifier
language: str | None = None # Language for responses
2025-06-03 00:10:35 -07:00
@classmethod
def from_runnable_config(
cls, config: RunnableConfig | None = None
2025-06-03 00:10:35 -07:00
) -> Configuration:
"""Create a Configuration instance from a RunnableConfig object."""
configurable = (config.get("configurable") or {}) if config else {}
_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})