google / google/adk-python

Big integer precision loss in tool calling

Open
#3,592 2 comments 0 reactions 1 assignee Assigned to @yyyu-google View on GitHub
needs review planned tools
Dominant language
Python
Stars
21.5k
Forks
4k
Avg merge
1d 14h
Merged PRs (30d)
37

Description

**Describe the bug**

ADK seems to have a precision limitation for integer arguments in function calling, which may catch Python users in surprise.

**To Reproduce**

A simplistic example:

```
from google.adk.agents.llm_agent import Agent

def add(a: int, b: int) -> int:
"""Returns the sum of two integers."""
return a + b

root_agent = Agent(
model='gemini-2.5-flash',
name='root_agent',
description="Add two integers.",
instruction="""
You are a helpful assistant that adds two integers.
Call the `add` tool to perform the calculation.
Just return its result. Do not doubt its correctness.
""",
tools=[add],
)
```

Interaction:
```
Me: 10000000000000001+123456789
Agent: The sum of 10000000000000001 and 123456789 is 10000000123456788.
```

Function calling log:
```
{"parts":[{"function_call":{"args":{"a":1e16,"b":123456789},"name":"add"},"thought_signature":"......"}],"role":"model"}
{"parts":[{"function_response":{"name":"add","response":{"result":1.0000000123456788e16}}}],"role":"user"}
```

You can see the numbers are actually represented as float numbers behind the sense, causing a loss of precision and inaccurate result.

**Expected behavior**

The integers are passed to tools without precision loss, and 10000000000000001+123456789 = 10000000123456790.

I believe this is caused by JSON serialization, which does not distinguish int and float numbers and may support only limited precision for numbers. But it's quite surprising for Python (and maybe even Go/Java) users, as the number I used (`10000000000000001`) is well within the range of 64-bit int types.

**Desktop (please complete the following information):**
- OS: Linux
- Python version(python -V): 3.13.7
- ADK version(pip show google-adk): 1.18.0

**Model Information:**
- Are you using LiteLLM: No
- Which model is being used: gemini-2.5-flash but the issue is model-agnostic I think.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.