INNER CODE UNIT · Python
__init__
victordibia/designing-multiagent-systems · course/samples/book_generator/autogen_core/app.py:32
def __init__(self, api_key: str) -> None:
super().__init__("Story generator agent")
self.client = genai.Client(api_key=api_key)
@message_handler
async def handle_story_request(self, message: StoryRequest, ctx: MessageContext) -> None:
try:
print(f">>> StoryGeneratorAgent: {message.prompt}")
response = self.client.models.generate_content(
model="gemini-2.0-flash-exp",
contents=f"Create a children's story book based on this prompt: {message.prompt}",
config=types.GenerateContentConfig(
system_instruction="""You are a creative children's book writer.
Create engaging, age-appropriate stories structured as a book with clear sections.
Each section needs a descriptive image that matches the story content. The book MUST HAVE:
1. Exactly 2 chapter sections
2. Each section must have an engaging title, a level (e.g., "title", "h1", "h2"), appropriate content, and a vivid image description.""",
response_mime_type="application/json",