---
title: "AI Agent Debugger"
video_id: 2RC13FFo1rQ
url: https://www.youtube.com/watch?v=2RC13FFo1rQ
workflow_page: https://workflows-of-ai.com/workflow/ai-agent-debugger
language: en
captions: generated
---

0:00 Today's video is sponsored by FR Give.
0:02 If you need help with Drupal NAI, don't
0:04 hesitate to get in contact with us.
0:08 So before we dive in, I want to quickly
0:10 set the stage for what this is you're
0:12 looking at. So this is the new AI agents
0:15 debugger and the goal here is simple,
0:17 full visibility into what your agents
0:20 are actually doing. So what you can see
0:23 here is I asked the in this case the
0:26 Drupal CMSS system but it could be any
0:28 agent a question and then you can
0:31 actually see all the inputs and outputs
0:34 for a run. You can get detailed
0:36 information about how a sub agent
0:39 request is starting what is added into a
0:42 AI input including things like token
0:45 replacements the provider that is being
0:48 used and so on. You can also export and
0:51 import runs. So debugging isn't locked
0:53 to a single environment or this specific
0:57 debugger.
0:58 Uh you can view the entire chat
1:01 discussion that's happening from the
1:02 user to the assistant but also from the
1:05 assistant to different agents. So you
1:08 can see how the agents are talking to
1:10 each other.
1:12 Uh you can also have a simpler graph
1:15 view of what's happening in each loop.
1:18 Um, and this part I think is especially
1:21 uh powerful. You can actually discuss a
1:25 run with an agent itself and ask this
1:29 agent that is looking at this run to
1:32 change the agent that you're talking
1:34 about. So you can actually start
1:36 chatting with it.
1:39 Uh so yeah, with this in mind, let's
1:41 jump into why this needed to exist and
1:44 how it fits into the whole AI agents
1:46 ecosystem.
1:48 So yeah, hey everyone and welcome. Um so
1:51 today I want to show you something that
1:52 I been wanting to build for a long time,
1:54 the AI agents debugger. I was in uh
1:58 Brussels last week for the Drupal AI
2:02 hackathon
2:04 and because the Drupal I was there as
2:06 technical support and because the Drupal
2:08 AI module seems to be fairly stable, I
2:10 didn't really have that much to do. So
2:12 finally I had some time to basically
2:15 focus on one thing and one thing only.
2:18 So what I did then was to do this, the
2:21 AI agents debugger. So if you ever
2:24 worked with AI agents in Drupal, you
2:25 probably know that the debugging of
2:27 agents has always been less than ideal
2:31 because we had the AI agents explorer
2:33 module for a while and that's inside AI
2:36 agents and that work great for the all
2:38 the workflow based coded agents but once
2:40 we have introduced like the react agents
2:43 that we have since AI agents 1.1 the
2:45 config ones that you can set up inside
2:48 the guey
2:50 this was just not built for it. So we
2:52 needed something that is purposely built
2:55 for it.
2:57 Um so you know instead of trying to keep
2:59 stretching the explorer further and
3:01 further I decided to do this. So this is
3:03 a module that exists in beta already. Uh
3:07 you can install it like any other
3:09 module. Uh there are still some things
3:13 that needs to go in in terms of a road
3:17 map. So the most important thing I want
3:19 to do is the step through function. So
3:21 it actually works similar to how Xdebug
3:24 works for instance because the agents
3:28 themselves they are serializable un
3:30 serializable which means that you can
3:32 store them in a state that they have
3:34 after one loop which means that you
3:36 could you know step through the loops of
3:39 the agent but also go back maybe change
3:43 some tool output or maybe change the
3:45 system prompt to see if the that loop
3:48 can become better depending on how you
3:50 change it.
3:53 Um,
3:55 so let's go through how to get started,
3:58 installed, and everything it can do.
4:02 Just a side note here, there's a
4:04 disclosure. Uh, I think there should
4:06 always be a disclosures until the coding
4:09 agents becomes defacto standard. But I
4:12 will be very clear with the only reason
4:15 that I could do this in half a day this
4:17 module uh was because of AI. And I would
4:23 say since the end of December or
4:27 sometime around December something
4:28 happened both with Claude Code Codeex um
4:35 they just became so much better
4:38 and um yeah the hype is becoming reality
4:43 let's say like this you should look into
4:45 it if you haven't seen it but this is
4:46 also a disclosure so you know uh that a
4:51 lot of this code was actually uh
4:54 generated.
4:56 So how you get started? You just install
4:59 this module. Um I would recommend you to
5:02 uninstall the uh AI agents explorer and
5:06 use this instead. Then it's the same as
5:09 always. You go to AI agent under AI,
5:12 take one of the agents. So we're going
5:14 to take the CMS assistant. And now
5:16 there's a debug button. So if you have
5:18 both, you actually see debug and
5:20 explore.
5:22 Um, and this will open the debugger
5:25 and then it is working similar to the
5:29 explorer. So, this is one of the uh
5:31 to-dos that in Drupal AI well 2.0 but
5:36 probably 1.3.0
5:38 we have a form element that can actually
5:40 show chat history. So, you should be
5:42 able to put in whole history here. So,
5:44 it can replicate what you're doing with
5:46 the assistant where you might talk back
5:48 and forth and back and forth. Um, but
5:51 anyway, you know, you just choose the
5:53 agent and the prompt. That's the easiest
5:55 mode. Click run the agent and then
5:57 you're going to start seeing the steps.
6:01 Um, and
6:04 what's important here is it's it's
6:06 showing each of the step structured and
6:09 you can also see very clearly when it
6:12 goes into sub agents. You can also see
6:15 all the timings.
6:17 So almost right away we did a AI
6:20 uh uh question where it basically asked
6:24 what I asked here, right? You have the
6:26 system prompt here and you can see then
6:30 in the AI output
6:33 what
6:35 uh decisions it took. So it actually
6:37 answered with a text and took the uh
6:40 said that the content type agent try
6:42 age. So that's a sub agent, right? It
6:44 told this prompt check if there's a
6:46 content type called page and if it has
6:48 an image field. Then it goes into the
6:51 sub aent that starts running and you can
6:53 see the first loop here. So this is the
6:55 sub aent that is then the content type
6:57 agent.
6:59 Uh and you can see that this then takes
7:03 a decision to use the tool get content
7:06 type info to get more information about
7:09 this content type. Then there's a second
7:12 loop or you can also see it's using this
7:15 tool content get content type info and
7:18 this is the output from this tool. So
7:20 this is what's being fed back to the
7:22 second loop. So it actually makes it
7:25 very easy to follow along what's
7:28 happening and then based on having that
7:31 in the history
7:34 uh you can see
7:37 uh here you can see that it has the two
7:39 results. So now there's a chat history
7:41 here because it's the second loop system
7:44 prompt
7:46 and then an output where it writes back
7:50 to the
7:52 uh writes back to the orchestration
7:55 agent but then the orchestration agent
7:57 is on its second loop where it has to
8:00 figure out that okay I also have to ask
8:03 the field agent list the fields for this
8:06 basic page and now it knows that the
8:08 machine name is page.
8:10 because it got that information from
8:11 content type agent. And then if we just
8:14 skip forward here, you can see that the
8:17 it's uh using the get entity field
8:20 information for node page. And this is
8:23 then if we clicking on this tool, it
8:25 gives back all the fields available.
8:28 Which means that it can see that there
8:30 is this field feature image that is I
8:33 entered the reference of media of target
8:36 bundle type image and from that it can
8:38 understand then in its output that it
8:41 will say
8:43 uh here are all the content types
8:47 and then it's going to base on this
8:50 figure out then that there is the field
8:52 feature image with the media entity of
8:54 type image.
8:57 Now one thing you saw directly here that
9:00 you can maybe improve
9:02 is what's going in here
9:06 uh
9:08 or no actually this was good. It's
9:10 actually asking field type image. I'm
9:13 not sure why it's an uh returning
9:16 everything there. Yeah, here it's
9:18 answering. So this is a thing we could
9:20 actually improve because this is
9:21 creating a lot of tokens and the only
9:24 thing the user in the end was interested
9:26 in is this answer here. They're not
9:29 interested in all this. Uh so what we
9:34 can do then is that there is this AI
9:36 agent handler agent. It's a little bit
9:39 meta but what this is it installs a
9:42 agent that can create agents for you and
9:45 it actually works quite well. I've tried
9:47 it on creating a lot of different
9:49 agents. As long as the tools are there,
9:51 it's very good at it. But if you install
9:54 that, this button shows up and there it
9:57 actually feeds the whole run into this
9:59 agent. So you can start asking questions
10:02 like uh the field agent
10:06 answered
10:08 with a very long
10:11 uh uh response.
10:15 That was too verbose. What should I
10:19 change in the system
10:23 prompt of that agent to make it more
10:28 concise
10:31 to save tokens. So we can actually ask
10:34 stuff like this because it is a agent
10:36 that actually has the uh uh possibility
10:39 to change stuff. You can actually go
10:42 ahead and ask it to change this as well.
10:44 and try to rerun it then.
10:47 Um,
10:51 so you can see here basically what it
10:53 wants to do and it has all the
10:56 information about that specific agent.
10:59 So it's not just giving back some
11:01 generic thing here. It's basing it in
11:03 this case on the field agent then. So
11:06 what can you also do here? Well, you can
11:10 see the actual
11:13 uh each of the loops and you can see
11:15 that in this loops it goes into another
11:18 agent here that also has a loop one.
11:21 Then you can see the uh tools it's using
11:25 when it's ending the second loop and
11:27 then it's getting a final answer. You
11:30 can click on this mode where you can see
11:32 exactly what is being said. So the user
11:35 is telling the Drupal CMS assistant, can
11:38 you tell me if there's a content type
11:40 page and uh it has some image field on
11:42 it. First thing the Drupal CMS assistant
11:45 is doing is contacting the content type
11:47 agent
11:49 that's asking this and answering this.
11:53 Second step when this comes back is that
11:55 it calls the field agent with this and
11:59 returns this. Right? So it's a it's a
12:02 easy way to see how the conversation is
12:05 flowing.
12:07 Uh there are some other cool things as
12:10 well. So as you might or might not know
12:15 a agent can take tokens Drupal tokens
12:18 but when you're testing those tokens
12:20 might not be available right. So you can
12:22 actually spoof tokens here by you know
12:25 adding the token name and uh the value
12:29 and that way you can test it with some
12:32 uh uh madeup token values.
12:34 What you can also do is when this has
12:37 run you can click export and it exports
12:40 this and then you can import it. I'm
12:42 going to import a lot longer
12:45 conversation here where you can see in
12:47 the prompt wait let's close here that
12:50 I'm telling it you know can you create a
12:53 content type that's called travel blogs
12:55 also create a taxonomy field that should
12:57 have the taxonomy travel places on it
12:59 could you add the 20 most interesting
13:01 places to visit in the world on it and
13:04 then we want to add those as field to
13:06 the content type so if you look in this
13:08 view you're going to see for instance
13:09 it's creating a lot of taxonomic terms
13:12 here, right? Uh here is probably
13:14 something we could improve by doing a
13:17 bulk tool or the option to add uh bulk
13:21 tools. Uh but yeah, you get all the
13:24 information out here. Uh
13:29 this view you have to zoom of course to
13:32 be able to see what actually happens
13:33 because it's using the taxonomy term. It
13:36 might be that we should put a number
13:38 there. But the thing is each of these
13:40 calls has different parameters and
13:42 that's probably good to know.
13:45 And then you can see here how the
13:48 conversation is flowing uh sequentially.
13:53 Uh and the idea behind the export and
13:57 import function is that uh this should
14:01 also be able to hook into other things.
14:04 So with the chatbot assistant that we
14:06 have, you can actually hook in and add
14:08 buttons that knows
14:12 uh what has happened so far. So this
14:15 means that we could create a button that
14:17 is export the session and then you can
14:19 open it here to see exactly what
14:21 happened. Uh we should of course build
14:24 it into
14:25 uh the logging system. So you can choose
14:28 to log certain agents, maybe even
14:31 production, export them and see them
14:33 here.
14:34 Um
14:36 yeah so that's the reasoning behind it.
14:38 I will just go through also the rest of
14:42 the road map that is important.
14:47 Yeah you have the chatbot expert chat
14:49 history and step through I talked about
14:51 this. The last thing that should be
14:53 added before it's production is spoof
14:55 tool output. So one of the things we see
14:59 that basically is a a make or break for
15:03 an agent
15:05 is how the tool output looks like. So
15:09 the idea is if we take some tool here
15:13 you can see that uh in this case it
15:17 added the great wall of China.
15:20 This is probably a okayish output
15:24 uh because it tells it successfully what
15:27 it's doing. Uh
15:30 we can see if we can find something
15:32 else. Maybe this one is too long for
15:34 instance. Maybe we have to make that
15:35 concise. But we don't want to go in and
15:37 program and see if that makes a
15:39 difference. So the idea is here that you
15:41 should be able to modify the output of
15:43 that tool just for this debug session.
15:47 uh go back using the debugger and run it
15:49 again.
15:51 There is one thing that I didn't show on
15:53 the road map there as well. Uh and
15:56 that's the idea that you should be able
15:58 to manipulate um the agents that's being
16:02 used but not actually save them. So you
16:06 should be able to try over and over
16:08 until you feel okay this is better now I
16:10 actually persist this in the age.
16:13 Um
16:15 yeah that is it. H one thing I can show
16:17 also of course if you open one of these
16:20 things
16:21 there is next and previous that you can
16:24 use. So you can follow that way as well
16:26 and you can use right and left button as
16:29 well uh on your keyboard
16:32 just to see everything there. Um
16:36 so that is it. It's still in beta.
16:38 Please test it. I I'm 99% sure that I
16:42 have all the inputs and outputs there.
16:45 If you feel something is missing that
16:47 should be there, just you know create
16:49 some um create some issue in the issue
16:52 queue. Um as always, if you're
16:57 uh willing to maintain
17:00 uh please reach out to me. We always
17:02 need maintainers for different modules.
17:05 Um thank you for watching.
