AWS Builder Center
Agents Can Build Their Own Tools Now?!

Agents Can Build Their Own Tools Now?!

What happens when your agent hits the edge of its toolbox? Instead of stopping, it can build the missing capability and keep going.

Sr. Developer Advocate, GenAI
I hit a wall with a Strands agent last month. It had a text counting tool and shell access, plenty for answering questions like “how many words are in this file?” Then I asked it how similar two articles in my data folder were. The agent could inspect both files and understand the question, but there was nothing in its toolset that could actually calculate similarity.
Normally, I would fix that by writing a  text_similarity  tool, adding it to the agent, testing everything again, and redeploying. But the missing capability was small and well defined, and I started wondering why I had to be the one to add it. Could the agent create the function itself, verify that it worked, load it at runtime, and then continue the original task?
That is what I tried next. In Strands, this pattern is called meta-tooling.

Let's start with the initial agent

The original agent was intentionally small.
from strands import Agent
from tools.text_count import text_count

agent = Agent(
system_prompt=(
"You are a helpful text analysis assistant. "
"Answer the questions using the tools available"
),
tools=[text_count, shell],
)

agent("how similar are two articles in the data folder")

The  shell  tool lets the agent inspect the files in my data directory, and I wrote one custom tool called  text_count . This is a normal Strands tool that I created myself and registered with the agent ahead of time. The  text_count  tool counts words, sentences, and characters. That works perfectly when the request matches the capability I gave it. But there is no similarity function in the tool list.
@tool
def text_count(text: str) -> dict:
"""Count the number of words, sentences, and characters in a text.

Args:
text: The text to analyze
"""
words = len(text.split())
sentences = text.count(".") + text.count("!") + text.count("?")
characters = len(text)

return {
"words": words,
"sentences": sentences,
"characters": characters,
}
So I asked:
How similar are the two articles in the data folder?
The agent could still inspect the articles and give me a qualitative answer. It could tell me that both were about the semiconductor shortage, supply-chain disruption, and investment in domestic chip manufacturing.
Something along these lines:
The two articles are fairly similar in topic. Both discuss the global semiconductor shortage, its impact on the automotive and electronics industries, and the U.S. response through the CHIPS Act.
That is not a bad answer, but it is not what I wanted. There is no similarity score, no defined comparison method, and no repeatable calculation I can use on the next pair of documents. The agent can reason about whether two texts sound similar, but it does not have a tool for actually measuring that similarity.
Normally, that is where I would write another tool. This time, I wanted the agent to do that part itself. So instead of adding  text_similarity  myself, I gave the agent tools for creating tools.

Now, with the meta-tooling capability

The second version adds  editor  and  load_tool :
from strands import Agent
from strands_tools import editor, load_tool, shell
from tools.text_count import text_count

agent = Agent(
system_prompt=SYSTEM_PROMPT,
tools=[text_count, editor, shell, load_tool],
)

 editor  lets the agent write a Python file.  load_tool  dynamically registers the new function with the running agent, making it available as another callable tool.
None of these tools calculates similarity. They simply give the agent a way to build the missing capability.
The part that took a few iterations was the system prompt. Telling the agent “create a tool when you need one” was too vague, so I gave it an explicit workflow:
First, it tells the agent when it is allowed to create a new tool. Second, it gives the agent a concrete contract for what that tool should look like.
SYSTEM_PROMPT = """You are a text analysis assistant with meta-tooling capabilities.
You have some existing tools. Use them when they fit the task.
When a required capability does not exist in your current tools, create it.

## TOOL NAMING
- File name and function name must match
- Example: tools/my_tool.py contains a function called my_tool

## TOOL STRUCTURE
Use the @tool decorator:

```python
from strands import tool

@tool
def tool_name(param1: str, param2: int = 10) -> dict:
\"\"\"Description of what this tool does.

Args:
param1: What this parameter is
param2: What this parameter is
\"\"\"
# implementation
return {"result": "value"}
```

## CREATION WORKFLOW
1. Write the tool to a file in the tools/ directory using editor
2. Validate syntax: python -c "import ast; ast.parse(open('path').read())"
3. Run a quick test to verify it works
4. Load it with load_tool (path=file_path, name=function_name)
5. Retry the original task using the new tool

## CONSTRAINTS
- Check if a suitable tool already exists before creating one
- Do not modify existing tools unless explicitly asked
- Handle bad input gracefully — return an error dict, do not crash
- One tool, one job
"""
So the prompt is not just saying “write some code.” It defines the shape of a valid Strands tool, then gives the agent a sequence for taking that tool from generated code to something it can actually use.
I then ran the exact same question again.

