Loading video player...
We've built our first AI agentic agent
using Microsoft agent framework.
Good job. But wait,
we want to do something a bit more
complicated.
Right.
Right.
Enter workflows.
Are you excited?
Hello everyone and welcome back to my
channel. My name is Kirk and in today's
video we're going to be looking at
workflows in Microsoft Agent Framework.
Now, as you probably know or maybe you
don't know, but this video is a part of
a series of videos where we keep on
diving into topics that help you build
AI agents using Microsoft Agent
Framework. So, with that said, you
should probably subscribe if you're not
already subscribed. Now, let's just jump
right into it and start looking at
workflows.
We are back to our AI agent. An agent is
given a task. After given this task, the
agent will then do react, reason plus
act. This is what makes the agent
agentic.
The agent perceives a task, reasons
about what to do, and acts by using
tools to produce outcomes.
But wait, agents often act like black
boxes. You just give them a prompt, and
they just figure it out.
Enter workflows. Workflows and agentic
frameworks give structure into how
agents think, act, and interact with its
environment. Workflows define explicit
steps in the reasoning and acting
process.
In the example shown here, we can see
the workflow steps, search knowledge
base, retrieve additional info, and
summarize info. Now, let's look at how
we can define workflows using Microsoft
Agent Framework.
And we are back and we're finally gonna
have a bit more fun with agents by
looking at workflows in Microsoft Agent
Framework. Are you excited? I am. Okay.
So, if you remember our first tutorial
way back when we first looked at
Microsoft agent framework, we created an
agent. We created an agent with tool
which had this get weather tool that we
passed into the agent and we also had
this rag tool. What I'm going to do is
I'm going to go to this agent with tool
and I'm going to modify it to create
structured output in its response.
And how we're going to do that. So I've
actually just copied this file into
agent with tools structured output
and we're going to modify this and we're
going to use a pedantic model
to create our response. And this model I
will show you right now.
It's going to be city info. And of
course
this we're going to have to import base
model here.
This is our pedantic model schema
and we're going to modify the agent
here. But let's give it a different
prompt here. When we create the agent
instead of just saying you are a helpful
assistant, we're going to say
you are a helpful assistant that figures
out the city from the information
provided and also returns the weather.
So, what we're going to do now in our
main, instead of saying, "Tell me the
weather in Los Angeles."
Now, I'm based in Canada.
So, what I'm going to do is change this
to say,
let's say
I'm at the CN Tower.
Hopefully, you know the CN Tower. If you
don't, it's uh
the second largest structure in the
world based in Toronto. I'm giving you a
hint right there. And what we're going
to do was we're going to run our agent
and we're also going to say
to let's just format this a bit nicer
and give it a response format of city
info.
And now
when this agent runs, we should have a
value and now we can output the city and
the weather in nice JSON format. That's
what we're going to get back by using
this pedantic model. So let's save this.
Let's run this.
And now the response is city Toronto
weather cloudy with a high of 15. And of
course that's what our tool does. Says
the weather in Toronto is cloudy with a
high 15. And now we are just responding
back. So think about this. The agent
figured out
just by giving it a request of I'm at
the CN Tower. It knows we're in Toronto.
can figure that out and use the tool to
return the weather.
That's pretty awesome, right? I mean,
that's worth uh the admission here just
watching this tutorial. I can just leave
now, right? I mean, we accomplished
something. I'm kidding. We haven't hit
workflows yet. So, stay tuned. A lot
more excitement, but this is step one
because we're going to use this in our
workflow next. Okay. Now what I've done
now is I've created this file called
agents and workflows
and this I've taken a lot of stuff from
our agent with tool structured output
have all the import statements we have
our padant model we have our get weather
tool and now we're going to start
filling out the contents of our main
function and what we're going to do is
we're going to create our first
workflow. Okay. So, first thing I'm
going to do in this main is I'm going to
create our chat client.
So, this looks very similar to what
we've done with agent with tool and
agent with tool structured output. So,
you look at here, we have our agent that
we're just creating and that's it. We
have our chat client.
Now we're going to create our first
agent that we're going to put into our
workflow. So I'm going to copy and paste
some code here.
Let's put this into a try.
Now look at this. We have our city info
agent and I'm giving it a name and I'm
giving it some instructions here and I'm
giving it the tools and the response
format city info. So if I just save
this, compare this to what we just did
before.
We have the exact same instructions
here. Our system prompt tools. We've
just given it a name. And our output
format, our response format, instead of
putting it here, we're putting it into
when we create the agent. So look at
that again. Pretty much the same thing
that we just did before. This is going
to take
an input.
For instance, wherever you're at, you
can put in Empire State Building and it
should give you a response of New York
and use the tool here.
And
actually, what is it? It's November 9th.
It's on a Sunday afternoon. I'm
recording this. I'm based in Toronto
and it is snowing. And yes,
probably a lot of you are not from
Canada and you think, well, it always
snows in Canada. This is pretty early
for snow
on November. Early November, December,
Christmas. Yes. So, what I'm doing is I
just changed this tool to say snowy with
with a high of 0 degrees Celsius. Gang,
I apologize. I'm a Canadian. I'm
thinking in Celsius, not Fahrenheit. But
I just want to show you that. So, we
have our agent
and we've created it. That's it. Next
step, let's create another agent. Okay,
I'm going to create another agent here.
I'm going to copy and paste some code
here.
And let's save this. Pretty much
creating the agent in the same way.
Wrapping it wrapping it with this agent
executive. Actually, I have to import
that as well. And so from
from agent framework
import
agent executive.
Save that for now.
Let's look at this agent I just created.
I'm going to call this tours
recommendations agent.
And what I'm going to do is say you are
actually not not an email assistant. You
are an assistant who provides tourist
recommendations based on
let's actually change the wording based
on a city.
Your input might be a JSON object that
includes city
and it might also include weather.
Base your response on city and weather.
If the weather is sunny and warm,
recommend an outdoor place. else
recommend an indoor place.
Do do not recommend the place you are
already at and return JSON with a single
response, a single field response. So
think about this. This agent is going to
is going to expect
as its request a JSON object with city
and weather.
This agent we already created is going
to output with city info which will have
city and it's going to have name and
weather.
So actually I should change this uh it's
going to have yeah city the name city
city info. So hopefully it will just
know that yeah um base response on city
and weather. Now it's gonna give a
response with hopefully just a
recommendation based on your input. Got
that? Okay. Now, we're going to create
our workflow. We're going to create a se
a sequential workflow pipeline.
And to do that, I'm going to copy some
code here.
We have our workflow here. We're using
workflow builder. We're going to say
start
at the city info agent. So that's the
first one we do.
Then we're create an edge.
So if you worked with other agentic
frameworks, very similar. We have nodes
which are agent executives. So something
that's being processed. In this case,
it's an agent. And we're going to attach
them.
We're going to attach these edges
together. city info agent and tourist
recommendation recommendations agent and
we're going to build it. And of course,
I have to import all this stuff.
And there we go. We have defined a very
simple sequential workflow pipeline.
Let's save that.
And I'm also gonna have a little bit of
a helper here to create diagrams for us.
So, let's do that next.
Okay. Our workflow here is pretty
simple. Just two nodes, one edge, very
it's just going to be sequential. But
when when things start getting more
complicated, we want a way to visualize
this. And Microsoft Agent Framework has
a really good helper to create diagrams
for us. Workflow viz. I've already
imported it here and I've already
installed it. So I've already done UV
add graph viz. So this is something you
need to add. Uh I'm using UV as my
package manager. So you can do pip
install as well. And you I'm also on a
MacBook. So I have brew install here.
Graph viz. I've I've already installed
this. If you are on a on Windows, I
think you have to um download it. And if
you are on Unix, you can just use appget
to install it. But just look that up. So
install graph viz and let's take a look
here. Okay. So I'm going to after we
create our workflow, we initiate our
workflow viz class here and let me give
this just give the name workflow
workflow architecture and just create a
SVG file. So that's that. Uh we run
this. Hopefully it will save this to our
docs.
I think that matches our try statement
right now. Save that. And let's give
this a run now.
Okay, I just had to match this up here.
Have this filing statement here. And now
we should be able to give this run. So
let's give this a run now.
And here we go. So this created our
workflow architecture diagram. Look at
that. So we have city info, our start
going to tourist recommendations gang
just a helper so you can visualize your
workflows. Ours is pretty simple right
now but in the future you probably want
this. So next let's actually try to run
this workflow.
Okay, now we are actually ready to run
this.
I going to run in here. We don't need to
create our diagram again. I'll just
comment that out. But if you want to
create your
diagram and again all this code will be
in my GitHub repo which you'll see in
the the comments below this. Hopefully
you're just following along. I'm trying
to do something a bit more interesting
than just a a simple workflow that
doesn't really do any AI magic. this.
I'm hoping you'll see it and it'll
inspire you
and it'll really get you excited about
using a frameworks specifically
Microsoft agent framework. Okay. So,
what I'm doing is we're going to run our
stream our workflow and say you are at
the CN Tower. Same thing that we did in
the last demo at the very start of this
tutorial. And what do you think it's
going to do? It's going to go through
that sequence, figure out what city
you're in, and then hopefully the next
agent, it will give you some more
recommendations of other places to go
based on the weather. Isn't that kind of
cool? Okay, so we have we're running the
stream
and I'm just going to copy some code
here.
Okay, so what I have here is we have a
collection of events from our stream.
And now once we are running this we're
and it's agent run update event we're
going to start outputting what's coming
from from it and I'm also outputting the
workflow status event. So let's actually
run this and see what happens and I'll
try to explain it to you. I'm hoping I
have everything here
in my import.
Yes, we do.
Look at that. So our first status event
is workflow run status in progress.
That's down here.
And
the next one we're going to have this
here. This eid is going to be our
executive name which we defined up here
as being city info.
and we're going to get back
remember Toronto and the weather in
Toronto is snowy with a high of 0
degrees which I can assure you right now
on November 9th it is and I'm not happy
about it. Okay,
now the response. Look at this. We're
coming back. We're going into our
tourist recommendations here and we've
inside the the workflow. We're feeding
in Toronto and the weather. And the
response here is since you are at the CN
Tower and the weather is snowy, a great
indoor option to explore could be the
Royal Ontario Museum. That makes sense,
right?
And then at the end, we our agent is
done. But look at that. That's pretty
cool. And that's a bit more interesting
than just um doing some very trivial
example of I don't know creating a bunch
of text and then summarizing it, which a
lot of workflow examples do. I'm hoping
this gives you a little bit of
inspiration. But let's actually change
this. Pretend again this is our weather
tool. You'd probably want to do a
restful call to actually get the real
weather. But let's say if it's
let's change this to be sunny and 20
degrees, which I assure you it's not
right now,
but sometimes it is. And I run this
again.
And right now, since the weather is
sunny and warm, okay, again, we're in
Toronto. Consider visiting High Park for
scenic outdoor experiences. So there it
knows there it knows the weather that's
being fed in from one agent in our
workflow and giving you re
recommendation since it's warm and sunny
outside telling you to go to a park.
That's it. Pretty simple, but we
actually accomplished a lot. The code
will be in my GitHub repo. Go take a
look. If you like this, please give it a
like. subscribe because I'm going to do
a lot more. I'm going to go in a lot
more depth with these agents. This is
just the start, but this is pretty
exciting. I'm excited. Hopefully, you
are too. And let's continue this
journey. Okay, that's it for today's
lesson on workflows in Microsoft Agent
Framework. And as I said, this is a part
of a series of videos on Microsoft Agent
Framework and building agents. So, if
you like this video, please like it. And
if you're not already subscribed, please
subscribe. We have a lot more to talk
about, even with workflows, a lot more
to talk about, and of course with
agents. So, until next time, I'll see
you then.
Workflows bring structure to your AI agents — letting them reason, act, and collaborate step by step. In this video, Kirk walks you through building your first multi-agent workflow using the Microsoft Agent Framework. You’ll learn how to: Turn simple agents into structured, chained workflows Use Pydantic models for structured outputs Connect multiple agents together with Workflow Builder Visualize your workflow using Graphviz Stream and interpret workflow execution events By the end, you’ll have an AI agent system that can take a location, infer the city, get the weather, and recommend places to visit — all automatically. 🔗 Code Repo: https://github.com/kirkmcpherson/microsoft-agent-framework-demo 🔗 Previous Video: https://www.youtube.com/watch?v=LVGZDzD87ok 🔗 Next Video: https://www.youtube.com/watch?v=hwNPYMWLLRE ⏱️ Chapters 00:00 – Intro: From Agents to Workflows 00:28 – Why Workflows Matter in AI Agents 01:31 – Understanding the ReAct Pattern and Black Box Problem 02:29 – Creating Structured Output with Pydantic Models 05:54 – Building Your First Agent Workflow 10:14 – Connecting Multiple Agents (City Info + Tour Recommender) 12:24 – Visualizing Workflows with Graphviz 15:00 – Running the Workflow: Streaming and Results 18:43 – Final Thoughts and Next Steps #AIagents #MicrosoftAgentFramework #Workflows #LangChain #AIengineering #PythonAI #AIAgent #MSTech #SemanticKernel #AutoGen