""" AI Agent 루프 예제. AI가 여러 번 워크플로우를 호출하며 결과를 평가하는 패턴. """ import asyncio from comfybridgeio import ComfyBridge async def generate_image(bridge: ComfyBridge, prompt: str, seed: int) -> bytes: result = await bridge.run( workflow="workflows/sdxl_bridge_template.json", inputs={"prompt": prompt, "seed": seed, "steps": 25}, ) return result.as_bytes("output_image") async def main(): bridge = ComfyBridge(host="localhost", port=8188) prompts = [ "a red apple on a wooden table, photorealistic", "a blue ocean at sunset, cinematic", "a futuristic city at night, neon lights", ] for i, prompt in enumerate(prompts): print(f"Generating [{i+1}/{len(prompts)}]: {prompt[:50]}...") img_bytes = await generate_image(bridge, prompt, seed=i * 1000) out_path = f"output_{i}.png" with open(out_path, "wb") as f: f.write(img_bytes) print(f" Saved: {out_path}") if __name__ == "__main__": asyncio.run(main())