# Creating a Math Agent with BedrockLLMAgent and Custom Tools

This guide demonstrates how to create a specialized math agent using BedrockLLMAgent and custom math tools. We’ll walk through the process of defining the tools, setting up the agent, and integrating it into your Multi-Agent Orchestrator system.

**Define the Math Tools**

Let’s break down the math tool definition into its key components:

A. Tool Descriptions

**Explanation:**

- This defines two tools:
`perform_math_operation`

and`perform_statistical_calculation`

. - Each tool has a name, description, and input schema.
- The input schema specifies the required parameters (operation and arguments) for each tool.

B. Tool Handler

**Explanation:**

- This handler processes the LLM’s requests to use the math tools.
- It iterates through the response content, looking for tool use blocks.
- When it finds a tool use, it calls the appropriate function (
`executeMathOperation`

or`calculateStatistics`

). - It formats the results and adds them to the conversation as a new user message.

C. Math Operation and Statistical Calculation Functions

**Explanation:**

- These functions perform the actual mathematical and statistical operations.
- They handle various operations like addition, subtraction, trigonometry, mean, median, etc.
- They return either a result or an error message if the operation fails.

**Create the Math Agent**

Now that we have our math tool defined and the code above in a file called `weatherTool.ts`

, let’s create a BedrockLLMAgent that uses this tool.

**Add the Math Agent to the Orchestrator**

Now we can add our math agent to the Multi-Agent Orchestrator:

## 4. Using the Math Agent

Now that our math agent is set up and added to the orchestrator, we can use it to perform mathematical operations:

### How It Works

- When a mathematical query is received, the orchestrator routes it to the Math Agent.
- The Math Agent processes the query using the custom system prompt (MATH_PROMPT).
- The agent uses the appropriate math tool (
`perform_math_operation`

or`perform_statistical_calculation`

) to perform the required calculations. - The mathToolHandler processes the tool use, performs the calculations, and adds the results to the conversation.
- The agent then formulates a response based on the calculation results and the original query, showing the work and explaining each step.

This setup allows for a specialized math agent that can handle various mathematical and statistical queries while performing real-time calculations.

By following this guide, you can create a powerful, context-aware math agent using BedrockLLMAgent and custom tools within your Multi-Agent Orchestrator system.