text
stringlengths
0
59.1k
`Create a detailed visual description for a square Instagram advertisement:
Product: ${productName}
Tagline: "${tagline}"
Concept: ${adConcept}
Style: ${style}
${targetAudience ? `Target audience: ${targetAudience}` : ""}
Requirements:
- Include the product name and tagline prominently
- Eye-catching and scroll-stopping design
- Modern design principles with clear visual hierarchy
- Optimized for Instagram feed`,
{ temperature: 0.5 }
);
// Prepare image generation with optional screenshot reference
const userContent = [{ type: "text", text: imagePrompt }];
const screenshotPath = context?.context.get("screenshotPath");
if (screenshotPath) {
const screenshotBuffer = await fs.readFile(screenshotPath);
const processedScreenshot = await sharp(screenshotBuffer)
.resize(1024, 1024, { fit: "cover" })
.png()
.toBuffer();
userContent.push({
type: "image",
image: processedScreenshot,
mediaType: "image/png",
});
}
// Generate the Instagram ad
const imageResult = await imageGenerationAgent.generateText(
[{ role: "user", content: userContent }],
{
providerOptions: {
google: { responseModalities: ["IMAGE"] },
},
temperature: 0.3,
}
);
// Save the generated image
const buffer = Buffer.from(imageResult.files[0].base64, "base64");
const filename = `instagram_${productName}_${Date.now()}.png`;
const filepath = path.join(outputDir, filename);
await fs.writeFile(filepath, buffer);
// Create public URL for immediate preview
const baseUrl = process.env.PUBLIC_BASE_URL ?? `http://localhost:${process.env.PORT ?? "3141"}`;
const publicUrl = new URL(path.relative(process.cwd(), filepath), baseUrl).toString();
return { success: true, publicUrl };
},
});
```
</details>
![Gemini Tool](https://cdn.voltagent.dev/examples/with-ad-generator/gemini-image-generation-tool.png)
Implementation:
- Two-stage generation: creative brief, then image
- Incorporates landing page screenshots as references
- Processes to Instagram square format (1024x1024)
- Local asset storage with public URL generation
- Context maintenance for traceability
**Screenshot integration:** When available, screenshots from landing page analysis are included as references for visual consistency.
### Application Structure
![Agent Running](https://cdn.voltagent.dev/examples/with-ad-generator/complete-app.png)
Application configuration and initialization:
<details>
<summary>Show index.ts</summary>
```typescript
import "dotenv/config";
import { VoltAgent, Memory, VoltAgentObservability } from "@voltagent/core";
import { LibSQLMemoryAdapter, LibSQLObservabilityAdapter } from "@voltagent/libsql";
import { createPinoLogger } from "@voltagent/logger";
import { honoServer } from "@voltagent/server-hono";
import { serveStatic } from "@hono/node-server/serve-static";
import { createSupervisorAgent } from "./agents/supervisor.agent";
// Create a logger instance
const logger = createPinoLogger({
name: "ai-ad-generator",
level: "info",
});
// Configure persistent memory (LibSQL / SQLite)
const memory = new Memory({
storage: new LibSQLMemoryAdapter({