Design a small orchestration engine for a multi-agent workflow. Each agent is a function that consumes a shared state dictionary and may emit new tasks for other agents; tasks form a directed dependency graph. Implement a scheduler that executes agents when their dependencies are satisfied, prevents duplicate execution, and detects cycles or deadlocks. The function should return the ordered execution trace and final shared state, or an error if the workflow cannot complete. Explain how your design would change if agents could fail transiently and need retries.