googleapis / googleapis/python-genai

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

Abierto
#2,902 2 comentarios 2 reacciones 1 asignado Reclamado por @kkorpal Ver en GitHub
priority: p2 type: bug
Lenguaje dominante
Python
Estrellas
4k
Forks
1k
Merge medio
2 d 12 h
PR fusionados (30 d)
41

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.