googleapis / googleapis/python-genai

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

Open
#2,902 2 comments 2 reactions 1 assignee Claimed by @kkorpal View on GitHub
priority: p2 type: bug
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

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

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.