"""Image generation tool for agents.""" from typing import Literal from agents import function_tool from backend.services.image_generator import ( generate_educational_image, generate_concept_visualization, ) @function_tool async def generate_image( description: str, style: Literal[ "realistic", "cartoon", "diagram", "sketch", "watercolor", "3d", "minimalist", "educational", ] = "educational", context: str = "", ) -> str: """ Generate an educational image using AI. Args: description: What to visualize in the image style: Style of the image context: Additional learning context Returns: Base64 encoded image data or error message """ result = await generate_educational_image( description=description, style=style, context=context if context else None, ) if "error" in result: return f"ERROR: {result['error']}" image_data = result.get("image_data", "") mime_type = result.get("mime_type", "image/png") return f"data:{mime_type};base64,{image_data}" @function_tool async def visualize_concept( concept: str, level: Literal["beginner", "intermediate", "advanced"] = "intermediate", ) -> str: """ Generate a visualization for a learning concept. Args: concept: The concept to visualize level: Explanation level (beginner, intermediate, advanced) Returns: Base64 encoded image data URL or error message """ result = await generate_concept_visualization( concept=concept, explanation_level=level, ) if "error" in result: return f"ERROR: {result['error']}" image_data = result.get("image_data", "") mime_type = result.get("mime_type", "image/png") return f"data:{mime_type};base64,{image_data}"