Chapter 42
Best Practices
Best Practices
When to Use What
| Scenario | Use This | Why |
|---|---|---|
| Creating/editing flows | AI Copilot | Fastest way to generate YAML flow code |
| Answering questions about your data | RAG | Grounds responses in real data |
| Fixed, repeatable ETL pipelines | Traditional workflows | Deterministic, predictable, compliant |
| Research and analysis tasks | AI Agents | Can adapt to findings and make decisions |
| Complex, multi-step objectives | Multi-agent systems | Specialized agents working together |
Cost Considerations
AI features use LLM APIs, which have costs based on token usage.
Pricing per 1M tokens (full pricing page):
| Model | Tier | Input | Output |
|---|---|---|---|
| Gemini 2.5 Flash | Free | $0.00 | $0.00 |
| Gemini 2.5 Flash | Batch / Flex | $0.15 | $1.25 |
| Gemini 3.5 Flash | Free | $0.00 | $0.00 |
| Gemini 3.5 Flash | Standard | $1.50 | $9.00 |
| Gemini 3.5 Flash | Batch / Flex | $0.75 | $4.50 |
| Gemini 3.5 Flash | Priority | $2.70 | $16.20 |
Use Gemini 2.5 Flash for most workflows — it's cheaper and free for standard inference. Step up to Gemini 3.5 Flash when you need stronger reasoning for complex agent tasks.
Cost-saving tips:
- Start with the free tier for learning and development
- Use smaller/cheaper models for simple tasks — check the pricing page
- Set
maxOutputTokensto limit response size - Monitor token usage in execution outputs
- Use traditional workflows when determinism is needed
Security
Never commit API keys to Git. Always use secrets:
# ❌ Wrong
apiKey: "sk-abc123def456"
# ✅ Correct
apiKey: "{{ secret('GEMINI_API_KEY') }}"Export base64-encoded keys as SECRET_-prefixed environment variables before starting Kestra. Rotate keys regularly (e.g., every 90 days) and monitor usage. Read more about secrets in the Kestra documentation.
Observability and Debugging
Enable detailed logging when troubleshooting:
- id: my_agent_task
type: io.kestra.plugin.ai.agent.AIAgent
provider:
# ...
# provider settings
# ...
configuration:
logRequests: true
logResponses: trueMonitor token usage per execution, agent tool calls and decisions, execution time and costs, and output quality.
Debugging tips:
- Start with simple prompts and iterate
- Check logs for LLM reasoning
- Verify tool execution outputs
Production Readiness
Before deploying AI workflows to production:
- Test thoroughly — run multiple times with different inputs, verify outputs are consistent and accurate
- Add fallbacks — handle API failures with retries and configure alerts on failure
- Set limits — cap
maxOutputTokensto control costs - Document behavior — explain what the agent does in your flow and task descriptions
