# Behavior Tree Back Chaining

> Construct an agent's behavior tree starting from the desired goal condition and recursively adding child nodes whose post-conditions satisfy each parent's pre-conditions.

- **Category**: Agentic AI
- **Subcategory**: Planning & Control Flow
- **Canonical URL**: https://designpattern.fyi/patterns/behavior_tree_back_chaining/

---

## Description
**Intent**: Construct an agent's behavior tree starting from the desired goal condition and recursively adding child nodes whose post-conditions satisfy each parent's pre-conditions.
**Context**: A team is authoring an agentic behavior tree for a complex task. Authoring it forward — guess at the root, then the children, then leaves — leads to trees that look plausible but do not actually achieve the goal because pre-conditions of interior nodes are not satisfied by the children chosen.
**Solution**: - Author the tree from the root downward by asking, for each new node: "What pre-conditions must hold for this to succeed, and what tasks produce those pre-conditions?" - Each task added becomes a child whose own pre-conditions trigger another round of back-chaining. - Recurse until pre-conditions are satisfied by the starting state. - Mechanical back-chaining yields broad trees; designers prune to the cases the agent will realistically encounter. - The discipline ensures every node's children are there because they produce something the parent needs.


## Use Cases
- Authoring a behavior tree for a task with expressible pre/post-conditions.
- Forward-authored trees have been failing because pre-conditions were missed.
- The team values construction discipline over speed of first draft.





## Trade-offs


### Advantages

- Trees demonstrably achieve the goal because pre-conditions are satisfied by construction.

- Surfaces missing tasks as an obvious gap when a pre-condition has no producer.

- Trees evolve cleanly; new edge cases add a producer for a missing pre-condition.




### Considerations & Drawbacks

- Pre-conditions and post-conditions must be expressible — many real tasks have fuzzy conditions.

- Mechanical back-chaining produces wide trees that need pruning judgment.

- Authoring discipline costs up-front time vs intuition-driven sketching.







---
**Reference**: [Original Source](https://www.agentpatternscatalog.org/patterns/behavior-tree-back-chaining/)

