mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-06 22:58:30 +00:00
* docs: Fix major memory system documentation issues - Remove misleading deprecation warnings, fix confusing comments, clearly separate three memory approaches, provide accurate examples that match implementation * fix: Correct broken image paths in README - Update crewai_logo.png and asset.png paths to point to docs/images/ directory instead of docs/ directly * docs: Add system prompt transparency and customization guide - Add 'Understanding Default System Instructions' section to address black-box concerns - Document what CrewAI automatically injects into prompts - Provide code examples to inspect complete system prompts - Show 3 methods to override default instructions - Include observability integration examples with Langfuse - Add best practices for production prompt management * docs: Fix implementation accuracy issues in memory documentation - Fix Ollama embedding URL parameter and remove unsupported Cohere input_type parameter * docs: Reference observability docs instead of showing specific tool examples * docs: Reorganize knowledge documentation for better developer experience - Move quickstart examples right after overview for immediate hands-on experience - Create logical learning progression: basics → configuration → advanced → troubleshooting - Add comprehensive agent vs crew knowledge guide with working examples - Consolidate debugging and troubleshooting in dedicated section - Organize best practices by topic in accordion format - Improve content flow from simple concepts to advanced features - Ensure all examples are grounded in actual codebase implementation * docs: enhance custom LLM documentation with comprehensive examples and accurate imports * docs: reorganize observability tools into dedicated section with comprehensive overview and improved navigation * docs: rename how-to section to learn and add comprehensive overview page * docs: finalize documentation reorganization and update navigation labels * docs: enhance README with comprehensive badges, navigation links, and getting started video
89 lines
2.6 KiB
Plaintext
89 lines
2.6 KiB
Plaintext
---
|
|
title: Conditional Tasks
|
|
description: Learn how to use conditional tasks in a crewAI kickoff
|
|
icon: diagram-subtask
|
|
---
|
|
|
|
## Introduction
|
|
|
|
Conditional Tasks in crewAI allow for dynamic workflow adaptation based on the outcomes of previous tasks.
|
|
This powerful feature enables crews to make decisions and execute tasks selectively, enhancing the flexibility and efficiency of your AI-driven processes.
|
|
|
|
## Example Usage
|
|
|
|
```python Code
|
|
from typing import List
|
|
from pydantic import BaseModel
|
|
from crewai import Agent, Crew
|
|
from crewai.tasks.conditional_task import ConditionalTask
|
|
from crewai.tasks.task_output import TaskOutput
|
|
from crewai.task import Task
|
|
from crewai_tools import SerperDevTool
|
|
|
|
# Define a condition function for the conditional task
|
|
# If false, the task will be skipped, if true, then execute the task.
|
|
def is_data_missing(output: TaskOutput) -> bool:
|
|
return len(output.pydantic.events) < 10 # this will skip this task
|
|
|
|
# Define the agents
|
|
data_fetcher_agent = Agent(
|
|
role="Data Fetcher",
|
|
goal="Fetch data online using Serper tool",
|
|
backstory="Backstory 1",
|
|
verbose=True,
|
|
tools=[SerperDevTool()]
|
|
)
|
|
|
|
data_processor_agent = Agent(
|
|
role="Data Processor",
|
|
goal="Process fetched data",
|
|
backstory="Backstory 2",
|
|
verbose=True
|
|
)
|
|
|
|
summary_generator_agent = Agent(
|
|
role="Summary Generator",
|
|
goal="Generate summary from fetched data",
|
|
backstory="Backstory 3",
|
|
verbose=True
|
|
)
|
|
|
|
class EventOutput(BaseModel):
|
|
events: List[str]
|
|
|
|
task1 = Task(
|
|
description="Fetch data about events in San Francisco using Serper tool",
|
|
expected_output="List of 10 things to do in SF this week",
|
|
agent=data_fetcher_agent,
|
|
output_pydantic=EventOutput,
|
|
)
|
|
|
|
conditional_task = ConditionalTask(
|
|
description="""
|
|
Check if data is missing. If we have less than 10 events,
|
|
fetch more events using Serper tool so that
|
|
we have a total of 10 events in SF this week..
|
|
""",
|
|
expected_output="List of 10 Things to do in SF this week",
|
|
condition=is_data_missing,
|
|
agent=data_processor_agent,
|
|
)
|
|
|
|
task3 = Task(
|
|
description="Generate summary of events in San Francisco from fetched data",
|
|
expected_output="A complete report on the customer and their customers and competitors, including their demographics, preferences, market positioning and audience engagement.",
|
|
agent=summary_generator_agent,
|
|
)
|
|
|
|
# Create a crew with the tasks
|
|
crew = Crew(
|
|
agents=[data_fetcher_agent, data_processor_agent, summary_generator_agent],
|
|
tasks=[task1, conditional_task, task3],
|
|
verbose=True,
|
|
planning=True
|
|
)
|
|
|
|
# Run the crew
|
|
result = crew.kickoff()
|
|
print("results", result)
|
|
``` |