KaiserShultz/Ankelodon_AI_Multi_task_agentic_system
1
1from typing import List, Optional, Literal2from pydantic import BaseModel, Field, field_validator3 4class ComplexityLevel(BaseModel):5 level: Literal["simple", "moderate", "complex"] = Field(description="Complexity level of the query")6 reasoning: str = Field(description="Explanation for the complexity assessment")7 needs_planning: bool = Field(description="Whether this query requires detailed planning")8 suggested_approach: str = Field(description="Recommended approach for handling this query")9 10class CritiqueFeedback(BaseModel):11 quality_score: int = Field(ge=1, le=10, description="Quality score from 1-10")12 is_complete: bool = Field(description="Whether the answer is complete")13 is_accurate: bool = Field(description="Whether the answer appears accurate")14 missing_elements: List[str] = Field(default_factory=list, description="What's missing from the answer")15 errors_found: List[str] = Field(default_factory=list, description="Potential errors identified")16 suggested_improvements: List[str] = Field(default_factory=list, description="Suggestions for improvement")17 needs_replanning: bool = Field(description="Whether the plan should be revised")18 replan_instructions: Optional[str] = Field(default=None, description="Instructions for replanning")19 20TaskType = Literal["info", "calc", "table", "doc_qa", "image_qa", "multi_hop"]21 22class PlanStep(BaseModel):23 id: str = Field(description="Unique step identifier (e.g., s1)")24 goal: str = Field(description="What the step accomplishes and why")25 tool: Optional[str] = Field(default=None, description="Exact tool name or null when no tool is required")26 inputs: Optional[str] = Field(default=None, description="Important inputs or references needed for the step")27 expected_result: str = Field(description="How to confirm the step succeeded")28 on_fail: str = Field(default="replan", description="Fallback action if the step fails (replan or stop)")29 30 @field_validator("tool", mode="before")31 @classmethod32 def normalize_tool(cls, value: Optional[str]) -> Optional[str]:33 """Ensure blank or null-like values are interpreted as no tool."""34 35 if value is None:36 return None37 if isinstance(value, str):38 cleaned = value.strip()39 if not cleaned or cleaned.lower() in {"null", "none"}:40 return None41 return cleaned42 return value43 44class PlannerPlan(BaseModel):45 task_type: TaskType46 summary: str = Field(description="Short explanation of the chosen strategy")47 assumptions: List[str] = Field(default_factory=list)48 steps: List[PlanStep] = Field(default_factory=list)49 answer_guidelines: Optional[str] = Field(default=None, description="Reminders for formatting, citations, etc.")50 51 52class ToolExecution(BaseModel):53 tool_name: str54 arguments: str55 call_id: str56 57 class Config:58 extra = "forbid"59 60class ExecutionReport(BaseModel):61 """Structured report for critic evaluation."""62 query_summary: str = Field(description="Brief summary of the user's query")63 approach_used: str = Field(description="What approach/strategy was used")64 tools_executed: List[ToolExecution] = Field(default_factory=list, description="List of tools used with results")65 key_findings: List[str] = Field(default_factory=list, description="Main findings or results")66 data_sources: List[str] = Field(default_factory=list, description="Sources of information used")67 assumptions_made: List[str] = Field(default_factory=list, description="Any assumptions made during execution")68 confidence_level: Literal["low", "medium", "high"] = Field(description="Confidence in the answer")69 limitations: List[str] = Field(default_factory=list, description="Known limitations or caveats")70 final_answer: str = Field(description="NO OTHER WORDS EXCEPT THESE RULES: Formatting rules: 1. If the question asks for a *first name*, output the first given name only.\n 2. If the answer is purely numeric, output digits only (no commas, units, words) as a string. \n 3. Otherwise capitalize the first character of your answer **unless** doing so would change the original spelling of text you are quoting verbatim")71 72 class Config:73 extra = "forbid"