Commit Graph
200 Commits
Author SHA1 Message Date
Xubin Ren 2bef9cb650 fix(agent): preserve interrupted tool-call turns
Keep tool-call assistant messages valid across provider sanitization and avoid trailing user-only history after model errors. This prevents follow-up requests from sending broken tool chains back to the gateway.
2026-04-10 05:37:25 +00:00
Xubin Ren dadf453097 Merge origin/main into fix/sanitize-messages-non-claude
Resolved conflict in azure_openai_provider.py by keeping main's
Responses API implementation (role alternation not needed for the
Responses API input format).

Made-with: Cursor
2026-04-09 04:45:45 +00:00
Xubin Ren d084d10dc2 feat(openai): auto-route direct reasoning requests with responses fallback 2026-04-08 15:21:08 +00:00
moranfongandXubin Ren 12ff8b22d6 fix(provider): extend StepFun reasoning fallback to all code paths
- Add reasoning_content fallback from reasoning in _parse dict branch
- Add content fallback from msg.reasoning in _parse SDK object branch
- Add reasoning_content fallback in _parse SDK object branch
- Add reasoning fallback in _parse_chunks dict branch
- Add reasoning fallback in _parse_chunks SDK object branch

This ensures StepFun Plan API works correctly in both streaming and
non-streaming modes, for both dict and SDK object response formats.
2026-04-08 00:59:39 +08:00
moranfongandXubin Ren 53107c6683 fix(provider): support StepFun Plan API reasoning field fallback
StepFun Plan API returns response content in the 'reasoning' field when
the model is in thinking mode and 'content' is empty. OpenAICompatProvider
previously only checked 'content' and 'reasoning_content', missing this field.

This patch adds a fallback: if content is empty and 'reasoning' is present,
extract text from reasoning to populate content, ensuring StepFun models
(step-3.5-flash, step-3.5-flash-2603) work correctly with tool calls.

Co-authored-by: moranfong <moranfong@gmail.com>
2026-04-08 00:59:39 +08:00
Balor.LC3andXubin Ren 1c2f4aba17 feat(anthropic): add adaptive thinking mode
Extends reasoning_effort to accept 'adaptive' in addition to
low/medium/high. When set, uses Anthropic's type: 'adaptive'
thinking API instead of a fixed budget, letting the model decide
when and how much to think per turn.

Also auto-enables interleaved thinking between tool calls on
claude-sonnet-4-6 and claude-opus-4-6.

Usage:
  "reasoning_effort": "adaptive" in agents.defaults config
2026-04-07 22:53:43 +08:00
Xubin Ren 35f53a721d refactor: consolidate _parse_retry_after_headers into base class
Merge the three retry-after header parsers (base, OpenAI, Anthropic)
into a single _extract_retry_after_from_headers on LLMProvider that
handles retry-after-ms, case-insensitive lookup, and HTTP date.

Remove the per-provider _parse_retry_after_headers duplicates and
their now-unused email.utils / time imports. Add test for retry-after-ms.

Made-with: Cursor
2026-04-06 08:44:52 +00:00
Xubin Ren aeba9a23e6 refactor: remove dead _error_response wrapper in Anthropic provider
Fold _error_response back into _handle_error to match OpenAI/Azure
convention. Update all call sites and tests accordingly.

Made-with: Cursor
2026-04-06 08:35:02 +00:00
Xubin Ren b575aed20e Merge origin/main into fix/structured-retry-classification-main
Made-with: Cursor
2026-04-06 08:28:20 +00:00
Xubin RenandXubin Ren ebf29d87ae fix: include byteplus providers, guard None reasoning_effort, merge extra_body
- Add byteplus and byteplus_coding_plan to thinking param providers
- Only send extra_body when reasoning_effort is explicitly set
- Use setdefault().update() to avoid clobbering existing extra_body
- Add 7 regression tests for thinking params

Made-with: Cursor
2026-04-06 16:12:08 +08:00
PlayDustinDBandXubin Ren bd94454b91 feat(think): adjust thinking method for dashscope and modelark 2026-04-06 16:12:08 +08:00
Xubin Ren 7b7a3e5748 fix: media_paths NameError, import order, add error logging and tests
- Move media_paths assignment before voice message handling to prevent
  NameError at runtime
- Fix broken import layout in transcription.py (httpx/loguru after class)
- Add error logging to OpenAITranscriptionProvider matching Groq style
- Add regression tests for voice transcription and no-media fallback

