StoryWriter Agent
| File | lib/agents/storyWriter.ts |
| Orchestrated by | lib/agents/storyOrchestrator.ts |
| Model | gemini-2.5-pro (Vertex AI) |
| Triggered by | Story generation — after SafetyGuardian approves |
What it does
Writes a complete children's story in the requested language and page count. Only runs after SafetyGuardian has approved the prompt. Produces story text per page plus an English image prompt for each page (used by the Illustrator agent).
Tools
| Tool | When called | Parameters |
|---|---|---|
submit_story | Once, with the complete story | title: string, pages: Page[] |
The agent calls submit_story exactly once with the full story JSON.
Output structure
json
{
"title": "Luna and the Golden Key",
"pages": [
{
"pageNumber": 1,
"text": "Story text in the target language...",
"imagePrompt": "Detailed English illustration prompt for Imagen..."
},
{
"pageNumber": 2,
"text": "...",
"imagePrompt": "..."
}
]
}Rules enforced by the agent prompt
- Story
textis written in the target language (Indonesian, French, Portuguese, etc.) imagePromptis always in English — required by Imagen for image generation- Page count is 4–6 depending on
pageCountinput (clamped: min 4, max 6) - Content is age-appropriate for 5–12, positive endings, simple vocabulary
- Each page text is 2–4 sentences, suitable for one storybook page
Supported languages
| Code | Language |
|---|---|
en | English |
id | Indonesian |
es | Spanish |
fr | French |
pt | Portuguese (Brazil) |
pt_pt | Portuguese (Portugal) |
de | German |
it | Italian |
ja | Japanese |
ko | Korean |
zh | Chinese (Simplified) |
ar | Arabic |
hi | Hindi |
ru | Russian |
vi | Vietnamese |
ms | Malay |
fil | Filipino |
tet | Tetum |
my | Burmese (Myanmar) |
lo | Lao |
km | Khmer (Cambodia) |
Flow
StoryOrchestrator (after SafetyGuardian approves)
│
▼
StoryWriter LLM call
│
└── submit_story({ title, pages[] })
│
▼
JSON extracted → returned to orchestrator
│
▼
Pages sent to Illustrator + Narrator (parallel)Observability span
Span name: agent/StoryWriter
| Attribute | Example value |
|---|---|
agent.name | StoryWriter |
agent.model | gemini-2.5-pro |
agent.language | id |
agent.pageCount | 5 |
agent.pages_generated | 5 |
agent.success | true |
agent.duration_ms | 14200 |
Simulation test cases
Run with npm run simulate:
| Scenario | Expected |
|---|---|
| English story — valid structure | title + pages[], all fields present |
| Indonesian story | Story text contains Indonesian words |
| Exact page count — 5 pages | pages.length === 5 |
| Non-English story — image prompts in English | imagePrompt contains English words |
