Feb 26, 2025

Picking up where we left off, in Part 1 we reviewed the basic concepts of agentic programming and some common frameworks like ReACT, Plan-and-Execute, and Tree of Thoughts. We then walked through two in-depth examples using LangChain (with ReACT) and CrewAI. In Part 2, we will take a look at OpenAI’s Swarm framework, LangGraph, and n8n. As always feel free to follow along with the video while you comb through the tutorial.
OpenAI Swarm
OpenAI Swarm is a framework that focuses on orchestrating multiple agents to work together on complex tasks. It allows for the creation of a swarm of agents, each with its own specialization, that can be dynamically called upon based on the requirements of a given task.
First thing, first. Set up a Python environment. Since we are creating a lot of projects, this helps us ensure we aren’t installing incompatible libraries from app to app.
In our app directory, create a requirements.txt
file.
You’ll notice we are using an older version of openai. That’s on purpose for compatibility when running Swarm.
Then issue the following command to install all of them:
Here’s an example of how to set up a simple swarm using OpenAI Swarm:
This fun example demonstrates how to create two agents with different roles and instructions, and how to transfer control between them. The message that says, “I want to talk to agent B.” should hand you off to Agent B, where you will be interpreting poetry rather than getting helpful responses.
Let’s work on a second example to test the waters a little bit. Here’s the full block of code:
Let’s break that down a bit. In this example, we have a main agent, a greeting agent, and a news agent. We’ll get to our main agent a little later. It is going to umbrella our other two agents. Our greeting agent is rather simple. It’s going to give you an Alexa-like response with a greeting and a joke (probably a cheesy one). Our news agent is a little more fun. In this code below, we are defining the news agent, and you will notice it is using a tool called:[fetch_news]:
The fetch_news()
is being used to grab the top headlines of the day to feed them into the prompt. The functions = [{{Tool Name}}]
gives our Agent this function as a resource it can use to construct its response.
You’ll also need to get an API key from newsapi.org, which has a very generous free tier.

Now we can use our main agent to effectively route the user to the other two agents when applicable.
In our example, when we run the Swarm client, it should trigger the news agent.
Feel free to modify thecontent of
the message to trigger the greeting agent instead. Maybe even try giving it a conflicting message like “Greet me for the day and give me the news” to see how it responds.
LangGraph
LangGraph is a powerful tool for creating complex, multi-agent systems with dynamic workflows. It allows developers to define nodes representing individual agents and edges depicting the connections between them.

What’s going on here? The Analyze node acts almost like anif
statement. It qualifies the user query, and that will determine which node it will go to next. If the query warrants the use of code in the response, the agent will move onto the Code node and if it’s just a generic type of question, it will pass onto the Generic node.
Here are the components of LangGraph:
Nodes
Nodes represent individual agents, each with a specific role. These agents might be responsible for planning, executing tasks, reviewing outputs, or utilizing specialized tools.
Edges
The edges represent the dynamic connections between agents. These connections adapt based on the context, enabling the system to cycle information through different agents as needed.
Conditional Nodes
Conditional nodes are decision-making points within the graph where the flow of execution is determined based on specific conditions or criteria.
State
State is the information that can be passed between nodes in a graph.
To get started, create a new environment like we did before. Use the following as your requirements.txt file this time and do the pip install -r requirements.txt
command like before:
The first thing to make is our agents.py file:
This file defines three key agents that form our LangGraph workflow. The analysis agent classifies incoming questions as either technical or general. The code agent handles technical queries with detailed programming responses, while the generic agent provides straightforward answers for general questions. Each agent uses ChatOpenAI and custom prompts to generate appropriate responses. These correspond to the nodes in the earlier graph exactly.
Now that we have our agents defined, we need to connect them with a graph in our graph.py
file:
This file structures the workflow between agents using a state-driven graph. It establishes the routing logic where questions flow from the analysis node to either the code or generic agent based on classification.
Finally, it all comes together in ourapp.py
:
This creates our interactive conversation loop. It manages user input, processes questions through our agent system, and handles the conversation flow.
n8n
n8n is a powerful workflow automation platform that can be leveraged for agentic programming by orchestrating agent workflows through a visual, no-code interface. Unlike the code-first approaches we've explored so far, n8n allows you to create complex agent systems by connecting nodes in a visual workflow editor.
Let's set up a simple n8n workflow that integrates with OpenAI to create an agentic system:
First, install n8n:
Once n8n is running, navigate to http://localhost:5678
in your browser to access the workflow editor.
Here's how easy it is to create an agentic workflow with n8n:
Create a new workflow: Click on "Create New Workflow" and give it a name like "Agent Workflow"
Add a On chat message node:
Add an Advanced AI node
Add agent nodes: Create OpenAI nodes for each agent type you want to use. For example, here is an Analyze Image node:
That’s it! Just add nodes as needed.
If you’re having trouble deciding a path or want to know other possibilities, n8n also provides templates to start from, like this simple AI agent for a web search.

What’s great about the n8n interface is you can start testing your inputs right away. Let’s ask our new agentic tool what the weather in Flint, MI is.

Our result was 14 degrees and cloudy. With really no code at all, we’ve provided a prompt, then our agent pinged the SERP API which generated this response:

Then, our agent also translated that back into natural language for the user.
There’s almost 1,200 templates as of the writing of this tutorial. Even if you want to build your own application from scratch, n8n can act as a well of inspiration.
n8n represents a different paradigm for creating agentic systems than what we have reviewed before, one with connectivity, and accessibility while maintaining many of the advanced capabilities of the code-based frameworks. This makes it particularly valuable for team environments where different stakeholders need visibility into how agents operate
Conclusion
Throughout this two-part tutorial series, we've explored the world of agentic programming from fundamentals to advanced implementations. You've learned how autonomous agents leverage LLMs to make decisions through frameworks like ReACT, Plan-and-Execute, and Tree of Thoughts, with hands-on examples using LangChain and CrewAI demonstrating their ability to perform complex, multi-step tasks independently.
In Part 2, we expanded your toolkit with OpenAI's Swarm framework for orchestrating multiple specialized agents and LangGraph's approach to creating dynamic, conditional workflows between agents. You've seen how main agents can intelligently route queries to specialized agents and how to implement sophisticated decision-making networks that analyze queries and direct them through appropriate channels.
You now have practical skills to implement agentic programming in your own projects—whether automating tedious tasks, enhancing customer interactions, or building complex problem-solving systems. As this field continues to evolve, we encourage you to keep experimenting with these frameworks and join communities like the OpenAI Application Explorers Meetup Group to share experiences and continue learning in this exciting domain.