Commit Graph

78 Commits

Author SHA1 Message Date
Mark McDonald 8b38ec09d8 fix: dont send default params in gemini genconfig
Gemini 3+ models may throw errors if a default value is set for
parameters like temperature, top-p, etc.

The 3-series models use 1.0 as the default temperature, so this
should be a backwards-compatible change.
2026-07-08 17:47:10 +08:00
Saurav Panda 2afef14667 Trim comments to essentials 2026-07-06 16:47:27 -07:00
Saurav Panda db70a813c1 Let truncation errors switch to the fallback LLM
The 400 status chosen for truncation errors (deliberately outside provider
retry lists — an identical retry truncates identically) also fell outside
Agent._try_switch_to_fallback_llm's allowlist, so a configured fallback_llm
could no longer rescue a truncated run. Before this PR the downstream parse
failure was wrapped as a 502 ModelProviderError, which did allow the switch.

Introduce ModelOutputTruncatedError(ModelProviderError, status 400): the
three providers raise it, provider retry loops still skip it, and the
agent's fallback check treats it as switchable explicitly — a fallback with
a different output cap can succeed where the primary truncated.
2026-07-06 16:31:18 -07:00
Saurav Panda db2b2c67f9 Describe truncation gracefully when the token cap is unset
max_completion_tokens (OpenAI) and max_output_tokens (Google) are optional;
when set to None the truncation message printed 'truncated at
max_output_tokens=None'. Fall back to "the model's output token limit" —
a MAX_TOKENS/length finish reason means some server-side cap fired even
with no client-side cap configured. Anthropic's max_tokens is non-optional
and unaffected.
2026-07-06 15:56:03 -07:00
Saurav Panda 5f690c207e Detect LLM output truncation instead of failing with misleading parse errors
Structured output cut off at the completion-token cap was never detected:
OpenAI's finish_reason='length', Anthropic's stop_reason='max_tokens', and
Gemini's MAX_TOKENS finish reason all produced JSON cut mid-string, which
surfaced as an opaque parse error ('Unterminated string starting at...') —
or worse, a valid-but-chopped prefix. The actual cause (output token cap)
was never mentioned, and with defaults like max_completion_tokens=4096 this
regularly hits long done()/extract outputs.

