Generator-backed tool input examples disappear from follow-up requests

Offen
#1,990 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

@sylvesterkaczmarek arbeitet bereits daran.

Seit 06.10.2026.

  • #1991 von @sylvesterkaczmarek — offen
  • #2002 von @iosayin — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
50/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
api

Rechercherichtung

Start at BaseFunctionTool, where a supplied input_examples iterable is stored as-is, and at the beta_tool/beta_async_tool constructors that pass it through; materialize the iterable once at construction so body serialization can be repeated. The issue already has two open pull requests (#1991, #2002), so check whether they already implement this before starting. Done means the public-client matrix (sync/async, JSON/streaming, generator and list-iterator inputs with list/tuple/empty/omitted controls) passes, with the eight currently failing cases green.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

beta_tool and beta_async_tool accept input_examples as Iterable[dict[str, object]], but BaseFunctionTool retains a supplied iterator directly. The first request consumes it during body serialization. Later requests from the same tool runner still carry that exhausted iterator and send input_examples: [] instead of the configured examples.

examples = ({"city": city} for city in ["Kraków", "London"])
tool = beta_tool(lookup, input_examples=examples)
# In a two-turn tool_runner run, the first request includes both examples;
# the follow-up request sends an empty input_examples list.

This silently changes the tool definition during a conversation and loses the examples intended for subsequent model calls. Lists and tuples do not exhibit the problem.

Materialize the iterable once when constructing the function tool, retaining its values for repeated serialization. Empty iterables and omitted examples should keep their respective empty/omitted behavior.

A public-client matrix reproduces the issue across sync/async and JSON/streaming runners, with generator and list-iterator inputs plus list/tuple/empty/omitted controls. Eight cases fail on unchanged main. The change is separate from #1838, which prevents telemetry from consuming the outer messages/tools iterables, and #1953, which concerns ToolError content.

Vorherrschende Sprache
Python
Sterne
4.1k
Forks
915
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus anthropics/anthropic-sdk-python

Alle Issues in anthropics/anthropic-sdk-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.