Request icon
AIAgent icon
GoogleGemini icon
Set icon
Log icon

AI Starship Recommender with Conditional Prompts

Kestra flow that adapts a Gemini prompt to a user-selected priority using Pebble conditionals and returns a JSON-schema-enforced recommendation from SWAPI data.

Categories
AI

A playful dataset, a very reusable pattern. This Kestra blueprint fetches the starship catalog from the public Star Wars API and asks a Gemini-powered AI agent to recommend the best ship for a long-range mission. The twist is that the prompt itself is dynamic: Pebble {% if %} conditionals rewrite the prioritization criteria depending on whether the user selected Cargo Capacity, Speed, or Cost Efficiency from a SELECT input. The answer is forced into a JSON schema with name, justification, potentialDownside, and url, cached with taskCache, persisted to the KV store, and logged in a readable summary. Swap starships for vendors, SKUs, cloud instance types, or job candidates and the exact same skeleton applies.

How it works

  1. The priority input (SELECT) offers three optimization goals, defaulting to Speed.
  2. The get_starships task (io.kestra.plugin.core.http.Request) pulls the starship list from swapi.dev with JSON content type. No API key is required.
  3. The recommend_best_starship task (io.kestra.plugin.ai.agent.AIAgent) builds its prompt with Pebble {% if %} / {% elseif %} blocks so the model receives criteria tailored to the chosen priority, for example lower hyperdrive rating and higher MGLT when Speed is selected. responseFormat: JSON with a required-fields jsonSchema guarantees a parseable answer, and taskCache reuses the response for identical inputs.
  4. The save_recommendation task (io.kestra.plugin.core.kv.Set) stores the structured JSON under the execution id with kvType: JSON.
  5. The log_recommendation task (io.kestra.plugin.core.log.Log) renders name, justification, downside, and source URL straight from jsonOutput fields.

What you get

  • A template for priority-aware prompting: one flow, three different model instructions, zero duplicated tasks.
  • Schema-enforced LLM output that downstream tasks reference as typed fields, not scraped text.
  • Free token savings on repeat runs through taskCache.
  • A KV-store history of every recommendation for later comparison.

Who it's for

  • Developers learning Pebble templating inside AI prompts.
  • Teams building decision-support flows where users pick the optimization criterion.
  • Solutions engineers who want a fun, dependency-free demo of structured AI output.

Why orchestrate this with Kestra

Conditional prompt construction usually means string concatenation in application code. Kestra moves it into the declarative layer: Pebble conditionals live next to the prompt they modify, inputs render as a real form in the UI, and the AIAgent task validates the model's answer against a JSON schema before any downstream task runs. Combined with task caching, secret management for the API key, and full execution logs of the rendered prompt, you get an auditable, repeatable recommendation service instead of a notebook experiment.

Prerequisites

  • A Google AI Studio API key with access to Gemini models.
  • Outbound HTTPS access to swapi.dev, the free Star Wars API (no key needed).

Secrets

  • GEMINI_API_KEY: Google Gemini API key used by the AIAgent task.

Quick start

  1. Add the GEMINI_API_KEY secret to your Kestra namespace.
  2. Execute the flow and pick a priority factor in the input form.
  3. Read the structured recommendation in the task outputs and the log summary.
  4. Re-run with a different priority and compare how the justification changes.

How to extend

  • Replace SWAPI with your own catalog API: instance types, vendors, or product SKUs.
  • Add more priorities by extending the SELECT values and the Pebble branches.
  • Send the recommendation to Slack or email with a notification task.
  • Chain a second AIAgent task that critiques the first recommendation for a two-step review.
  • Store results in a database table instead of the KV store for analytics over many runs.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.