google / google/adk-python

Big integer precision loss in tool calling

オープン
#3,592 コメント 2 件 リアクション 0 件 担当者 1 名 @yyyu-google に割り当て済み GitHub で見る
needs review planned tools
主要言語
Python
スター
21.5k
フォーク
4k
平均マージ
1日 14時間
マージ済み PR(30日)
37

説明

**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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。