Multi-LLM Workflows
Leverage different LLM models for specific tasks within a workflow.
This example demonstrates how to use multiple LLM models within a single ControlFlow workflow. We’ll use GPT-4o-mini models for efficient classification tasks and GPT-4o for more complex synthesis. This approach allows us to optimize for both speed and quality in our AI-powered workflows.
In this scenario, we’ll create a workflow that analyzes customer feedback for a product. The workflow will:
- Classify the sentiment of each piece of feedback (using GPT-4o-mini)
- Categorize the topic of each piece of feedback (using GPT-4o-mini)
- Generate a comprehensive summary of the feedback (using GPT-4o)
Code
Example usage
Key points
-
Multiple LLM Models: We use GPT-4o-mini for quick classification tasks (sentiment and topic) and GPT-4o for the more complex task of summarization.
-
Specialized Agents: We create separate agents for different tasks, each with its own LLM model. This allows us to optimize for both speed and quality.
-
Structured Data: We use Pydantic models (
Feedback
andFeedbackSummary
) to ensure type safety and consistent data structures throughout the workflow. -
Task-Specific Result Types: Each task has a specific
result_type
that matches the expected output, ensuring that the agents provide the correct type of information. -
Workflow Composition: The
analyze_customer_feedback
flow composes multiple tasks into a cohesive workflow, demonstrating how ControlFlow can manage complex, multi-step processes that include loops and conditional logic.
This example showcases how ControlFlow allows you to leverage the strengths of different LLM models within a single workflow. By using more efficient models for simpler tasks and more powerful models for complex analysis, you can create workflows that are both fast and capable of high-quality output.