Agent Inside Workflow vs Workflow Inside Agent — Part 2: Code

📰 Medium · Python

Learn to implement Agent Inside Workflow and Workflow Inside Agent patterns using Microsoft Agent Framework in Python, and understand their differences in predictability, testability, and recoverability.

intermediate Published 16 Apr 2026
Action Steps
  1. Implement Agent Inside Workflow using Microsoft Agent Framework in Python to control execution and call agents as steps.
  2. Implement Workflow Inside Agent using Microsoft Agent Framework in Python to give agents control over execution and workflows.
  3. Compare the predictability, testability, and recoverability of both patterns in your system.
  4. Analyze how the boundaries between agent authority and workflow authority become visible or invisible in your code.
  5. Test and debug both patterns to understand how they handle errors and exceptions.
Who Needs to Know This

Developers and architects designing autonomous systems can benefit from understanding these patterns to make informed decisions about system design and implementation.

Key Insight

💡 The choice between Agent Inside Workflow and Workflow Inside Agent patterns determines how predictable, testable, and recoverable your system is, and understanding their differences is crucial for informed system design decisions.

Share This
💡 Implement Agent Inside Workflow and Workflow Inside Agent patterns in Python to control execution and improve system predictability, testability, and recoverability.

Key Takeaways

Learn to implement Agent Inside Workflow and Workflow Inside Agent patterns using Microsoft Agent Framework in Python, and understand their differences in predictability, testability, and recoverability.

Full Article

Title: Agent Inside Workflow vs Workflow Inside Agent — Part 2: Code

URL Source: https://medium.com/@drewelewis/agent-inside-workflow-vs-workflow-inside-agent-part-2-code-def82f4575cb?source=rss------python-5

Published Time: 2026-04-16T00:02:38Z

Markdown Content:
# Agent Inside Workflow vs Workflow Inside Agent — Part 2: Code | by Drew Lewis | Apr, 2026 | Medium

[Sitemap](https://medium.com/sitemap/sitemap.xml)

[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=post_page---top_nav_layout_nav-----------------------------------------)

Sign up

[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40drewelewis%2Fagent-inside-workflow-vs-workflow-inside-agent-part-2-code-def82f4575cb&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

[](https://medium.com/?source=post_page---top_nav_layout_nav-----------------------------------------)

Get app

[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav------------------)

[Search](https://medium.com/search?source=post_page---top_nav_layout_nav-----------------------------------------)

Sign up

[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40drewelewis%2Fagent-inside-workflow-vs-workflow-inside-agent-part-2-code-def82f4575cb&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

![Image 1](https://miro.medium.com/v2/resize:fill:32:32/1*dmbNkD5D-u45r44go_cf0g.png)

# Agent Inside Workflow vs Workflow Inside Agent — Part 2: Code

[![Image 2: Drew Lewis](https://miro.medium.com/v2/resize:fill:32:32/0*RsolKGt7zE1OZQnu.jpg)](https://medium.com/@drewelewis?source=post_page---byline--def82f4575cb---------------------------------------)

[Drew Lewis](https://medium.com/@drewelewis?source=post_page---byline--def82f4575cb---------------------------------------)

Follow

12 min read

·

1 hour ago

[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2Fdef82f4575cb&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40drewelewis%2Fagent-inside-workflow-vs-workflow-inside-agent-part-2-code-def82f4575cb&user=Drew+Lewis&userId=5bba1226e677&source=---header_actions--def82f4575cb---------------------clap_footer------------------)

[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2Fdef82f4575cb&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40drewelewis%2Fagent-inside-workflow-vs-workflow-inside-agent-part-2-code-def82f4575cb&source=---header_actions--def82f4575cb---------------------bookmark_footer------------------)

[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3Ddef82f4575cb&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40drewelewis%2Fagent-inside-workflow-vs-workflow-inside-agent-part-2-code-def82f4575cb&source=---header_actions--def82f4575cb---------------------post_audio_button------------------)

Share

In a previous post I walked through the conceptual distinction between Agent Inside Workflow and Workflow Inside Agent. The short version: Agent Inside Workflow means the workflow controls execution and agents are called as steps. Workflow Inside Agent means the agent controls execution and workflows become tools the agent calls at its discretion. Both patterns are valid. The choice determines how predictable, testable, and recoverable your system is.

This post is the follow-up I promised. I am going to show both patterns side by side using Microsoft Agent Framework in Python, walk through what happens when things go wrong in each model, and discuss where the boundaries between agent authority and workflow authority become visible or invisible in your code.

## The Scenario

To keep this concret
Read full article → ← Back to Reads