Tools
Count the words
A tool is a small recipe the agent may run. def names the recipe. The quoted line under the name says what it is for.
This first example runs the recipe by itself, so you can see the number.
Example
def word_count(text: str) -> str:
"""Count the words in text."""
return str(len(text.split()))
print(word_count("praison agents university"))Example explained
- def — Starts the recipe.
- docstring — The quoted description the agent reads.
Give the recipe to an agent
tools is the list of recipes. The agent can call word_count while it answers.
Example
from praisonai import Agent
def word_count(text: str) -> str:
"""Count the words in text."""
return str(len(text.split()))
agent = Agent(
name="Counter",
instructions="Use the word_count tool.",
tools=[word_count],
)
print(agent.start("How many words are in: praison agents university"))Example explained
- tools — Where the recipe is attached.
Two tools
Agents may pick among several tools. The agent must call word_count, not guess.
Example
from praisonai import Agent
def word_count(text: str) -> str:
"""Count the words in text."""
return str(len(text.split()))
def echo(text: str) -> str:
"""Return the same text."""
return text
agent = Agent(
instructions="Use word_count for counting. Never count without the tool.",
tools=[word_count, echo],
)
print(agent.start("How many words in: agents use tools?"))Example explained
- from praisonai import Agent — Imports Agent needed for two tools.
- def word_count — Defines `word_count` used directly in the two tools workflow.
- def echo — Defines `echo` used directly in the two tools workflow.
- Agent(…) — Instantiates the Agent configured for two tools.
Reference: documentation