Ever sent your AI agent into the "battle" of a complex task, only to watch it fumble with a blunt sword or use the wrong weapon for the fight? When an agent fails, our first instinct is to blame its "brain" (the LLM). But the real culprit is often the arsenal we equipped it with—the collection of weapons was dull, confusing, or simply not right for the job.
In our previous tutorial, LLM Agents are simply Graph — Tutorial For Dummies, we revealed that every agent is like a warrior following a simple battle plan: Assess -> Strike -> Repeat
. We showed how the 'assessing' happens in a decision node that plans the next move. Now, it's time to forge the weapons used for the Strike.
That 'Strike' is powered by the agent's Arsenal—the official set of weapons, tools, and spells it can draw upon. In technical terms, this is its Action Space. This isn't just a list of functions; it is the very soul of your agent's power. A well-forged arsenal, where every blade is sharp and serves a unique purpose, is the difference between an agent that is defeated by the first obstacle and one that conquers any challenge.
In this guide, you are the master blacksmith. Using the transparent and powerful PocketFlow framework as your forge, we will teach you how to craft an arsenal of actions that will turn your agent from a clumsy squire into a legendary warrior.
The Battle Tactician: How an Agent Chooses Its Weapon
So, we have an arsenal. But how does the agent, our digital warrior, know when to draw a longsword for a close-quarters fight versus firing a bow from a distance?
This critical decision happens in the DecideAction
node—the agent's battle tactician. At its core, every agent is just a simple loop that consults its tactician, who then chooses an action from the arsenal. The chosen action is performed, and the results are reported back to the tactician to plan the next move.
Visually, the battle plan looks like this:
In this diagram:
DecideAction
(The Tactician): This is the brain. It analyzes the battlefield (the user's request and current data).The Arrows (The Commands): Based on its analysis, the tactician issues a command:
search_web
,write_file
, oranswer_question
. This is the branch in the graph.The Action Nodes (The Specialists): Each command goes to a specialist soldier who executes that one task.
The Loop Back (The Report): After the specialist completes their task, they report back to the tactician with new information, and the cycle begins again.
"But what magic happens inside that DecideAction
node?" you ask. "How does it actually think?"
This is the most misunderstood part of agent design, and the secret is shockingly simple. It's just a prompt. There's no complex algorithm, just a carefully written set of instructions for the LLM.
The tactician's "brain" is a prompt that looks something like this:
### CONTEXT
You are a research assistant. Here is the current situation:
Question: {the user's original question}
Previous Actions: {a log of what has been done so far}
Current Information: {any data gathered from previous actions}
### ARSENAL (Available Actions)
Here are the weapons you can use. Choose one.
[1] search_web
Description: Search the internet for up-to-date information.
Parameters:
- query (str): The specific topic to search for.
[2] write_file
Description: Save text into a local file.
Parameters:
- filename (str): The name of the file to create.
- content (str): The text content to write into the file.
[3] answer_question
Description: Provide the final answer to the user.
Parameters:
- answer (str): The complete, final answer.
## YOUR NEXT COMMAND
Review the CONTEXT and choose the single best ACTION from your ARSENAL to proceed.
Format your response as a YAML block.
That's it! The agent's entire decision-making process boils down to this: the LLM reads the description of the situation and the "user manual" for every weapon in its arsenal, and then it picks the one that makes the most sense.
The quality of its choice is 100% dependent on how clearly you describe its weapons. A sharp, well-defined arsenal in your prompt leads to a smart, effective agent. A vague, confusing one leads to a warrior who brings a knife to a dragon fight.
Now, let's learn how to forge these weapons, from simple daggers to god-tier magic spells.
Level Up Your Arsenal: The Three Tiers of Weapon Complexity
As a master blacksmith, you wouldn't forge just one type of weapon. You need a full range, from simple daggers for quick jabs to powerful, enchanted swords for epic battles. The same is true for your agent's arsenal. Actions can be designed with varying levels of power and complexity. Let's explore the three tiers.
Level 1: The Simple Dagger (The "Button" Action)
A simple dagger is a no-frills weapon. You draw it, you use it. It does one thing, and it does it reliably. These are actions that require no parameters.
Think of them as on/off switches or simple commands.
In the Forge (Code):
An action like request_human_help
or finish_task
.
In the Arsenal (Prompt Description):
[1] request_human_help
Description: If you are stuck or need clarification, use this action to pause and ask the human user for guidance.
When to Use It:
For clear, binary decisions. When the agent needs to signal a state change, like "I'm finished," "I'm stuck," or "I've failed." They are perfect for controlling the overall flow of the battle plan.
Level 2: The Sharpshooter's Bow (The Parameterized Tool)
A bow is useless without an arrow and a target. This weapon requires input to be effective. These are the most common and versatile actions in an agent's arsenal—actions that require specific parameters to function.
To use these weapons, the agent must not only choose the bow but also aim it by providing the correct inputs.
In the Forge (Code):
An action like search_web(query)
or send_email(to, subject, body)
.
In the Arsenal (Prompt Description):
[2] search_web
Description: Searches the public internet for a given text string.
Parameters:
- query (str): The precise search term to look up. Must be a focused string.
[3] send_email
Description: Composes and sends an email to a recipient.
Parameters:
- to (str): The email address of the recipient.
- subject (str): The subject line of the email.
- body (str): The main content of the email.
The Crucial Link to Your Blacksmithing Skills:
How does the agent provide these parameters? This is where your skill in structured output becomes critical. As we covered in our guide, Structured Output for Beginners, you must instruct the LLM to format its response in a structured way (like YAML or JSON) so your program can easily parse the action and its parameters.
Without this skill, you've given your agent a powerful bow but no way to nock an arrow.
Level 3: The Spellbook of Creation (The Programmable Action)
This is the ultimate weapon: a spellbook that doesn't contain a list of spells but teaches the agent how to write its own. These are programmable actions where the agent generates code or complex instructions on the fly.
This gives the agent god-like flexibility to solve novel problems you never explicitly trained it for.
In the Forge (Code):
An action like execute_sql(query)
or run_python_code(code)
.
In the Arsenal (Prompt Description):
[4] execute_sql
Description: Write and run a SQL query against the company's sales database. The database contains tables named 'customers', 'orders', and 'products'.
Parameters:
- sql_query (str): A valid SQL query string to execute.
[5] run_python_code
Description: Write and execute a sandboxed Python script for complex calculations, data manipulation, or interacting with APIs.
Parameters:
- code (str): A string containing the Python code to run.
The Power and the Peril:
A spellbook is the most powerful weapon in your arsenal, but it's also the most dangerous.
Power: Your agent can solve almost any problem that can be expressed in code. It's no longer limited to pre-defined tools.
Peril: It's much more likely to make a mistake (e.g., writing buggy code). More importantly, it opens up massive security risks if not handled carefully (e.g., executing malicious code like
os.remove("important_file.txt")
). Always run such code in a secure, sandboxed environment.
Mastering these three tiers allows you to build a balanced and effective arsenal, equipping your agent for any challenge it might face.
Forging the Perfect Arsenal: 3 Golden Rules for Your Weapon Inventory
A legendary warrior doesn't just carry a random assortment of weapons. Their arsenal is carefully curated—each item is perfectly crafted, serves a distinct purpose, and is instantly accessible. As the master blacksmith for your agent, you must apply the same discipline. Here are the three golden rules for forging a world-class action space.
Golden Rule #1: Engrave a Crystal-Clear User Manual (Clarity is King)
The descriptions for your actions and their parameters are not notes for yourself; they are the user manual for the LLM. If the manual is vague, the LLM will misuse the tool. Be painfully, relentlessly explicit.
A Dull Blade (Bad Description):
search: searches for stuff
The agent sees this and thinks, "What stuff? How? What do I provide?" The result is a wild guess.
A Sharpened Katana (Good Description):
search_web(query: str):
Description: Searches the public internet for up-to-date information on a single, specific topic. Returns the top 5 text snippets.
Parameters:
- query (str): A simple and focused search query, typically 3-5 words long.
Now the agent understands its constraints. It knows the tool is for one topic and the query should be short. It will correctly generate a command like search_web(query: "2024 Nobel Prize Physics winner")
, leading to a much better outcome.
Golden Rule #2: Don't Burden Your Warrior with a Junk Drawer (Keep it Concise)
A warrior grabbing a weapon in the heat of battle can't afford to sift through a hundred options. They need a small, elite set of choices. Overwhelming the LLM with too many actions leads to confusion, slower decision-making (more tokens to process), and a higher chance of picking the wrong tool.
The Blacksmith's Guideline: An arsenal of 10 weapons is formidable. An arsenal of 100 is a junk drawer.
If your action space is growing too large, it's a sign that your tools are too granular. Instead of creating read_json_file
, read_csv_file
, and read_text_file
, forge a single, more powerful weapon: read_file(filename: str)
. Your code can handle the internal logic of parsing different file types. Keep the agent's choices clean and high-level.
Golden Rule #3: Make Every Weapon Unique (Slay Redundancy)
Every weapon in the arsenal should have a unique purpose. If the agent has two tools that do similar things, it will get confused about which one to use. This is called a lack of "orthogonality."
The Confusing Arsenal (Bad Design):
read_csv_from_disk(file_path: str)
: Reads customer data from a local CSV file.query_database(sql: str)
: Queries the live customer database.
The agent is asked to "find the total sales for new customers from this quarter." Which tool should it use? The data might be in the CSV, or it might be in the database. The agent doesn't know and might make the wrong choice.
The Pro-Gamer Move: Simplify the Battlefield
A true master blacksmith doesn't just forge weapons; they shape the battlefield to their advantage. Instead of giving the agent two ambiguous tools, do the work for it behind the scenes.
The Decisive Arsenal (Good Design):
Before the agent even starts, run a script that loads the CSV data into a temporary table in the database.
Now, the agent's arsenal is clean and unambiguous:
query_database(sql: str)
: Queries the customer database, which contains all known customer data.
The ambiguity is gone. The agent has one, and only one, tool for retrieving customer data. You've eliminated redundancy and made the agent's decision trivial, guaranteeing it makes the right choice every time.
Conclusion: An Agent is Only as Sharp as its Arsenal
And so, the secrets of the forge are yours. You now understand that the true power of an LLM agent doesn't come from some mysterious, hidden algorithm. It comes from the thoughtful, disciplined, and creative process of crafting its Action Space.
You've learned that agents are just warriors in a loop with branches, making decisions based on a prompt that serves as their battle plan. And you've seen how to stock their arsenal for any challenge:
With Simple Daggers for quick, decisive commands.
With Sharpshooter's Bows for precise, targeted actions.
With reality-bending Spellbooks of Creation for ultimate flexibility.
Most importantly, you now hold the three golden rules of the master blacksmith:
Engrave a Clear Manual: Your descriptions are the agent's guide to victory.
Avoid the Junk Drawer: A curated, concise arsenal is deadlier than a cluttered one.
Slay Redundancy: Make every weapon unique to ensure the agent never hesitates.
The next time you see a complex agent framework with thousands of lines of code, you won't be intimidated. You'll know to look past the noise and ask the fundamental questions: "What's in the arsenal? How is it described? Is it sharp, concise, and unique?"
Armed with this knowledge, you are no longer just a coder; you are an agent blacksmith. You have the power to forge not just tools, but intelligent, reliable, and effective digital warriors.
Ready to light the forge? Dive into the code and explore these principles in action by checking out PocketFlow on GitHub!
Congrats, Zachary! Great article, great explanation, as always. Let me share some of my experience: I never used Cursor for AI Coding, I used to go with CLINE/RooCode. But 2 weeks ago I have changed to Claude Code, since their plan is the most affordable and their agent is incredible (once, the Agent researched an issue for 5 minutes in the Web and got a correct response). Also, Claude costs only $17 and is kind of unlimited (limited unlimited - after around 2 full context windows you have to await a couple hours to use it again). Also, I will try the new Coding Agent: "Open Code". Everyone says it is great and also works with Claude PRO. And I'm willing to try a new tool from the dagger.io team/community called "container use". https://github.com/dagger/container-use
I hope this can be useful.
Best Regards
1. You chose a good metaphor
2. You might be playing a lot of video games.