Back
RCreddit.com
17
·8 hr ago·Dev community · RSS

How to Build Agentic Graphs

View original
Plans & limits

Heat trend

Collecting trend data

The percentage is based on available heat signal, not comment count or independent people.

AI summary

The author shares lessons learned over four months about agentic graph design, aiming to help others avoid common mistakes. Key takeaways include the importance of idempotent nodes, controlled returns, and proper context reuse to build resilient agent graphs. The post also notes that speculative compaction is worthwhile at approximately 88% context usage for regular sessions and around 71% for workflows, according to a slop-chart.

Over the past 4 months of working with graphs, I've learned several major lessons about graph design the hard way. In this post, I want to share the main takeaways so you don't repeat my mistakes.

First, my definition of graphs:

Agent graphs (a.k.a. workflows) are directed graphs that allow cycles and describe how work is passed between agents (nodes) operating in a loop through predefined transitions (edges). Graphs consist of branches, loops, scripts, and transitions (along with their prompts and parameters).

Parallelism is not the silver bullet

At first, I was very enthusiastic about parallel branches in graphs. But over time, I realized that parallelism can not only increase costs but also slow down task execution.

A standard parallel group of checks may include code review, QA, and scope review. The problem begins when these stages are inside a loop.

Let's take a simple example. Suppose code review, QA, and architecture run in parallel, after which the task returns to implementation if necessary.

If the architecture review passes but the code review finds several minor issues, the task returns to the implementation agent. Once the fixes are made, it goes back for review - and the architecture reviewer has to examine the updated diff again, even though the previous version was completely acceptable.

In cyclic graphs, parallel checks often lead to duplicated work, cache invalidation, and unnecessary costs with no real benefit.

In theory, this problem can be solved with a smart router. Kent supports this through script nodes: the router can determine whether the agent completed the entire implementation or only addressed feedback from a specific reviewer (kent.sh is my free, open-source project for building agent graphs. I mention it because I use it myself and don't know of any similar products. You can apply this advice to any comparable orchestrator).

However, this brings us back to the problem we were trying to avoid with agent graphs: the agent once again gets to decide which verification stages need to be run. This negates a significant portion of the graph's value.

In practice, the solution is simpler: dependent checks should run sequentially. In my workflows, architecture review always comes before code review. The task moves on to code review only after the architecture has been approved.

That's why I've removed many parallel stages and now save tokens by avoiding checks on results that would have been rejected at another stage anyway.

This approach works especially well with planning, code review, and QA. For example, code review should first filter out implementation issues, and only then should QA begin. Otherwise, both stages may independently find the same bug and produce duplicate feedback.

Agents must be able to challenge feedback

Initially, absolutism and dictatorship ruled my development agent graph: every reviewer comment had to be addressed, or the task could not proceed. But reviewers don't always produce the right result either.

Now, every agent in my graphs can ask me a question and clarify what to do with conflicting feedback. For example, scope review may reject tests that code review had required just one step earlier because it considered task verification incomplete without them. At the same time, agents cannot be fully trusted to resolve such conflicts on their own. Even with new models like Sol, you can end up in an infinite loop of fixing made up or nitpick problems.

I solve this by delegating the final decision to myself (pure choice, I like to be involved). You can also hand it off to a PM agent or set up communication between multiple agents. For example in Kent agents can get others' session IDs so they can discuss the situation and reach a compromise.

Anthropic in their recent paper argue that this is the model's problem. I disagree - this is the harness's problem, and my system above proves that.

A graph must have a mechanism for escalating conflicting or questionable feedback - otherwise, review turns into a dictatorship capable of trapping the entire workflow in a loop, or a war of stubborness.

Don't forget static checks

Agent graphs sound exciting, and it's easy to want to create dozens of agents and verification stages. This can indeed reduce the primary agent's cognitive load and improve the quality of its work, but static checks should take priority.

Initially, my implementation agent ran the linter, architecture tests, and unit tests itself, opened the PR, and checked incoming comments. I realized at one point that that's just cargo culting, then decided to move these actions into script nodes in the agent graph.

Now, a separate stage:

How to Build Agentic Graphs · BuzzRadr