Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /topoteretes_cognee /cognee /infrastructure /session /feedback_models.py
| from pydantic import BaseModel, Field, field_validator | |
| from cognee.infrastructure.session.session_context_models import ( | |
| CandidateContextUpdate, | |
| CandidateContextUpdateVariant, | |
| ServedContextRating, | |
| coerce_rating_or_none, | |
| ) | |
| class SessionTurnAnalysis(BaseModel): | |
| """ | |
| Result of analyzing a user message for answer routing and durable guidance. | |
| """ | |
| response_to_user: str | None = Field( | |
| default=None, | |
| description="Brief acknowledgement when no answer should be generated.", | |
| ) | |
| query_to_answer: str | None = Field( | |
| default=None, | |
| description="The question/request to answer now, or null when there is none.", | |
| ) | |
| served_context_ratings: list[ServedContextRating] = Field( | |
| default_factory=list, | |
| description="Up to 3 ratings of session-context entries served to the previous answer.", | |
| ) | |
| candidate_context_updates: list[CandidateContextUpdateVariant] = Field( | |
| default_factory=list, | |
| description=( | |
| "Up to 3 proposed session-context updates. Each item must be one of the " | |
| "section-specific candidate update types." | |
| ), | |
| ) | |
| previous_answer_rating: int | None = Field( | |
| default=None, | |
| description=( | |
| "1-5 rating of the previous answer, only when this message gives clear " | |
| "evidence about its quality; otherwise null." | |
| ), | |
| ) | |
| def rating_in_range_or_none(cls, value): | |
| """Coerce anything outside 1-5 to None, so a malformed value degrades to | |
| "no signal" rather than raising (non-blocking contract).""" | |
| return coerce_rating_or_none(value) | |
| def normalize_optional_text(cls, value: str | None) -> str | None: | |
| if value is None: | |
| return None | |
| if not isinstance(value, str): | |
| raise ValueError("value must be a string") | |
| stripped = value.strip() | |
| return stripped or None | |
| def normalize_candidate_context_updates(cls, value): | |
| if not isinstance(value, list): | |
| return [] | |
| normalized = [] | |
| for item in value: | |
| if isinstance(item, CandidateContextUpdate): | |
| item = item.model_dump() | |
| if isinstance(item, dict): | |
| item = dict(item) | |
| section = item.get("section") | |
| if isinstance(section, str): | |
| item["section"] = section.strip().lower() | |
| normalized.append(item) | |
| return normalized | |
| def cap_three(cls, v: list) -> list: | |
| """Truncate the list to the first 3 items; never raises (non-blocking contract).""" | |
| if not isinstance(v, list): | |
| return [] | |
| return v[:3] | |
| # Backwards-compatible import name for existing internal imports. | |
| FeedbackDetectionResult = SessionTurnAnalysis | |
| class AgentTraceFeedbackSummary(BaseModel): | |
| """One-sentence summary generated from an agent trace step return value.""" | |
| session_feedback: str = Field( | |
| default="", | |
| description="One short human-readable sentence summarizing the method return value.", | |
| ) | |
| def normalize_feedback(cls, value: str) -> str: | |
| if not isinstance(value, str): | |
| raise ValueError("session_feedback must be a string") | |
| return value.strip() | |
Xet Storage Details
- Size:
- 3.7 kB
- Xet hash:
- c177d48b1ad10950553ca40b0669f5649998ccb0a7d1ea0b864262f5087eaf98
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.