Each provider now checks the finish/stop reason before parsing structured
output and raises a clear ModelProviderError ('Model output was truncated
at max_*_tokens=N; increase it or request shorter output'). Status code 400
is used deliberately: it is not in any retry list, and retrying the same
request would truncate identically.

Also adds an 'except ModelProviderError: raise' guard in the Anthropic
handler so the new error is not re-wrapped by the generic catch-all.
2026-07-06 15:17:52 -07:00
MagMueller 22939a2580 Revert "feat(llm/google): forward cached_content into generate_content (#4889)"
This reverts commit 5a745a8502, reversing
changes made to 640360e9b7.
2026-05-23 12:03:38 -07:00
Saurav Panda df063f9068 feat(llm/google): forward cached_content into generate_content
Adds a cached_content field on ChatGoogle (and a per-call kwarg on
ainvoke) that gets threaded into the GenerateContentConfigDict before
each generate_content call. This lets callers point Gemini at an
explicit CachedContent resource (e.g. "cachedContents/abc123") instead
of relying on implicit caching, which is constrained by the ~5-minute
TTL window.

Token accounting already pulls cached_content_token_count from
response.usage_metadata into ChatInvokeUsage.prompt_cached_tokens, so
the savings show up in usage stats without further work.

Cache creation itself (client.caches.create) is left to the caller —
this PR only adds the forwarding hook so explicit caching becomes
opt-in usable. A follow-up can wire agent-side cache lifecycle if
useful.
2026-05-22 17:54:04 -07:00
Saurav Panda 5ef0d9dbac feat(llm/google): add gemini-3.1-pro-preview to verified models
Routes through the existing Gemini 3 Pro thinking branch by extending
is_gemini_3_pro to match 'gemini-3.1-pro' alongside 'gemini-3-pro'.
2026-05-22 11:48:10 -07:00
Saurav Panda 9e8dfdd18f fix(llm/google): route gemini-3.1-flash through gemini-3 flash thinking branch 2026-05-22 10:50:35 -07:00
Saurav Panda 5c54ef4197 chore(llm): rename flash-lite recommendation to gemini-3.1-flash-lite 2026-05-22 10:49:12 -07:00
Saurav Panda b00c41b66b chore(llm): recommend gemini-3-flash-preview in examples and tests
- add gemini-3-flash-preview-lite to VerifiedGeminiModels and token mappings
- list both gemini-3-flash-preview[-lite] alongside existing -latest aliases in CLOUD.md and api-v2.md SupportedLLMs
- swap example code and recommendations (examples/, AGENTS.md, quickstart.md, bug report placeholder) to gemini-3-flash-preview / -lite
- update Google CI test + evaluate_tasks judge LLM to gemini-3-flash-preview / -lite
2026-05-22 10:47:58 -07:00
Mark McDonald 115199d2ba fix: handle types.HttpOptionsDict better, add more tests 2026-05-22 14:30:40 +08:00
Mark McDonald 2eb3e3cded feat: add client header to GoogleChat
Added header per integration
[guidelines](https://ai.google.dev/gemini-api/docs/partner-integration).
2026-05-22 14:20:24 +08:00
Mark McDonald 90783e69b4 fix: set default temperature to 1.0 for gemini-3 models 2026-03-23 14:13:08 +08:00
Saurav Panda 6d54f521cf set default gemini thinking to auto 2026-01-26 12:44:51 -08:00
Saurav Panda bb3b1e8cf5 added minimal model for gemini 3 flash 2026-01-23 15:11:13 -08:00
Saurav Panda 041d03a93f feat: updated the thinking budget 2026-01-23 14:42:59 -08:00
Saurav Panda 5b06f4edd9 set default thinking to 0 for gemini-3 models 2026-01-23 13:44:29 -08:00
Saurav Panda eb2382c7c4 added gemini 3 flash preview model 2025-12-18 11:25:23 -08:00
mertunsall dc0db88215 kv caching for BU agents 2025-12-15 18:23:22 -08:00
Saurav Panda 49882fb086 added gemini-3-pro-preview to verified models 2025-12-09 13:38:34 -08:00
Mert Unsal 4d87e49e1f Merge branch 'main' into mert/structured_output 2025-11-25 13:43:55 -08:00
mertunsall ed7cfa4ab2 fix title problem in schema as well as enum problems 2025-11-25 13:02:39 -08:00
mertunsall 84be050ed7 exponential retries improved 2025-11-25 11:18:03 -08:00
Magnus Müller af649d357a Retry 503 errors 2025-10-29 23:04:58 -07:00
Magnus Müller b27d7fe9d2 Retry 503 errors 2025-10-29 23:02:06 -07:00
Magnus Müller 9715c4e764 Linter 2025-10-29 17:14:45 -07:00
Magnus Müller 577c1ff148 Retry google on 403 error. 2025-10-29 16:51:32 -07:00
Magnus Müller 9caa248316 Merge code7 branch changes 2025-10-21 18:55:54 -07:00
Magnus Müller 98995449c2 reduce max_output_tokens gemini 2025-10-14 14:31:57 -07:00
Magnus Müller 3aaafa7bf8 Remove required from prompt 2025-10-05 20:30:36 -07:00
Magnus Müller a3a811e3be Remove create_gemini_optimized_schema 2025-10-05 19:03:10 -07:00
Magnus Müller 968414b982 Compress gemini schema 2025-10-05 12:48:25 -07:00
Magnus Müller 781f948bb8 change gemini 2.5 flash to gemini latest 2025-09-26 15:54:19 -07:00
Magnus Müller 6c7b5cd622 fix-gemini-thinking-budget-for-latest-lite-version 2025-09-26 12:09:03 -07:00
Magnus Müller 6d77cc6bb9 fix-gemini-thinking-budget-for-latest-version 2025-09-26 11:53:58 -07:00
Magnus Müller db27b32b04 fix gemini client 2025-09-26 09:50:01 -07:00
Magnus Müller cf0ad68b4c Merge branch 'speed-ups3' of https://github.com/browser-use/browser-use into speed-ups3 2025-09-22 18:37:59 -07:00
Magnus Müller 343b766b09 Comment 2025-09-22 18:37:57 -07:00
Magnus Müller c8e00e4511 Update browser_use/llm/google/chat.py
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2025-09-22 18:35:26 -07:00
Magnus Müller 5d749793ec Refactor model timeout logic and enhance ModelProviderError initialization 2025-09-22 16:02:03 -07:00
Magnus Müller d5ba9008b7 Update thinking_budget default value to 0 for flash and flash-lite models 2025-09-22 14:50:24 -07:00
Magnus Müller aa56461dbc Update thinking_budget default value to -1 for specific model 2025-09-20 07:23:17 -07:00
Magnus Müller 545dc86295 Include thinking_budget 0 2025-09-19 23:40:32 -07:00
Magnus Müller 13a83b7321 Include thinking_budget 600 2025-09-19 23:22:56 -07:00
Magnus Müller 382bbd45fc Include thinking_budget -1 2025-09-19 23:14:28 -07:00
Magnus Müller 653fa4206f Automaticlly set reasoning budget to 0 for 2.5 flash, because we do it with thinking for memory 2025-09-19 22:21:37 -07:00
Magnus Müller fbcde93cad Force no thinking 2025-09-19 19:40:33 -07:00
Magnus Müller af1fe232f1 Forse thinking -1 2025-09-19 19:39:18 -07:00
Magnus Müller 7e2d4de32c Timing 2025-09-19 19:36:53 -07:00