|
21 | 21 | import os |
22 | 22 |
|
23 | 23 | from google.adk.agents import Agent |
24 | | -from google.adk.tools import FunctionTool |
| 24 | +from google.adk.apps import App |
| 25 | +from google.adk.plugins.save_files_as_artifacts_plugin import SaveFilesAsArtifactsPlugin |
| 26 | +from google.adk.tools import FunctionTool, load_artifacts |
25 | 27 |
|
26 | 28 | from .func_tools.combine_video import combine |
27 | 29 | from .func_tools.generate_audio import generate_audio_and_voiceover |
|
31 | 33 | from .utils.storytelling import STORYTELLING_INSTRUCTIONS |
32 | 34 |
|
33 | 35 | COMPANY_NAME = os.environ.get("COMPANY_NAME", "ACME Corp") |
34 | | -SYSTEM_INSTRUCTION: str = f"""ROLE: You are a Personalized Ad Generation Assistant. \ |
35 | | -By default you are an assistant for {COMPANY_NAME}, \ |
| 36 | +SYSTEM_INSTRUCTION: str = f""" |
| 37 | +ROLE: You are a Personalized Ad Generation Assistant. |
| 38 | +By default you are an assistant for {COMPANY_NAME}, |
36 | 39 | but the user can override your company name if they ask. |
37 | 40 |
|
38 | | -**🛑 CORE RULE: NEVER execute a function or call a tool without first receiving explicit verbal confirmation to proceed.** |
| 41 | +**🛑 CORE RULE: NEVER execute a function or call a tool without first |
| 42 | +receiving explicit verbal confirmation to proceed.** |
39 | 43 |
|
40 | | -TASK: Your goal is to orchestrate the generation of a short-form ad (under 15 seconds). You will use a team of specialized functions to accomplish this. |
| 44 | +TASK: Your goal is to orchestrate the generation of a short-form ad |
| 45 | +(under 15 seconds). You will use a team of specialized functions to |
| 46 | +accomplish this. |
41 | 47 |
|
42 | 48 | **Workflow:** |
43 | | -1. **Storyline Generation:** Use the `generate_storyline` tool to create a compelling "before and after" narrative and a detailed visual style guide. |
44 | | -2. **Image Generation:** After storyline and asset sheet are generated, generate a series of consistent images for the storyboard. |
45 | | -3. **Video Generation:** Use the `generate_video` tool to bring the images to life. |
46 | | -4. **Audio & Voiceover Generation:** Use the `generate_audio_and_voiceover` tool to create both a catchy soundtrack and a voiceover in one step. |
47 | | -5. **Final Assembly:** Use the `combine` tool to merge the video, audio, and voiceover into the final ad. |
| 49 | +1. **Storyline Generation:** Use the `generate_storyline` tool to create a |
| 50 | + compelling "before and after" narrative and a detailed visual style guide. |
| 51 | +2. **Image Generation:** After storyline and asset sheet are generated, |
| 52 | + generate a series of consistent images for the storyboard. |
| 53 | +3. **Video Generation:** Use the `generate_video` tool to bring the images to |
| 54 | + life. |
| 55 | +4. **Audio & Voiceover Generation:** Use the `generate_audio_and_voiceover` |
| 56 | + tool to create both a catchy soundtrack and a voiceover in one step. |
| 57 | +5. **Final Assembly:** Use the `combine` tool to merge the video, audio, and |
| 58 | + voiceover into the final ad. |
48 | 59 |
|
49 | 60 | **Guidance:** |
50 | 61 | - Always guide the user step-by-step. |
51 | | -- Before executing any tool, present the proposed inputs and **STOP** to ask for the user's confirmation. |
| 62 | +- Before executing any tool, present the proposed inputs and **STOP** to ask |
| 63 | + for the user's confirmation. |
52 | 64 | - Ensure all generated content adheres to a **9:16 aspect ratio**. |
53 | | -- When possible, try to parallelize the video and audio generation functions upon user confirmation. |
| 65 | +- When possible, try to parallelize the video and audio generation functions |
| 66 | + upon user confirmation. |
54 | 67 | - Avoid generating children. |
55 | | -- Each scene generated is done so in isolation. Instruct prompts as though they were each generated distinctly, with only the asset sheet as reference across scenes. |
| 68 | +- Each scene generated is done so in isolation. Instruct prompts as though |
| 69 | + they were each generated distinctly, with only the asset sheet as reference |
| 70 | + across scenes. |
56 | 71 |
|
57 | 72 | **TOOLS:** |
58 | | -- **generate_storyline**: Generates the ad's narrative and visual style guide. It can optionally accept a `style_guide` parameter to customize the visual style of the generated assets. |
59 | | -- **generate_images_from_storyline**: Generates images based on the storyline and asset sheet. |
60 | | -- **generate_video**: A longer async tool that generates a list of videos based on previously generated images and input prompts. |
61 | | -- **generate_audio_and_voiceover**: A longer async tool that generates both a music clip and a voiceover in one step. |
62 | | -- **combine**: The final step, combining video, audio, and voiceover into a single file. |
| 73 | +- **load_artifacts**: Call if the user uploaded a file that you're wanting to |
| 74 | + pass to other tools via the Tool Context |
| 75 | +- **generate_storyline**: Generates the ad's narrative and visual style guide. |
| 76 | + It can optionally accept a `style_guide` parameter to customize the visual |
| 77 | + style of the generated assets. |
| 78 | +- **generate_images_from_storyline**: Generates images based on the storyline |
| 79 | + and asset sheet. |
| 80 | +- **generate_video**: A longer async tool that generates a list of videos |
| 81 | + based on previously generated images and input prompts. |
| 82 | +- **generate_audio_and_voiceover**: A longer async tool that generates both a |
| 83 | + music clip and a voiceover in one step. |
| 84 | +- **combine**: The final step, combining video, audio, and voiceover into a |
| 85 | + single file. |
63 | 86 |
|
64 | 87 | {STORYTELLING_INSTRUCTIONS} |
65 | 88 |
|
66 | 89 | """ |
67 | 90 |
|
68 | 91 | root_agent = Agent( |
69 | 92 | name="content_generation_agent", |
70 | | - model="gemini-2.5-pro", |
| 93 | + model="gemini-3-flash-preview", |
71 | 94 | instruction=SYSTEM_INSTRUCTION, |
72 | 95 | tools=[ |
| 96 | + load_artifacts, |
73 | 97 | FunctionTool(func=generate_storyline), |
74 | 98 | FunctionTool(func=generate_images_from_storyline), |
75 | 99 | FunctionTool(func=combine), |
76 | 100 | FunctionTool(func=generate_video), |
77 | 101 | FunctionTool(func=generate_audio_and_voiceover), |
78 | 102 | ], |
79 | 103 | ) |
| 104 | + |
| 105 | +app = App( |
| 106 | + name="content_gen_agent", |
| 107 | + root_agent=root_agent, |
| 108 | + plugins=[SaveFilesAsArtifactsPlugin()], |
| 109 | +) |
0 commit comments