Tool Agent
Using tools (formerly functions), you can define a built-in agent that can take decisions and reasoning based on the tools provided to it.
Letβs illustrate this concept using the llamaindex sum div sample: an agent that can sum or divide two numbers and needs to answer basic arithmetic questions.
Using tools
By declaring tools (and providing a descriptive description), you provide the opportunity for the LLM to requests a tool call during the output generation. In the snippet below, we declare a tool that can sum two numbers. It will be called by the LLM when a sum operation is required.
You can also simplify the parameter definition by provider an example object and the schema will be inferred._createMdxContent
Parameters
The arithmetic question can be declared as a script parameter to be used in the agent script.
The parameter value are populated in the env.vars
object.
Putting it all together, we define another tool to divide two numbers and inline an arithmetic question.
π€ user
π€ assistant
- π tool call
divide({"a":15,"b":3})
(call_9p0oWdWpT6vGyxzwq2vJXHrq
)
π οΈ tool call_9p0oWdWpT6vGyxzwq2vJXHrq
π€ assistant
Using system.math
The system prompt system.math
wraps the parsers.math
expression parser and evaluator and exposes it as a tool.
This simplifies the agent script as we do not have to define tools anymore.