Made-with: Cursor
2026-04-06 06:01:14 +00:00
Xubin Ren 413740f585 Merge remote-tracking branch 'origin/main' into pr-2530
Made-with: Cursor

# Conflicts:
#	nanobot/channels/whatsapp.py
2026-04-06 05:59:31 +00:00
Xubin RenandXubin Ren f82b5a1b02 fix: graceful fallback when langfuse is not installed
- Use import importlib.util (not bare importlib) for find_spec
- Warn and fall back to standard openai instead of crashing with
  ImportError when LANGFUSE_SECRET_KEY is set but langfuse is missing

Made-with: Cursor
2026-04-06 13:53:42 +08:00
lang07123andXubin Ren 4e06e12ab6 feat(provider): 添加 Langfuse 观测平台的集成支持
feat(provider): 添加 Langfuse 观测平台的集成支持
2026-04-06 13:53:42 +08:00
chengyongruandXubin Ren 5479a44691 fix: stop leaking reasoning_content to stream output
The streaming path in OpenAICompatProvider.chat_stream() was passing
reasoning_content deltas through on_content_delta(), causing model
internal reasoning to be displayed to the user alongside the actual
response content.

reasoning_content is already collected separately in _parse_chunks()
and stored in LLMResponse.reasoning_content for session history.
It should never be forwarded to the user-facing stream.
2026-04-05 17:27:14 +08:00
JiajunandXubin Ren 7e1ae3eab4 feat(provider): add Qianfan provider support (#2699) 2026-04-05 16:52:37 +08:00
Xubin Ren 77a88446fb Merge remote-tracking branch 'origin/main' into pr-2722 2026-04-04 13:51:59 +00:00
Xubin RenandXubin Ren 17d9d74ccc fix(provider): omit temperature for GPT-5 models 2026-04-04 20:18:22 +08:00
7dc8c9409c feat(providers): add GPT-5 model family support for OpenAI provider
Enable GPT-5 models (gpt-5, gpt-5.4, gpt-5.4-mini, etc.) to work
correctly with the OpenAI-compatible provider by:

- Setting `supports_max_completion_tokens=True` on the OpenAI provider
  spec so `max_completion_tokens` is sent instead of the deprecated
  `max_tokens` parameter that GPT-5 rejects.
- Adding `_supports_temperature()` to conditionally omit the
  `temperature` parameter for reasoning models (o1/o3/o4) and when
  `reasoning_effort` is active, matching the existing Azure provider
  behaviour.

Both changes are backward-compatible: older GPT-4 models continue to
work as before since `max_completion_tokens` is accepted by all recent
OpenAI models and temperature is only omitted when reasoning is active.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 20:18:22 +08:00
Lingao MengandXubin Ren 3f8eafc89a fix(provider): restore reasoning_content and extra_content in message sanitization
reasoning_content and extra_content were accidentally dropped from
_ALLOWED_MSG_KEYS.

Also fix session/manager.py to include reasoning_content when building
LLM messages from session history, so the field is not lost across
turns.

Without this fix, providers such as Kimi, emit reasoning_content in
assistant messages will have it stripped on the next request, breaking
multi-turn thinking mode.

Fixes: https://github.com/HKUDS/nanobot/issues/2777
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-04-04 20:08:44 +08:00
pikaxinge 31d3061a0a fix(retry): classify 429 as WAIT vs STOP using semantic signals 2026-04-04 05:23:21 +00:00
pikaxinge cabf093915 Merge remote-tracking branch 'origin/main' into fix/structured-retry-classification-main
# Conflicts:
#	nanobot/providers/anthropic_provider.py
#	nanobot/providers/base.py
#	nanobot/providers/openai_compat_provider.py
2026-04-04 05:04:43 +00:00
Xubin RenandXubin Ren 7229a81594 fix(providers): disable Azure SDK retries by default
Made-with: Cursor
2026-04-04 12:36:45 +08:00
pikaxingeandXubin Ren dbdf7e5955 fix: prevent retry amplification by disabling SDK retries 2026-04-04 12:36:45 +08:00
Xubin Ren 91a9b7db24 Merge origin/main into fix/retry-after-robust
Made-with: Cursor
2026-04-03 19:07:30 +00:00
Lingao MengandXubin Ren 210643ed68 feat(provider): support reasoning_content in OpenAI compat provider
Extract reasoning_content from both non-streaming and streaming responses
in OpenAICompatProvider. Accumulate chunks during streaming and merge into
LLMResponse, enabling reasoning chain display for models like MiMo and DeepSeek-R1.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-04-04 02:09:57 +08:00
Lingao Meng cf6c979339 feat(provider): add Xiaomi MiMo LLM support
Register xiaomi_mimo as an OpenAI-compatible provider with its API base URL,
add xiaomi_mimo to the provider config schema, and document it in README.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-04-03 14:42:57 +08:00
pikaxinge b951b37c97 fix: use structured error metadata for app-layer retry 2026-04-02 18:42:20 +00:00
pikaxinge 5d1ea43858 fix: robust Retry-After extraction across provider backends 2026-04-02 18:39:24 +00:00
Xubin Ren 714a4c7bb6 fix(runtime): address review feedback on retry and cleanup 2026-04-02 10:57:12 +00:00
Xubin Ren eefd7e60f2 Merge remote-tracking branch 'origin/main' into feat/runtime-hardening 2026-04-02 10:40:49 +00:00
pikaxinge 87d493f354 refactor: deduplicate tool cache marker helper in base provider 2026-04-02 07:29:07 +00:00
Xubin RenandXubin Ren cc33057985 refactor(providers): rename openai responses helpers 2026-04-02 13:43:34 +08:00
Xubin RenandXubin Ren ded0967c18 fix(providers): sanitize azure responses input messages 2026-04-02 13:43:34 +08:00
Kunal KarmakarandXubin Ren e206cffd7a Add tests and handle json 2026-04-02 13:43:34 +08:00
Kunal KarmakarandXubin Ren ac2ee58791 Add tests and logs 2026-04-02 13:43:34 +08:00
Kunal KarmakarandXubin Ren 7c44aa92ca Fill up gaps 2026-04-02 13:43:34 +08:00
Kunal KarmakarandXubin Ren 8c0607e079 Use SDK for stream 2026-04-02 13:43:34 +08:00
Kunal KarmakarandXubin Ren 0417c3f03b Use OpenAI responses API 2026-04-02 13:43:34 +08:00
Xubin RenandXubin Ren a3e4c77fff fix(providers): normalize anthropic cached token usage 2026-04-02 12:51:45 +08:00
chengyongruandXubin Ren da08dee144 feat(provider): show cache hit rate in /status (#2645) 2026-04-02 12:51:45 +08:00
Tejas1KoliandXubin Ren 42fa8fa933 fix(providers): only apply cache_control for Claude models on OpenRouter 2026-04-02 04:04:18 +08:00
Tejas1KoliandXubin Ren 05fe73947f fix(providers): only apply cache_control for Claude models on OpenRouter 2026-04-02 04:04:18 +08:00
RongLeiandXubin Ren c5f0997381 fix: refresh copilot token before requests
Address PR review feedback by avoiding an async method reference as the OpenAI client api_key.

Initialize the client with a placeholder key, refresh the Copilot token before each chat/chat_stream call, and update the runtime client api_key before dispatch.

Add a regression test that verifies the client api_key is refreshed to a real string before chat requests.

Generated with GitHub Copilot, GPT-5.4.
2026-04-02 03:46:40 +08:00
RongLeiandXubin Ren a37bc26ed3 fix: restore GitHub Copilot auth flow
Implement the real GitHub device flow and Copilot token exchange for the GitHub Copilot provider.

Also route github-copilot models through a dedicated backend and strip the provider prefix before API requests.

Add focused regression coverage for provider wiring and model normalization.

Generated with GitHub Copilot, GPT-5.4.
2026-04-02 03:46:40 +08:00
Xubin Ren fbedf7ad77 feat: harden agent runtime for long-running tasks 2026-04-01 19:12:49 +00:00
pikaxinge 607fd8fd7e fix(cache): stabilize tool ordering and cache markers for MCP 2026-04-01 17:07:22 +00:00
Ziyan Lin 26ae906116 fix(providers): enforce role alternation for non-Claude providers
Some LLM providers (OpenAI-compat, Azure, vLLM, Ollama) reject requests
with consecutive same-role messages or trailing assistant messages. Add
_enforce_role_alternation() to merge consecutive same-role user/assistant
messages and strip trailing assistant messages before sending to the API.
2026-03-30 15:15:15 +08:00
FloandXubin Ren 1331084873 fix(providers): make max_tokens and max_completion_tokens mutually exclusive (#2491)
* fix(providers): make max_tokens and max_completion_tokens mutually exclusive

* docs: document supports_max_completion_tokens ProviderSpec option
2026-03-27 21:19:23 +08:00