Does Route.pipeline
accept a Crew
or does it really need to be a Pipeline
? I see that Route.pipeline
is of type Any
and that arbitrary_types_allowed = True
.
Read the pipe line docs if not already
Thanks for your response @matt. That’s where I started and that’s how i found out about pipelines. The docs stated that we use Pipeline
s for Route.pipeline
but, when i looked at the code in hopes for greater flexibility, I saw what i reported in the op.
I just searched the docs and can’t find reference to route.pipeline’s can you share the link?
Oh are you referring to the route class in route.py?
yes. It doesn’t look like it, but the OP has 2 different links to the code.
sorry completely missed that, what is it you are trying to achieve exactly?
oooh, how come I didn’t see this before in the docs?
This allows for conditional branching in your pipeline, where different crews or sub-pipelines can be executed based on the router’s decision.
I think it means that routers can route sub-pipelines and crews.
I am trying to use routers to dynamically choose different crews without having to wrap the target crews into pipelines just for the sake of using routers. For example, I would like to do this:
# Define your crews
classification_crew = Crew(agents=[classifier], tasks=[classify_task]) # classify email between high and low urgency 1-10
urgent_crew = Crew(agents=[urgent_handler], tasks=[urgent_task])
normal_crew = Crew(agents=[normal_handler], tasks=[normal_task])
# Create a router
email_router = Router(
routes={
"high_urgency": Route(
condition=lambda x: x.get("urgency_score", 0) > 7,
pipeline=urgent_crew
),
"low_urgency": Route(
condition=lambda x: x.get("urgency_score", 0) <= 7,
pipeline=normal_crew
)
},
default=Pipeline(stages=[normal_crew]) # Default to just normal if no urgency score
)
# Use the router in a main pipeline
main_pipeline = Pipeline(stages=[classification_crew, email_router])
where the Route
s are instantiated with a Crew
instead of a Pipeline
Lest I be a lazy, I ran the code above (+ from crewai import Router, Route, Pipeline, Crew, Agent, Task
) on my system. And, although I installed version 0.51.1, I get
ImportError: cannot import name 'Router' from 'crewai'
Worked around it by:
from crewai.routers.router import Router
After this workaround, it looks like the answer to this question may be version-specific.
Try the latest version and see what happens.
@matt, I attempted to answer this question by executing the code here but all sorts of troubles came out of updating crewAI. Can you provide some sort of clarity around the validity of instantiating a Route
while stuffing a crew into its pipeline
attribute (as opposed to an actual Pipeline
)? IOW, Route(pipeline=a_crew)
(and, bonus, Router(default=a_crew)
)