googleapis / googleapis/python-genai

generate_content and generate_content_stream show afc warning for empty config or config with empty tools

Aperta
#2,902 2 commenti 2 reazioni 1 assegnatario Rivendicata da @kkorpal Vedi su GitHub
priority: p2 type: bug
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

Google GenAI model methods `generate_content` and `generate_content_stream` have automatic function calling (AFC) feature which can invoke passed callables. There are alternative function calling patterns though. I.e. when generate content config has only function declarations but not callables. Recently a warning was implemented about non-recommended usage of AFC. Interestingly the warning (and AFC code path overall) is not activated when non empty function declarations are passed to model. However warning (AFC code path overall) is activated when config is empty/config tools is empty. Supposedly `_extra_tools.should_disable_afc` should return `True` for empty config/empty config tools.

#### Environment details

- Programming language: python
- OS: ubuntu 24.04
- Language runtime version: 3.12.3
- Package version: 2.19.0

#### Steps to reproduce

```python
from google import genai
from google.genai.models import Models

client = genai.Client()

print('CONFIG IS NONE')

client.models.generate_content(
model="gemini-2.5-flash",
contents="Hello",
config=None,
)

Models._logged_afc_warning = False

print('CONFIG.TOOLS IS NONE')

client.models.generate_content(
model="gemini-2.5-flash",
contents="Hello",
config={"tools": None},
)

Models._logged_afc_warning = False

print('CONFIG.TOOLS IS FUNCS')

client.models.generate_content(
model="gemini-2.5-flash",
contents="Hello",
config={
"tools": [
{
"function_declarations": [
{"name": "ping", "description": "Return pong"}
]
}
]
},
)
```

Observed result:

```
CONFIG IS NONE
Direct use of automatic function calling (AFC) in Models.generate_content is not recommended. Instead, we recommend to use AFC in Chat.send_message. Similarly, direct use of AFC in Models.generate_content_stream is not recommended. Instead, we recommend to use AFC in Chat.send_message_stream.
CONFIG.TOOLS IS NONE
Direct use of automatic function calling (AFC) in Models.generate_content is not recommended. Instead, we recommend to use AFC in Chat.send_message. Similarly, direct use of AFC in Models.generate_content_stream is not recommended. Instead, we recommend to use AFC in Chat.send_message_stream.
CONFIG.TOOLS IS FUNCS
```

Expected result:

No AFC warnings shown

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.