In this lecture, I'm going to show you
a neat trick you can do with agents
and tools.
So right now, I'm just running an agent.
I haven't showed the code on purpose, and
if I say hello to it, you'll see
it's a rather slow system to talk.
How are you?
So it's thinking a lot, and the reason
for that is that this agent I'm running
right now is running chatgpt 5.2, so
one of the bigger models, and we have
run in the past with a smaller model.
So here's the agent, and we can of
course switch it to run 4.1 nano
again.
Run it.
Say hello to it, and we get a
faster answer.
How are you?
Again, almost instant, but what if we want
that certain things should be just handled by
a small agent, and other things should be
handled by a bigger agent?
For example, that could be that we want
to have it really good at astronomy, like
for example, explain the lights.
Yes, the agent here can talk about what
it is, but it's not as good a
way of doing it as a bigger model
that can really think about some more hard
questions.
So what I have here is I have
an agent that we just run with no
specific instructions or tools or anything, but then
I also have an astronomy agent up here,
which we're not using at the moment, and
that is using chatgpt 5.2, because we
want to be really, really good at astronomy,
and the rest someone else can take care
of.
It could also be that we want to
make an agent that was really good at
your data and had some tools in order
to do that.
But let's step within astronomy for this time,
and say we want to have this main
agent refer all astronomy questions to the astronomy
agent, and then we take the agent itself
and just say, treat it as a tool,
and when we do that, we will end
up being able to say this agent can
answer all the questions, but if it's astronomy
questions, it needs to pass it on to
this bigger agent, which has more capability of
answering.
We add middleware here so we can see
that it's being called, so nothing special there.
So, if we run it like this and
say, hello, it will just answer quickly back,
how are you, will answer quickly back, but
what if we ask, explain northern lights, which
is a astronomy question, it will now pass
the question on to another agent, and you
can see it's actually enhancing the query other
than just what the user, me, answered, and
we can see it takes a longer time
now because now we are actually using a
bigger model to answer this specific question.
So, certain things are easy, certain things are
harder, and hopefully this should be a better
answer because it's a better model at answering
questions.
So, again, just for reference, I know I
was a bit coy about showing the code,
but let's go through it.
We make our connections like normal, and then
we just make two agents.
There's no limits to how many agents you
can have in an AI programme, of course,
the one just being the default agent, and
the other one being an agent that gets
the first agent as a tool.
You could give multiple agents tools, and you
give other tools among these, so it will
just be treated as a tool, and then
we put in the middleware, which we saw
in the lecture about that, so we can
see that it's really actually passing on the
question to the other agent, and then we
have our normal chat loop.
So, using it like this, where we have,
you can almost see this as a kind
of dispatcher that takes care of certain questions,
but you can pass it on to other
agents for certain areas, certain topics, and so
on.
So, that is how you use agents as
tools.