1from typing import List
2
3from kern.agent import Agent
4from kern.models.neosantara import Neosantara
5from pydantic import BaseModel, Field
6
7
8class MovieScript(BaseModel):
9 setting: str = Field(
10 ..., description="Provide a nice setting for a blockbuster movie."
11 )
12 ending: str = Field(
13 ...,
14 description="Ending of the movie. If not available, provide a happy ending.",
15 )
16 genre: str = Field(
17 ...,
18 description="Genre of the movie. If not available, select action, thriller or romantic comedy.",
19 )
20 name: str = Field(..., description="Give a name to this movie")
21 characters: List[str] = Field(..., description="Name of characters for this movie.")
22 storyline: str = Field(
23 ..., description="3 sentence storyline for the movie. Make it exciting!"
24 )
25
26
27# Agent that uses structured outputs
28agent = Agent(
29 model=Neosantara(id="grok-4.1-fast-non-reasoning"),
30 description="You write movie scripts. Respond ONLY with a valid JSON object matching the provided schema.",
31 output_schema=MovieScript,
32 use_json_mode=True,
33)
34
35# Print the response in the terminal
36agent.print_response("New York")