# 1.5 Workflows vs. agents

Workflows orchestrate LLMs through predefined code paths; agents direct their own control flow.

1. Workflow: predefined code path, deterministic hops.
2. Agent: model-directed control flow and tool selection.
3. An unhandled edge case breaks the static path.
4. The agent re-plans at runtime, paying in turns and latency.

- **Use when:** Workflows for predictable decomposition; agents for open-ended tasks.
- **Avoid:** Autonomy where a single augmented LLM call suffices.

```
# Workflow: your code decides the path
def handle(task):
    return polish(draft(outline(task)))

# Agent: the model decides the path
def handle(task):
    while not done:
        action = llm.next_action(history)
        history.append(run(action))
```

## References

- [Building effective agents](https://www.anthropic.com/engineering/building-effective-agents) (Anthropic)
- [A practical guide to building agents](https://cdn.openai.com/business-guides-and-resources/a-practical-guide-to-building-agents.pdf) (OpenAI)
- [Workflows and agents](https://docs.langchain.com/oss/python/langgraph/workflows-agents) (LangChain)
- [12-factor agents](https://github.com/humanlayer/12-factor-agents) (HumanLayer)
