# app.py # AI Agent Framework Imports from smolagents import CodeAgent, HfApiModel, tool, load_tool # Standard Library Imports (allowed) import time import yaml # Final Answer and UI Handling from tools.final_answer import FinalAnswerTool from Gradio_UI import GradioUI # -------------------------------------------- # Tool: detect_ambiguity @tool def detect_ambiguity(content: str) -> str: """Checks for vague instructions and suggests clarifications. Args: content: Text to analyze. """ return "Ambiguity detected. Click 'Is this ambiguous?' for help." # -------------------------------------------- # Tool: explain_assumed_knowledge @tool def explain_assumed_knowledge(term: str) -> str: """Defines technical terms in a simple way. Args: term: The term to explain. """ return f"Definition of '{term}': [Detailed beginner-friendly explanation here]" # -------------------------------------------- # Tool: highlight_elements (modified to a placeholder) @tool def highlight_elements(step: str, element: str, auto_execute: bool = False) -> str: """(Placeholder) Highlights a UI element and optionally performs an action. Args: step: The current step in the guide. element: The UI element to highlight (as an identifier). auto_execute: If True, the agent would auto-click the element. """ return "Highlight functionality is currently not available." # -------------------------------------------- # Tool: explain_code_line @tool def explain_code_line(line: str) -> str: """Explains what a line of code does in simple terms. Args: line: The code line to explain. """ return f"Explanation for: {line} [Insert explanation here]" # -------------------------------------------- # Tool: teacher_box_query @tool def teacher_box_query(question: str) -> str: """Allows users to ask the AI questions while browsing. Args: question: User's query. """ return f"AI Answer: [Response for '{question}']" # -------------------------------------------- # Tool: toggle_auto_execution @tool def toggle_auto_execution(enable: bool) -> str: """Lets the user turn automatic navigation on or off. Args: enable: True for auto-mode, False for manual steps. """ return "Auto-execution enabled." if enable else "Manual step-by-step mode enabled." # -------------------------------------------- # Configure the AI Model. model = HfApiModel( max_tokens=2096, # Maximum response length. temperature=0.5, # Controls response randomness. model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # Selected model. custom_role_conversions=None ) # Load prompt templates from a YAML configuration file. with open("prompts.yaml", 'r') as stream: prompt_templates = yaml.safe_load(stream) #