10 ms·
LLM Agents Are Simply Graph – Tutorial for Dummies
- zh2408 2y agoHey folks! I just posted a quick tutorial explaining how LLM agents (like OpenAI Agents, Pydantic AI, Manus AI, AutoGPT or PerplexityAI) are basically small graphs with loops and branches. For example: OpenAI Agents: for the workflow logic: https://github.com/openai/openai-agents-python/blob/48ff99bb736249e99251eb2c7ecf00237488c17a/src/agents/run.py#L119 https://github.com/openai/openai-agents-python/blob/48ff99bb... Pydantic Agents: organizes steps in a graph: https://github.com/pydantic/pydantic-ai/blob/4c0f384a0626299382c22a8e3372638885e18286/pydantic_ai_slim/pydantic_ai/_agent_graph.py#L779 https://github.com/pydantic/pydantic-ai/blob/4c0f384a0626299... Langchain: demonstrates the loop structure: https://github.com/langchain-ai/langchain/blob/4d1d726e61ed58b39278903262d19bbe9f010772/libs/langchain/langchain/agents/agent_iterator.py#L174 https://github.com/langchain-ai/langchain/blob/4d1d726e61ed5... If all the hype has been confusing, this guide shows how they actually work under the hood, with simple examples. Check it out! https://zacharyhuang.substack.com/p/llm-agent-internal-as-a-graph-tutorial https://zacharyhuang.substack.com/p/llm-agent-internal-as-a-...
- czbond 2y agoThank you - really interesting looking read, thanks for crafting the deep explanation, with links to actual internal code examples. Also, thanks for not putting it behind the Medium paywall
- zh2408 2y agoThank you!!
- pseudopersonal 2y agoThanks for this write up. It'll be inspiring my ruby framework.
- zh2408 2y agoThank you!
- godelski 2y agoMinor comment: do you mean "LLM Agents Are Simply Graphs". Personally, I'd drop the adjective to "LLM Agents are Graphs" as I think it sounds better, but the plural is needed.
- bambax 2y agoThis explanation and demo is super clear. It would be interesting to dig deeper into the "thinking" part: how does an LLM know what it doesn't know / how to fight hallucinations in this context?
- erichi 2y agoI like the minimalistic approach! How to test such agents?
- mentalgear 2y agoEverything that was previously just called automation or pipeline processing on-top of LLM is now the buzzword "agents". The hype bubble needs constant feeding to keep from imploding.
- zh2408 2y agoThank you! I'm not against such hype TBH :)
- deleted 2y ago[deleted]
- campbel 2y agoI follow Mr. Huang, read/watch his content and also plan to use PocketFlow in some cases. A preamble, because I don't agree with this assessment. I think agents as nodes in a DAG workflow is _an_ implementation of an agentic system, but is not the systems I most often interact with (e.g. Cursor, Claude + MCP). Agentic systems can be simply the LLM + prompting + tools[1]. LLMs are more than capable (especially chain-of thought models) to breakdown problems into steps, analyze necessary tools to use and then executing the steps in sequence. All of this is done with the model in the driver seat. I think the system described in the post need a different name. It's a traditional workflow system with an agent operating on individual tasks. Its more rigid in that the workflow is setup ahead of time. Typical agentic systems are largely undefined or defined via prompting. For some use cases this rigidity is a feature. [1 https://docs.anthropic.com/en/docs/build-with-claude/tool-use/overview https://docs.anthropic.com/en/docs/build-with-claude/tool-us...
- zh2408 2y agoLet me clarify: this tutorial focuses on the technical internal implementation of the agent (e.g., OpenAI agent, Pydantic AI, etc.), rather than the UI/UX of the agent-based products that end users interact with.
- campbel 2y agoThat's what I am talking about as well. The low-level implementation of an agent isn't necessarily a rigid graph, and I'd actually argue its explicitly not this.
- zh2408 2y agoThe current implementations of Agents, e.g., OpenAI agents released last week, are based on graph (workflow): https://github.com/openai/openai-agents-python/blob/48ff99bb736249e99251eb2c7ecf00237488c17a/src/agents/run.py#L119 https://github.com/openai/openai-agents-python/blob/48ff99bb... Not sure about Cursor you mentioned as its agent is not open sourced.
- _pdp_ 2y agoIt is hard to put a pin on this one because there are so many thing wrong with this definition. There are agent frameworks that are not rebranded workflow tools too. I don't think this article helps explain anything except putting the intended audience in the same box of mind we were stuck since the invention of programming - i.e. it does not help. Forget about boxes and deterministic control and start thinking of error tolerance and recovery. That is what agents are all about.
- zh2408 2y agoHey, sorry for the confusion. This tutorial is focusing on the low-level internals of how agents are implemented—much like how intelligent large language models still boil down to matrix multiplications at their core.
- adamnemecek 2y agoDespite the memes, this reductivism is not exactly insightful. Like why stop there? Matrix multiplication is just a bunch of dot product. Which in turn is just cos and magnitude. What insights were generated from this?
- ethanwillis 2y agoThe reductionism is insightful when it comes to providing an implementation with those specific details in mind. In the case of LLMs knowing it does boil down to matrix multiplication is insightful and useful because now you know what kind of hardware is best suited to executing a model. What is actually not insightful or useful is believing LLMs are AGI or conscious.
- ForTheKidz 2y agoBelief is generally not insightful or useful by definition. Then again, I don't think anyone who can follow this article believed that LLMs were conscious to begin with, so I'm not sure what your point is. You're preaching on behalf of a demographic that won't read this article to begin with, and presumably the people who are can see how useless, distracting, and unproductive this reductionism is.
- miguelinho 2y agoGreat write up! In my opinion, your description likely accurately models what AI agents are doing. Perhaps the graph could be static or dynamic. Either way - it makes sense! Also, thank you for removing the hype!
- zh2408 2y agoThank you!
- jumploops 2y agoAnthropic[0] and Google[1] are both pushing for a clear definition of an “agent” vs. an “agentic workflow” tl;dr from Anthropic: > Workflows are systems where LLMs and tools are orchestrated through predefined code paths. > Agents, on the other hand, are systems where LLMs dynamically direct their own processes and tool usage, maintaining control over how they accomplish tasks. Most “agents” today fall into the workflow category. The foundation model makers are pushing their new models to be better at the second, “pure” agent, approach. In practice, I’m not sure how effective the “pure” approach will work for most LLM-assisted tasks. I liken it to a fresh intern who shows up with amnesia every day. Even if you tell them what they did yesterday, they’re still liable to take a different path for today’s work. My hunch is that we’ll see an evolution of this terminology, and agents of the future will still have some “guiderails” (note: not necessarily _guard_rails), that makes their behavior more predictable over long horizons. [0]https://www.anthropic.com/engineering/building-effective-agents https://www.anthropic.com/engineering/building-effective-age... [1]https://www.youtube.com/watch?v=Qd6anWv0mv0 https://www.youtube.com/watch?v=Qd6anWv0mv0
- zh2408 2y agoLet me clarify: we are discussing how the Agent is internally implemented, given LLM calls and tools. It can be built using a graph, where one node makes decisions that branch out to tools and can loop back. The workflow can vary. For example, it can involve multiple LLM calls chained together without branching or looping. It can also be built using a graph. I know the terms "graph" and "workflow" can be a bit confusing. It’s like we have a low-level 'cache' at the CPU level and then a high-level 'cache' in software.
- jumploops 2y agoYes, the difference is that in the “pure” agent approach, the model is the only thing directing what to do. In a sense there’s still a graph of execution, but the graph isn’t known until the “agent” runs and decides what tools to use, in what order, and for how long. There is no scaffold, just LLM + MCP (or w/e) in a loop.
- bckr 2y agoAnyone succeeding with agents in production? Other than cursor :)
- DrFalkyn 2y agoI think the model he is looking for is a deterministic finite automata (DFA)
- nxpnsv 2y agoI found it understandable and clear. Pocket flow looks cool, although that magic with - >> operators seems a bit obtuse... Also, I think "simply" is a trap - an agent might be modeled by a graph, but that graph can be arbitrarily complex.
- v3ss0n 2y agoMy experience is Mistral Small, QwQ and QwenCoder can build much better diagrams in Mermaid compared to those attempt by Mr haung
- admiralrohan 2y agoStrangely the original HN post on the framework got no comments but this one is getting viral! Good luck.
- DebtDeflation 2y agoThere are two competing definitions of agents being used in industry. https://www.anthropic.com/engineering/building-effective-agents https://www.anthropic.com/engineering/building-effective-age... "- Workflows are systems where LLMs and tools are orchestrated through predefined code paths. - Agents, on the other hand, are systems where LLMs dynamically direct their own processes and tool usage, maintaining control over how they accomplish tasks." What Anthropic calls a "workflow" in the above definition is what most of the big enterprise software companies (Salesforce, ServiceNow, Workday, SAP, etc.) are building and calling AI Agents. What Anthropic calls an "agent" in the above definition is what AI Researchers mean by the term. It's also something that mainly exists in their labs. Real world examples are fairly primitive right now, mainly stuff like Deep Research. That will change over time, but right now the hype far exceeds the reality.
- kodablah 2y agoI think Anthropic's definition of workflows is inaccurate for modern definitions of the term. Temporal for instance (disclaimer, my employer) allows completely dynamic logic in agentic workflows to let the LLM choose what to do next. It can even be very dynamic (e.g. eval some code) though you may want it to operate on a limited set of "tools" you make available. The problem with all of these AI specific workflow engines is they are not durable, so they are process local, suffer crashes, cannot resume, don't have good visibility or distribution, etc. They often only allow limited orchestration instead of code freedom, only one language, etc
- zh2408 2y ago"Workflow can be very dynamic" is a great summary!
- infecto 2y agoWhat about workflows are not agents?
- stronglikedan 2y ago