Make Your AI Agents Predictable With Graph Engineering - Zachary Blumenfeld, Neo4j https://www.youtube.com/watch?v=g_NgCLTibiM AI Engineer · 20 min · 198 sentences · sentence-level transcript from YouTube's caption track; each line begins at the time shown [00:01] [music] [00:12] Uh we're going to talk about graph engineering today. [00:14] How many people have heard about that term graph engineering? [00:18] Okay, so so fair amount of the room. [00:19] And then just so I understand, how many people here are familiar with Neo4j and have used Neo4j? [00:26] Okay, so we got a few people. [00:27] So that's good for uh just letting me know who we're talking to today. [00:36] Um so just some history on some of the verbage that's being used. [00:41] Uh there was a tweet that went out by Peter Steinberger, I think earlier this year in the summer, uh that talked about graph engineering and it was almost like is this sort of a new discipline that's happening as this evolution [00:54] from prompt engineering and context engineering. [00:57] Uh and there's a lot of hype around this. [01:00] Um and the name for this is new, but the mechanisms are not really new. [01:04] They we've always known in computer science generally about state machines and workflow graphs and knowledge graphs and all these different things. [01:12] What's changing is really how we think about them in reference to agents. [01:18] Um and what I'm going to talk to you about today is just how we think about graph engineering. [01:23] I'm going to offer you a little bit of a new perspective on this. [01:26] So if we actually try to define what graph engineering is, I think a good definition is it's just the practice of designing agent work as an explicit graph. [01:36] So where nodes do work and edges effectively route state between them. [01:42] And I tend to think of it in terms of three different types of graphs. [01:47] We have our general execution graphs, which you're probably very familiar with. [01:52] So these are the workflow graphs with routers and agents as actual nodes that happen within side of an agent harness. [02:00] But, there's other ways that we can think about graph engineering, too, that overlap with this. [02:05] So, that includes context graphs. [02:07] These are decision traces, instances of what's happened, and how it connects to other data inside of your domain. [02:15] And then there's also something that I'd call more procedural graphs. [02:19] So, this is almost like having a skill or procedural knowledge as a graph, where the steps might not be actual agents, but they might be steps inside of uh uh a way of doing something, basically a procedure. [02:32] So, different calls, maybe a step for a decision model, steps for different agents, whether to escalate, validation steps, and these sorts of things. [02:42] And I'm really going to focus on these last two, because I think we don't talk about them enough, and I think by understanding these, you can actually get a little bit at what the first graph is trying to do as well, but in a very portable and efficient way. [02:57] So, graph engineering lets agents really take on bigger, more complex work, and that's why we care about it. [03:04] And really, if you were to split it up, I think in terms of the benefits that a graph offers agents in this uh context, it would be predictability so being able to constrain a path that an agent takes, [03:16] making sure that the the answer is basically accurate from a task that it's doing um and having an explicit graph, the ability to govern, control, and guide what the agent does, and audit it, so you can understand what it's doing and make it better next time. [03:32] And then the third one, which is going to be interesting that we'll talk about, is how do we actually make graph engineering portable? [03:38] And instead of thinking about a graph as something that happens in the runtime, it could be something that you can store and actually move between different runtimes and have inside of a knowledge layer, [03:49] which gives you more interoperability and allows you to have a very simple stack. [03:54] Um and in the runtime, when we think about the graph, it's really like a piece of orchestration. [03:58] So, we're probably all of us or a large portion of us are probably familiar with LangGraph, ADK, um and all these other agent frameworks. [04:08] Um even to a certain extent Anthropic's multi-agent research and and some other stuff fits inside of graph engineering. [04:14] Um and what I'm going to talk about today is actually what happens when we take that sort of graph and we put it next to our data as context graphs and some other things that I was talking about before. [04:26] Um and really when you do this, as I was saying, you add this portability layer, you add the ability to take all of this knowledge and make it work [04:36] basically with any type of runtime. [04:39] So, that's what I'm going to go over today. [04:41] Um and this is what we're doing at Neo4j is we're defining this knowledge layer and this knowledge layer sits between systems of record that you would ordinarily retrieve data from. [04:52] So, Data Bricks, BigQuery, Snowflake, these types of places. [04:55] It could be documentation, it could be Obsidian, these these markdown files. [05:00] Um and then can we create standard protocols and artifacts that live inside of that layer that then you can take a graph engineering process and make it available to any runtime or any agent. [05:14] Um and the way our product works, just so you know at Neo4j, uh is we have our core database and then we have a ton of other AI stuff on top of it. [05:24] Uh so, the database and the analytics layer, um I'm going to be showing some of this throughout my talk, uh but what I'm really going to be focusing on is this top layer where we talk about sort of this agentic brain or these other memory tools [05:38] that wrap around the database. [05:40] So, just know that as I go through, I'm going to be showing you data being loaded into the database. [05:44] That's going to constitute our knowledge layer. [05:46] It's going to come from multiple different sources. [05:49] Um but a lot of the sort of extensions of that tooling and some of the experimental things that I'm going to show you exist as sort of this graph AI that hooks into that and loads data in and out of that thing. [06:00] [snorts] [06:01] Um, so, what we're doing at Neo4j, and kind of how we're thinking about this: we start with this concept of a context graph, which has different types of memory [06:12] from short-term memory which is going to be like your conversation history your long-term memory, being entities that are extracted from that or from your data, and then reasoning or decision trees inside of that. [06:25] And one of the interesting things that we've been looking at from a research perspective, and this really started out not so much at that graph, but actually at individual skill level. [06:35] There was a paper that we wrote earlier this year that we published in a workshop, and we were really trying to ask the question, can we take procedural knowledge, [06:45] whether it be from past decisions or even something like a skill like we have here, and compile it down to a graph? [06:53] And what we came up with was a process of taking written material, often a skill MD file, and the scripts and the references and assets, and moving that into an actual graph structure, which is what you see on that other side. [07:07] And the result of doing this and giving the agent the access to that graph structure, which has different nodes again representing inside of the skill decisions, different routing points, different scripts that have to be executed, [07:22] taking pros and compiling them down to to determine the six scripts. [07:26] When we do that and we force the agent to sort of run that graph, what we see is increases in uh task reward and performance. [07:34] So, this was uh from a while ago. [07:37] I I'm still [clears throat] working on updating it to the latest models, um but we were able to use a smaller model. [07:43] In this case, I think it was Sonnet, um, and now we're we're on to Haiku, as a matter of fact. [07:49] But, uh, we were seeing, even for really challenging tasks over diverse fields in physics and computer science and, um, various security, uh, physical training, a whole a whole ton of things, [08:02] um, is this overall increase in task reward, um, performance. [08:08] Then we were able to switch over to this. [08:10] And our PMs, uh, Will Lein, who works in our Labs team, actually took this idea and said, "Well, if we can do that with skills, maybe we can do it, too, with these memory graphs." [08:21] So, you can actually take that context graph that I was showing you earlier and distill a skill from that and have it still be connected in the same graph [08:32] over to all of your past decision traces and data. [08:35] And so, then you get those performance benefits, but you also have all this provenance that goes back from every step. [08:41] It's versioned, it's tracked, and you have governance over time where you can assess drift, you can understand where certain tool calls are coming from and their history. [08:50] A human can go through actually inside of NAMS, Neo4j Agent Memory Service, which is our reference architecture for this. [08:56] There's a QR code there, and there will be another one at the end, um, and be able to understand, like, exactly how this works, edit it, change it, do all sorts of cool stuff with it. [09:08] Um, so again, what we're talking about now are these artifacts that you can move around. [09:12] I mean, this thing makes a skill, right? [09:14] And so, any agent harness that can take that skill can now be running these graphs and doing all of this logic. [09:21] Um, and we have various customers that are using us for graph engineering types of tasks. [09:29] I'll go quickly because we're we're starting to run out of time. [09:33] Um, and even though they're not may not be using exactly the Labs project that they that we have, uh, we have consultancies which are working with other asset managers, [09:42] uh, for tough problems in compliance. [09:45] Uh, so being able to write audit reports, for example, where you have data that might come from multiple sources. [09:51] How do you automate that, but do it in a way that's governed and trustworthy? [09:54] So, you have compliance documentation. [09:57] You might have entities with different ticker symbols and names from different databases, and those all need to be resolved. [10:03] And so, giving your agent these graphs that express the logic that you need to do on besides the data basically allows you to automate those things in a trustworthy way. [10:13] Um and we have other people uh such as Uber that do this with configuration graphs. [10:18] Uh, so basically, if you have, um, you can imagine if you have drivers across the country, uh, compliance and regulations for different areas geographically vary greatly, um, and they come from this sprawl of microservices [10:31] that you need to pull data from to figure out like, "Okay, well, what is it for each area, for each component of a car, for example?" [10:38] Um and so being able to express that logic and have it sit aside the data um also helps them operationalize some of these things effectively. [10:47] So, I'm going to jump to a demo now. [10:50] It I'm going to warn you in advance: it's going to be quite a lot, and I'm going to jump through it kind of quickly, um, but it's very interesting. [10:56] And what I'm going to show you is how we can use that AIP library that I was talking about before, uh, to compile a skill and actually get a task that was not governed very well and took [11:08] very long to run, basically cut its cost by like 100% and then run it a lot, lot faster. [11:14] Um and of course, it's uh it's a demo, it's not a formal research proposal, but you can go there and look at the code. [11:19] It's all It's all very transparent. [11:22] Uh so, this is going to be an example for a loan um a loan approval process. [11:29] So, in a side of a loan approval process, there's lots of policies that have to be followed, obviously. [11:35] I'm not a financial expert, but many of you in the room are. [11:38] Um and so there's probably going to be a policy doc. [11:41] There's going to be a systems of steps that have to be followed exactly, and then you need your agent to be able to explain those steps very clearly, articulate them, and really get the answer right as if it was a human reviewing. [11:53] Um and the first thing you can do, like I was saying before, and I don't have time to probably run this all live, and the internet's going to be slow. [12:00] So, luckily I I have this preloaded. [12:03] Um and basically, the question that was asked was should we approve this new loan for this Rosa's Bakery business? [12:09] And in this case, you know, we have a business plan that's in a PDF that was uploaded. [12:16] Um and that is, let's see, um the business plan is the orange data. [12:22] So, if I was to scroll out here, you can see it here in the graph. [12:26] That connects also to data that we pulled from Data Bricks, from past transactions, lending policy data, and past decisions that were actually made. [12:36] And with that, the agent can crawl over all that information and basically realize that this person either had a loan before or there was a mistake before, something happened before, [12:47] and come up with an audit trail for that and basically post a solution uh very, very quickly. [12:53] [snorts] [12:53] Um and this is a great start. [12:55] Just in terms of like resolving data and being able to follow policies and understand how things connect, uh this is great. [13:02] One of the issues with this is, and I can show you a graph kind of of what this looks like. [13:07] This is an example of me running more of these policies. [13:11] Um and if I zoom in, I have a conversation here. [13:16] And then I have my my reasoning trace that exists inside of this graph. [13:19] And all of these steps are time-stamped and they have tool calls. [13:23] Uh what can happen is if I uh look at this happening twice. [13:30] I think this is the right query. [13:32] Um this is this is two decision chains. [13:35] It's going to be a little bit hard to see. [13:36] Let me zoom in. [13:38] Um they they're of different lengths, you'll notice. [13:41] So, one is longer than the other. [13:43] Um in this case, it was cuz it found a precedent in one. [13:47] Um basically, something else that had happened before. [13:50] But the the problem with this is that if you run these over and over again, there's nothing actually like enforcing that the agent follows an exact path. [13:58] You might have a skill or something that will say like do these things. [14:02] Uh but then there's other problems where it's like there's these decision steps where it's approve or deny is a simple one, or approve it or send to a human to review. [14:10] And those decision steps as well come with confidence scores. [14:14] Uh or you say like if you're confident about it, if you're not confident about something, but those decisions aren't calibrated. [14:21] So, it would be great to like even take some of this and send it to something like a type safe, you know, Jev type of model as well to be able to do some of those things. [14:30] So, what you can do is you can scrape all of this and you can compile it into a graph shape skill, which is what we did here. [14:37] And that graph shape skill, if I go here, you're not going to be able to see it. [14:41] But that's okay that you don't see a lot of the detail here. [14:45] The important part is that we sort of compiled all the information down from those successful runs that we did, even though they were a little bit inconsistent, and we put them into this graph YAML shape [14:56] inside of this skill. [14:58] And this skill, even though you probably have trouble seeing, has scripts, it has assets here, it has sometimes other reference resources. [15:07] It doesn't for this one. [15:09] It also has source documentation around the policy that you're supposed to do for the loan. [15:15] So, there's So, there's basically a ton of stuff in here for traceability, but then also telling the agent how to run the skill. [15:21] But the great thing is once the skill is in this YAML format, we can port it into all this different tooling, including inside of a graph, cuz it's all sort of this deterministic [15:30] format. [15:32] And in a graph, it looks kind of like this thing here. [15:36] So, let me Actually, let me just run this run this sucker again. [15:40] Um This is kind of what it looks like. [15:44] So, you have all of these steps out here, and then basically what I just did is I wrapped the small cli around this, so the agent can say, "Hey, run the skill." [15:54] And instead of the agent deciding all the routing steps, it's just done programmatically. [15:59] We took a lot of that policy down, and we put a lot of it into these execution scripts. [16:05] Basically, what's happening here, if if I was just to sum it up, there's an execution that basically looks at, "Hey, do do we meet certain hard rules around policies?" [16:16] After that, it's routed if it's not auto approved or denied based on that, it's routed to a decision model like Javelin type safe. [16:25] Um, and I can even probably show you a little bit of a clearer view here. [16:31] Um, and it's given that that model is given like a risk tier choice. [16:36] Um, let me make that a little bigger. [16:38] Hold on. [16:41] Um, whether or not there's there's some exposure material and then like an outcome of whether or not you're approving or denying. [16:49] And then the rest of this um, will basically follow down into writing a report, whether or not you need to escalate to a human review as this router. [16:57] And then if not, basically the agent is going to write a report and there's a circulation here to sort of check and lint that report. [17:04] Um, so once you do this and you sort of get the model going where okay, well now we have this cli that we can just run this thing in. [17:12] Um, well now I can go in here and then maybe I can probably don't have time to run this whole thing again, but I will give it a shot. [17:22] Um, I'll see if it goes and picks this up. [17:26] It takes about 2 minutes to run. [17:28] Uh, but the idea I guess while this is running and it should pick up the AIP scale which which it is here. [17:35] Um, once you have it in this format, not only can you have the agent run this very quickly. [17:42] Uh, you can track the runs. [17:43] So for example, um, if I was to look at a single run, I can run this again. [17:51] I can basically persist the runs inside of the graph. [17:55] Um, so this is a run of that scale with like individual steps that it ran. [18:00] Um, and then uh, I can just persist these over time. [18:03] I can examine how well they work. [18:05] So from a governance perspective, um, I have a little inspector here that I built really quickly. [18:10] You can look at the status of all these. [18:12] You can look at how a specific one ran, what was approved, what was denied inside of the process, what branches it took. [18:20] Um, and then once you have a graph, you can even do these cool observability things where you can ask, well, like what branches were taken and which branches weren't taken. [18:29] Um, which is very interesting from a governance perspective it failed ever [snorts]. [18:33] Um, all these cool different things, and all of that is stored besides your data. [18:38] Um, and so in none of this, we're not like creating a loop, right, inside of our agent. [18:43] All we're doing here is basically giving it a cli to run this like programmatic skill that we compiled from documentation or in this case from our memory graph. [18:53] Um, and this might take a while to run just because of the the internet. [18:59] But what I will show you is I we ran this a few times. [19:04] Um, and what we saw is just running I was using Fable so my organization already yells at me for this enough so I'm spending a bunch of money. [19:12] Um, but like just using Fable alone on the graph and it was correct you know, pretty much every time but it took 2.7 minutes. [19:20] When we had the procedure it almost cut in half just using AIP and then because we had the procedure we can use a simpler model like Haiku and then we can cut the model time down even more and then of course, [19:31] you know, the cost just goes way down. [19:33] So, cuz you're taking all of that load, right, of having to figure out all the routing, all the stuff you're doing, you're putting into these execution scripts, these Java models and everything, [19:42] um which makes everything just much, much more efficient. [19:46] Um, and this is going to take too long to run. [19:49] Uh, it's mostly internet. [19:52] You can see here about half a minute or 2 minutes wall clock on average down from like 7 and 1/2. [19:58] All right, so anyway, um, I'll end it here. [20:01] So I want to give you some resources to check out if you're interested in this type of stuff. [20:06] Aura is our cloud service offering where you can get the database that I was showing you before. [20:11] You get $100 of free credits. [20:13] We have nodes coming up which are is speakers event. [20:16] There's a startup program and then all the code that I was referencing in the other projects that I was using to hook up to your agent memory, all that sort of stuff is down there. [20:25] So, I'll leave this up for a second until someone kicks me off, and I guess that's it for me for now.