Yesterday one tool. What happens when the agent has two — and needs to pick the right one based on the prompt?
I add a second @agent.tool_plain function. The agent sees both and chooses based on which fits the prompt?
Exactly. Define both tools on the same agent, run the agent — it picks:
agent = Agent(model)
@agent.tool_plain
def word_count(text: str) -> int:
return len(text.split())
@agent.tool_plain
def char_count(text: str) -> int:
return len(text)How does the agent know which tool to use? Does it read the function name?
The agent reads the function name, type annotations, and docstring — all three contribute to the tool description the model receives. A well-named function with a clear docstring gets selected more accurately. word_count and char_count are self-describing, so the model picks correctly when the prompt asks for one or the other.
def agent_two_tools(prompt: str) -> str:
agent = Agent(model)
@agent.tool_plain
def word_count(text: str) -> int:
return len(text.split())
@agent.tool_plain
def char_count(text: str) -> int:
return len(text)
return agent.run_sync(prompt).outputThe agent is picking the tool — I just defined them. That's genuinely different from any code I've written before.
You went from writing the logic yourself to defining the tools and letting the agent decide. That's the Week 4 shift.
I can add a rate calculator, a date formatter, a template filler — all as tools. The agent decides which one the prompt needs.
Name them clearly and add docstrings. The model selects tools based on how they're described — a def calc(x) with no docstring will be used inconsistently compared to def compute_invoice_total(hours: float, rate: float) -> float: """Compute total from hours and rate.""" .
agent = Agent(model)
@agent.tool_plain
def word_count(text: str) -> int:
return len(text.split())
@agent.tool_plain
def char_count(text: str) -> int:
return len(text)
result = agent.run_sync(prompt).outputThe agent receives descriptions of both tools and selects the appropriate one based on the prompt. It reads:
word_count vs char_countUse clear, specific names: compute_invoice_total beats calc. Add a one-line docstring for any tool where the name alone is ambiguous.
The agent may call neither tool (if the prompt does not require either), one tool, or call a tool multiple times if needed.
Yesterday one tool. What happens when the agent has two — and needs to pick the right one based on the prompt?
I add a second @agent.tool_plain function. The agent sees both and chooses based on which fits the prompt?
Exactly. Define both tools on the same agent, run the agent — it picks:
agent = Agent(model)
@agent.tool_plain
def word_count(text: str) -> int:
return len(text.split())
@agent.tool_plain
def char_count(text: str) -> int:
return len(text)How does the agent know which tool to use? Does it read the function name?
The agent reads the function name, type annotations, and docstring — all three contribute to the tool description the model receives. A well-named function with a clear docstring gets selected more accurately. word_count and char_count are self-describing, so the model picks correctly when the prompt asks for one or the other.
def agent_two_tools(prompt: str) -> str:
agent = Agent(model)
@agent.tool_plain
def word_count(text: str) -> int:
return len(text.split())
@agent.tool_plain
def char_count(text: str) -> int:
return len(text)
return agent.run_sync(prompt).outputThe agent is picking the tool — I just defined them. That's genuinely different from any code I've written before.
You went from writing the logic yourself to defining the tools and letting the agent decide. That's the Week 4 shift.
I can add a rate calculator, a date formatter, a template filler — all as tools. The agent decides which one the prompt needs.
Name them clearly and add docstrings. The model selects tools based on how they're described — a def calc(x) with no docstring will be used inconsistently compared to def compute_invoice_total(hours: float, rate: float) -> float: """Compute total from hours and rate.""" .
agent = Agent(model)
@agent.tool_plain
def word_count(text: str) -> int:
return len(text.split())
@agent.tool_plain
def char_count(text: str) -> int:
return len(text)
result = agent.run_sync(prompt).outputThe agent receives descriptions of both tools and selects the appropriate one based on the prompt. It reads:
word_count vs char_countUse clear, specific names: compute_invoice_total beats calc. Add a one-line docstring for any tool where the name alone is ambiguous.
The agent may call neither tool (if the prompt does not require either), one tool, or call a tool multiple times if needed.
Create a free account to get started. Paid plans unlock all tracks.