Skip to content

Commit 3b7d1ed

Browse files
Cheuk Lun Koccreutzi
authored andcommitted
Bug fix in math agent example
1 parent d799312 commit 3b7d1ed

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

examples/SolveSimpleMathProblemUsingAIAgent.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ In this example, use an LLM to find the smallest root of a second\-order polynom
4343
- Find the smallest real number from a list of two numbers.
4444
## Compute Roots of Second\-Order Polynomial
4545

46-
The `solveQuadraticEquation` function takes the three coefficients of a quadratic polynomial as input and uses the [`roots`](https://www.mathworks.com/help/matlab/ref/roots.html) function to return a column vector containing the two roots.
46+
The `solveQuadraticEquation` function takes the three coefficients of a quadratic polynomial as input and uses the [`roots`](https://www.mathworks.com/help/matlab/ref/roots.html) function to return a column vector containing the two roots. The LLM used in this example uses textual representations of tool call results in JSON format. Roots of polynomials can be complex, but JSON does not support complex numbers. Therefore, specify the roots as strings.
4747

4848
```matlab
49-
function r = solveQuadraticEquation(a,b,c)
49+
function strR = solveQuadraticEquation(a,b,c)
5050
r = roots([a b c]);
51+
strR = string(r);
5152
end
5253
```
5354

@@ -62,7 +63,7 @@ toolSolveQuadraticEquation = addParameter(toolSolveQuadraticEquation,"c",type="n
6263
```
6364
## Find Smallest Real Number
6465

65-
The `smallestRealNumber` function computes the smallest real number from a list of two numbers. The LLM used in this example expresses tool calls, including input parameters, in JSON format. Roots of polynomials can be complex, but JSON does not support complex numbers. Therefore, specify the roots as strings and convert them back into numbers using the [`str2double`](https://www.mathworks.com/help/matlab/ref/str2double.html) function.
66+
The `smallestRealNumber` function computes the smallest real number from a list of two numbers. The LLM used in this example expresses tool calls, including input parameters, in JSON format. As JSON does not support complex numbers, specify the roots as strings and convert them back into numbers using the [`str2double`](https://www.mathworks.com/help/matlab/ref/str2double.html) function.
6667

6768
```matlab
6869
function xMin = smallestRealNumber(strX1,strX2)
@@ -253,15 +254,13 @@ agentResponse = runReActAgent(userQuery,toolRegistry);
253254

254255
```matlabTextOutput
255256
User: What is the smallest root of x^2+2x-3=0?
256-
[Thought] To find the smallest root of the quadratic equation \(x^2 + 2x - 3 = 0\), I will first solve the quadratic equation to find both roots. Then, I will determine the smallest root.
257-
258-
I will start by solving the quadratic equation.
257+
[Thought] I will solve the quadratic equation x^2 + 2x - 3 = 0 to find its roots.
259258
[Action] Calling tool 'solveQuadraticEquation' with args: "{\"a\":1,\"b\":2,\"c\":-3}"
260-
[Observation] Result from tool 'solveQuadraticEquation': [-3.0000000000000004,0.99999999999999978]
261-
[Thought] I have found the roots of the equation to be approximately -3 and 1. Now, I will identify the smallest root between these two values.
259+
[Observation] Result from tool 'solveQuadraticEquation': ["-3","1"]
260+
[Thought] I will find the smallest root from the roots -3 and 1.
262261
[Action] Calling tool 'smallestRealNumber' with args: "{\"x1\":\"-3\",\"x2\":\"1\"}"
263262
[Observation] Result from tool 'smallestRealNumber': -3
264-
[Thought] The smallest root of the quadratic equation \(x^2 + 2x - 3 = 0\) is -3. I will now provide this as the final answer.
263+
[Thought] The smallest root is -3. I will now provide the final answer.
265264
```
266265

267266

@@ -272,7 +271,7 @@ disp(agentResponse);
272271
```
273272

274273
```matlabTextOutput
275-
The smallest root of the equation \(x^2 + 2x - 3 = 0\) is -3.
274+
The smallest root of the equation x^2 + 2x - 3 = 0 is -3.
276275
```
277276

278277
# References
-76 Bytes
Binary file not shown.
-48 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)