INNER CODE UNIT · Python

ImageGeneratorAgent

victordibia/designing-multiagent-systems · course/samples/book_generator/autogen_core/app.py:80

class ImageGeneratorAgent(RoutedAgent):
    def __init__(self, api_key: str) -> None:
        super().__init__("Image generator agent")
        self.client = genai.Client(api_key=api_key)

    async def generate_image(self, prompt: str) -> str:
        try:
            images = generate_images(prompt, output_dir=OUTPUT_DIR)
            return images[0] if images else ""
        except Exception as e:
            print(f"Error generating image: {str(e)}")
            return ""

    @message_handler
    async def handle_book_sections(self, message: BookSections, ctx: MessageContext) -> None:
        try:
            print(">>> ImageGeneratorAgent: Generating images for book sections")
            sections_with_images = []

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…