This is what the agent built

This time, the agent recognized that none of its existing tools could calculate similarity. It created  tools/text_similarity.py , tested it, and dynamically loaded it into its own tool registry.
I did not write this file beforehand. This is the tool the agent generated on the fly:
from strands import tool
import math
import re
from collections import Counter

@tool
def text_similarity(text1: str, text2: str) -> dict:
"""Computes similarity between two texts using multiple metrics.

Calculates:
- Jaccard similarity (word-level overlap)
- Cosine similarity (TF-weighted vectors)
- Shared keywords (meaningful overlapping words)
- Overall similarity score (average of Jaccard + Cosine)

Args:
text1: The first text to compare.
text2: The second text to compare.
"""
if not text1 or not text2:
return {"error": "Both text1 and text2 must be non-empty strings."}

STOPWORDS = {
"a", "an", "the", "and", "or", "but", "in", "on", "at", "to", "for",
"of", "with", "by", "from", "that", "this", "it", "is", "was", "are",
"were", "has", "have", "had", "as", "be", "been", "which", "its",
"their", "they", "not", "what", "how", "about", "during", "across"
}

def tokenize(text: str) -> list[str]:
return [
w.lower()
for w in re.findall(r'\b[a-zA-Z]+\b', text)
if w.lower() not in STOPWORDS
]

tokens1 = tokenize(text1)
tokens2 = tokenize(text2)

if not tokens1 or not tokens2:
return {
"error": "One or both texts contain no meaningful words after filtering."
}

set1, set2 = set(tokens1), set(tokens2)
intersection = set1 & set2
union = set1 | set2
jaccard = len(intersection) / len(union) if union else 0.0

freq1 = Counter(tokens1)
freq2 = Counter(tokens2)
vocab = set(freq1) | set(freq2)

vec1 = [freq1.get(w, 0) for w in vocab]
vec2 = [freq2.get(w, 0) for w in vocab]

dot = sum(a * b for a, b in zip(vec1, vec2))
mag1 = math.sqrt(sum(a ** 2 for a in vec1))
mag2 = math.sqrt(sum(b ** 2 for b in vec2))

cosine = dot / (mag1 * mag2) if mag1 and mag2 else 0.0
overall = (jaccard + cosine) / 2

return {
"jaccard_similarity": round(jaccard, 4),
"cosine_similarity": round(cosine, 4),
"overall_similarity": round(overall, 4),
"shared_keywords": sorted(intersection),
"unique_to_text1": sorted(set1 - set2),
"unique_to_text2": sorted(set2 - set1),
}

What I liked was how conservative the implementation was. It stayed within the Python standard library, handled invalid input, and used two straightforward measures: Jaccard similarity for vocabulary overlap and cosine similarity for word-frequency overlap.
Would I use this exact approach for production semantic similarity? Probably not. I might use embeddings. But the algorithm was not the experiment.
The experiment was whether the agent could notice a missing capability, create something reasonable, test it, load it, and continue.
It could.
The agent started the request with:
text_count
editor
shell
load_tool

and finished it with:
text_count
editor
shell
load_tool
text_similarity

No restart, no manual change to the agent definition, and no redeploy. The new tool was created and loaded during the same run.
That is what makes meta-tooling interesting to me. The initial tool list does not necessarily have to contain every capability the agent will ever need. For some workloads, it can be the starting point.
Of course, a generated tool that runs is not automatically a good tool, and giving an agent permission to write and execute code raises obvious safety questions. That is where evaluations and guardrails come in, and that is what I’ll cover in Part 2.
For now, I wanted to answer one question: what happens when the agent reaches the edge of the tools I gave it?
In this case, it built the missing one.
You can find the GitHub code repo  here .
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article