Advanced project: LLM reporting agent
This example demonstrates a resilient agentic report generator that showcases Flyte 2.0’s advanced features for building production-grade AI workflows.
What you’ll build
A batch report generator that:
- Processes multiple topics in parallel
- Iteratively critiques and refines each report until it meets a quality threshold
- Produces multiple output formats (Markdown, HTML, summary) for each report
- Serves results through an interactive UI
Concepts covered
| Feature | Description |
|---|---|
ReusePolicy |
Keep containers warm for high-throughput batch processing |
@flyte.trace |
Checkpoint LLM calls for recovery and observability |
RetryStrategy |
Handle transient API failures gracefully |
flyte.group |
Organize parallel batches and iterations in the UI |
asyncio.gather |
Fan out to process multiple topics concurrently |
| Pydantic models | Structured LLM outputs |
AppEnvironment |
Deploy interactive Streamlit apps |
RunOutput |
Connect apps to pipeline outputs |
Architecture
flowchart TD
A[Topics List] --> B
B["report_batch_pipeline<br/><i>driver_env</i>"]
subgraph B1 ["refine_all (parallel)"]
direction LR
R1["refine_report<br/>topic 1"]
R2["refine_report<br/>topic 2"]
R3["refine_report<br/>topic N"]
end
B --> B1
subgraph B2 ["format_all (parallel)"]
direction LR
F1["format_outputs<br/>report 1"]
F2["format_outputs<br/>report 2"]
F3["format_outputs<br/>report N"]
end
B1 --> B2
B2 --> C["Output: List of Dirs"]
Each refine_report task runs in a reusable container (llm_env) and performs
multiple LLM calls through traced functions:
flowchart TD
A[Topic] --> B["generate_initial_draft<br/><i>@flyte.trace</i>"]
B --> C
subgraph C ["refinement_loop"]
direction TB
D["critique_content<br/><i>@flyte.trace</i>"] -->|score >= threshold| E[exit loop]
D -->|score < threshold| F["revise_content<br/><i>@flyte.trace</i>"]
F --> D
end
C --> G[Refined Report]
Prerequisites
- A Union.ai account with an active project
- An OpenAI API key stored as a secret named
openai-api-key
To create the secret:
flyte secret create openai-api-keyParts
- Resilient generation: Set up reusable environments, traced LLM calls, and retry strategies
- Agentic refinement: Build the iterative critique-and-revise loop
- Parallel outputs: Generate multiple formats concurrently
- Serving app: Deploy an interactive UI for report generation
Key takeaways
-
Reusable environments for batch processing:
ReusePolicykeeps containers warm, enabling efficient processing of multiple topics without cold start overhead. With 5 topics × ~7 LLM calls each, the reusable pool handles ~35 calls efficiently. -
Checkpointed LLM calls:
@flyte.traceprovides automatic checkpointing at the function level, enabling recovery without re-running expensive API calls. -
Agentic patterns: The generate-critique-revise loop demonstrates how to build self-improving AI workflows with clear observability through
flyte.group. -
Parallel fan-out:
asyncio.gatherprocesses multiple topics concurrently, maximizing throughput by running refinement tasks in parallel across the batch.