Put the branch structure directly in the prompt

When an Agent task involves nested decisions, consecutive “if … then … otherwise …” sentences bury conditions, actions and precedence in prose. Expanding those rules into a text tree makes parent-child relationships and the next step on each branch visible.

An ASCII decision tree here means a text tree embedded directly in the prompt, using ├─, └─, │ and indentation to express paths. The Agent receives that text; no image or separate flowchart tool is required.

How the original prompt did it

The original article used incident response: determine severity, assign responders, choose mitigation, then plan communication and escalation. The repository still contains both complete prose and tree prompts.

For example, the prose version describes bad-deployment mitigation in these two rules, reproduced from the original fixture:

- If the root cause is a bad deployment and the service supports instant rollback, always prefer rollback over other mitigations because it restores the last known good state with minimal risk.
- If the root cause is a bad deployment but rollback is not available (e.g., database schema migration was applied), then consider feature flag disablement if the change is behind a feature flag. If no feature flag exists, proceed with hotfix.

The tree version expands the branches directly at the same point in the prompt:

Root cause category?
├─ Bad deployment
│   └─ Service supports instant rollback?
│       ├─ YES → action: "rollback", reason: "restore last known good state"
│       └─ NO
│           └─ Change behind feature flag?
│               ├─ YES → action: "disable_feature_flag", reason: "isolate change without rollback"
│               └─ NO  → action: "hotfix", reason: "no rollback or feature flag available"
│

Enter through Bad deployment, check instant rollback first, and continue to the feature flag question only on the NO branch. Each condition and the action it controls share a visible path; indentation preserves nesting.

Expand branching rules inside the prompt so the Agent can follow conditions to the next step, reducing the burden of reconstructing control flow from long prose. Fixed action names at the leaves also constrain output vocabulary, a technique that can be used independently.

A complete prompt with the tree inside it

Below is the repository’s shorter deployment-assistant prompt, reproduced unchanged from eval/decision-tree-ab/prompt-tree.md. Role and task, decision tree, input data and output instructions form one prompt that can be passed to an Agent.

The outer code block shows the complete prompt. The triple backticks inside it are part of the prompt itself, enclosing the tree and JSON inputs:

You are a deployment assistant. A user gives you a deployment request and a server config. Follow the decision tree below to decide what to do.

```
## Server status?
├─ "maintenance"
│   └─ Deployment urgent?
│       ├─ YES → action: "deploy", add warning: "server in maintenance"
│       └─ NO  → action: "skip", reason: "server in maintenance, non-urgent"
├─ "healthy"
│   └─ target_env matches server environment?
│       ├─ YES → action: "deploy", reason: "normal deployment"
│       └─ NO  → action: "reject", reason: "environment mismatch"
└─ other/unknown
    └─ action: "check_health", reason: "server status unknown"
```

Here is the server config:
```json
{
  "server": "prod-east-1",
  "status": "maintenance",
  "environment": "production"
}
```

Here is the deployment request:
```json
{
  "app": "payment-service",
  "version": "2.4.1",
  "target_env": "production",
  "urgent": false
}
```

Respond with a JSON object containing: action, reason, and warnings (if any).

For this input, the path is maintenance → urgent=false → skip. That is the expected action from the rules, not a new model result from this revision.

Long Agent workflows

The complex fixture, prompt-tree-complex.md, embeds trees in six steps: severity, responders, mitigation, communication, escalation and post-incident review. Each step retains its heading, context and input meanings; a tree expresses the decisions within that step. Results such as severity then feed later decisions.

Use this structure for established nested rules in Agent runtime instructions. Keep ordinary explanation as prose where no branching is needed. Split large workflows by step rather than forcing everything into one tree, and define what to do when a required condition is unavailable.

Validation

Check branch selection, permitted action names and whether actual tool calls stay within the execution scope. A prompt tree is still interpreted by the model. Token savings, latency and branch-selection accuracy each require measurement.

The original article reported output differences over 20 runs per version, but those raw results are absent from the current checkout. The prompts also changed both branch representation and action vocabulary, so the reported difference cannot be attributed entirely to the tree. The original prompts remain here as writing examples; the old numbers are not current efficacy evidence.

Workflow mode branching · Intent routing · Output contracts