DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Reference / Methods / and_()
Method Flow

and_(): Reference Guide

By DevShelfHub

Combinator that makes @listen wait for ALL listed upstream methods to complete.

See the CrewAI methods catalog, CrewAI introduction, kickoff() reference, and core concepts for surrounding context.

What is and_()?

and_(method_a, method_b) is the declarative join primitive for CrewAI Flows. When you decorate a downstream method with listen using and_ across fetch_prices and fetch_news, the runtime schedules listeners only after every referenced upstream method has completed successfully for the current flow execution. That gives you a deterministic fan-in point where you combine outputs, merge partial state, or kick off a summarizer that must see both artifacts before continuing.

The combinator composes with router decorators because parallel branches tagged by different return values still converge through and_ when you list concrete method references you need rather than router labels themselves. Prefer explicit method references over stringly typed wiring so Flow plot output and static analysis stay accurate when you refactor method names.

If any upstream raises, downstream and_ listeners may never fire unless you design compensating error listeners with or_ or separate listen edges for failure handlers. Keep branches short lived so joins do not block human facing flows unnecessarily. Document partial failure semantics in your flow state model so operators know which inputs may be missing at join time.

Testing joins requires driving every upstream success path plus selective failure injections so you can assert the joiner never runs on half baked state. In production, metrics on join latency expose accidental serialization bottlenecks when fan out grows. Pair joins with idempotent reducers so duplicate deliveries from retries do not double count business metrics. Instrument orchestration dashboards with per join counters and upstream duration histograms so SRE teams can distinguish slow branches from actual join deadlocks when incidents spike.

Use Cases

  • Fan-in
  • Join after parallel fetch

Key Features

  • AND semantics
  • Variadic

When NOT to Use

When 'either' is enough — use or_().

Notes

Single upstream and_ is noise

and_ with one method adds no synchronization value. Listen directly on that method unless you are generating combinators dynamically.

Ordering of arguments is not execution order

and_ declares dependencies, not sort priority. Upstreams still run according to the flow graph and async scheduling; the join only gates the listener.

State shape at join time

Mutate Flow state in-place on each upstream so the joiner reads consistent keys. Replacing self.state wholesale in one branch can race with siblings unless you serialize writes.

Debugging joins

When a join never fires, inspect Flow plot output to verify every listed method actually executes on the path you expect — missing listen wiring is a common culprit.

Code Examples

Fan-in

python
@listen(and_(fetch_a, fetch_b))
def combine(self):
    return process(self.state)

Three-way data merge

python
@listen(and_(load_users, load_orders, load_inventory))
def reconcile(self):
    self.state.report = build_report(self.state)

Join after async start branches

python
@listen(and_(fetch_remote, fetch_cache))
def pick_source(self):
    self.state.body = merge(self.state.remote, self.state.cache)

When to Use

Joining parallel branches.

Common Mistakes

❌ Using and_ with a single method — pointless

✅ Just listen on the method directly.

Related: @tool decorator reference, Agent class reference, and the first Crew tutorial.

and_() FAQ

What is and_() in CrewAI?

Combinator that makes @listen wait for ALL listed upstream methods to complete. and_(method_a, method_b) is the declarative join primitive for CrewAI Flows. When you decorate a downstream method with listen using and_ across fetch_prices and fetch_news, the runtime schedules listeners only after every referenced upstream method has completed successfully for the current flow execution. That gives you a deterministic fan-in point where you combine outputs, merge partial state, or kick off a summarizer that must see both artifacts before continuing. The c…

Which CrewAI types expose the method and_()?

DevShelfHub documents and_() on Flow. The reference maps it to Python module crewai.flow.flow — pin your installed crewai version and match imports to the snippet on this page.

When should I use and_()?

Joining parallel branches.

When should I avoid and_()?

When 'either' is enough — use or_().

How do I call and_() from Python?

@listen(and_(step_a, step_b))

Where can I explore more CrewAI API reference pages?

Open the CrewAI API reference index on DevShelfHub to search classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.