Commit Graph

157 Commits

Author SHA1 Message Date
zhangxiaoyu.york
f72ceb7a3c fix:set subagent result message role = assistant 2026-03-18 00:43:46 +08:00
Xubin Ren
8cf11a0291 fix: preserve image paths in fallback and session history 2026-03-17 22:37:09 +08:00
Xubin Ren
46b19b15e1 perf: background post-response memory consolidation for faster replies 2026-03-16 09:01:11 +00:00
Xubin Ren
6d63e22e86 Merge remote-tracking branch 'origin/main' into pr-1961
Made-with: Cursor

# Conflicts:
#	.gitignore
2026-03-16 08:47:28 +00:00
Xubin Ren
b29275a1d2 refactor(/new): background archival with guaranteed persistence
Replace fire-and-forget consolidation with archive_messages(), which
retries until the raw-dump fallback triggers — making it effectively
infallible. /new now clears the session immediately and archives in
the background. Pending archive tasks are drained on shutdown via
close_mcp() so no data is lost on process exit.
2026-03-16 16:40:09 +08:00
chengyongru
9820c87537 fix(loop): restore /new immediate return with safe background consolidation
PR #881 (commit 755e424) fixed the race condition between normal consolidation
and /new consolidation, but did so by making /new wait for consolidation to
complete before returning. This hurts user experience - /new should be instant.

This PR restores the original immediate-return behavior while keeping safety:

1. **Immediate return**: Session clears and user sees "New session started" right away
2. **Background archival**: Consolidation runs in background via asyncio.create_task
3. **Serialized consolidation**: Uses the same lock as normal consolidation via
   `memory_consolidator.get_lock()` to prevent concurrent writes

If consolidation fails after session clear, archived messages may be lost.
This is acceptable because:
- User already sees the new session and can continue working
- Failure is logged for debugging
- The alternative (blocking /new on every call) hurts UX for all users
2026-03-16 16:40:09 +08:00
Xubin Ren
d684fec27a Replace load_skill tool with read_file extra_allowed_dirs for builtin skills access
Instead of adding a separate load_skill tool to bypass workspace restrictions,
extend ReadFileTool with extra_allowed_dirs so it can read builtin skill paths
while keeping write/edit tools locked to the workspace. Fixes the original issue
for both main agent and subagents.

Made-with: Cursor
2026-03-15 23:21:02 +08:00
Ben
45832ea499 Add load_skill tool to bypass workspace restriction for builtin skills
When restrictToWorkspace is enabled, the agent cannot read builtin skill
files via read_file since they live outside the workspace. This adds a
dedicated load_skill tool that reads skills by name through the SkillsLoader,
which accesses files directly via Python without the workspace restriction.

- Add LoadSkillTool to filesystem tools
- Register it in the agent loop
- Update system prompt to instruct agent to use load_skill instead of read_file
- Remove raw filesystem paths from skills summary
2026-03-15 23:21:02 +08:00
Xubin Ren
19ae7a167e fix(feishu): avoid breaking tool hint formatting and think stripping 2026-03-14 15:40:53 +00:00
Xubin Ren
44af7eca3f merge: resolve PR #1966 conflicts with main 2026-03-14 15:32:19 +00:00
chengyongru
a2acacd8f2 fix: add exception handling to prevent agent loop crash 2026-03-14 18:34:22 +08:00
Tony
2787523f49 fix: prevent empty </think> tags from appearing in messages
- Enhance _strip_think to handle stray tags:
  * Remove unmatched closing tags (</think>)
  * Remove incomplete blocks (<think> ... to end of string)
- Apply _strip_think to tool hint messages as well
- Prevents blank/parse errors from showing </think> in chat outputs

Fixes issue with empty </think> appearing in Feishu tool call cards and other messages.
2026-03-13 14:55:34 +08:00
Tony
d286926f6b feat(memory): implement async background consolidation
Implement asynchronous memory consolidation that runs in the background when
sessions are idle, instead of blocking user interactions after each message.

Changes:
- MemoryConsolidator: Add background task management with idle detection
  * Track session activity timestamps
  * Background loop checks idle sessions every 30s
  * Consolidation triggers only when session idle > 60s
- AgentLoop: Integrate background task lifecycle
  * Start consolidation task when loop starts
  * Stop gracefully on shutdown
  * Record activity on each message
- Refactor maybe_consolidate_by_tokens: Keep sync API but schedule async
- Add debug logging for consolidation completion

Benefits:
- Non-blocking: Users no longer wait for consolidation after responses
- Efficient: Only consolidate idle sessions, avoiding redundant work
- Scalable: Background task can process multiple sessions efficiently
- Backward compatible: Existing API unchanged

Tests: 11 new tests covering background task lifecycle, idle detection,
scheduling, and error handling. All passing.

🤖 Generated with Claude Code
2026-03-13 13:52:36 +08:00
Xubin Ren
ca5047b602 feat(web): multi-provider web search + Jina Reader fetch 2026-03-13 05:44:16 +00:00
Xubin Ren
62a2e71748 Merge PR #1958: fix(restart): use -m nanobot for Windows compatibility
fix(restart): use -m nanobot for Windows compatibility
2026-03-13 11:19:57 +08:00
chengyongru
6ad30f12f5 fix(restart): use -m nanobot for Windows compatibility
On Windows, sys.argv[0] may be just "nanobot" without full path when
running from PATH. os.execv() doesn't search PATH, causing restart to
fail with "No such file or directory".

Fix by using `python -m nanobot` instead of relying on sys.argv[0].

Fixes #1937
2026-03-13 11:01:01 +08:00
chengyongru
127ac39063 fix: catch BaseException in MCP connection to handle CancelledError 2026-03-13 10:23:15 +08:00
Re-bin
64aeeceed0 Add /restart command: restart the bot process from any channel 2026-03-12 04:33:51 +00:00
Re-bin
231b02963d Merge branch 'main' into pr-1751
Made-with: Cursor

# Conflicts:
#	nanobot/agent/loop.py
2026-03-12 03:53:59 +00:00
Re-bin
35260ca157 fix: raise persisted tool result limit to 16k 2026-03-12 02:50:28 +00:00
Re-bin
9fc74bde9a Merge remote-tracking branch 'origin/main' into pr-1874 2026-03-11 15:26:39 +00:00
Re-bin
c72c2ce7e2 refactor: move generation settings to provider level, eliminate parameter passthrough 2026-03-11 09:47:04 +00:00
WhalerO
6ef7ab53d0 refactor: centralize tool call serialization in ToolCallRequest 2026-03-11 15:32:43 +08:00
WhalerO
ed82f95f0c fix: preserve provider-specific tool call metadata for Gemini 2026-03-11 15:32:26 +08:00
ethanclaw
12104c8d46 fix(memory): pass temperature, max_tokens and reasoning_effort to memory consolidation
Fix issue #1823: Memory consolidation does not inherit agent temperature
and maxTokens configuration.

The agent's configured generation parameters were not being passed through
to the memory consolidation call, causing it to fall back to default values.
This resulted in the consolidation response being truncated before the
save_memory tool call was emitted.

- Pass temperature, max_tokens, reasoning_effort from AgentLoop to
  MemoryConsolidator and then to MemoryStore.consolidate()
- Forward these parameters to the provider.chat_with_retry() call

Fixes #1823
2026-03-11 14:22:33 +08:00
Re-bin
62ccda43b9 refactor(memory): switch consolidation to token-based context windows
Move consolidation policy into MemoryConsolidator, keep backward compatibility for legacy config, and compress history by token budget instead of message count.
2026-03-10 19:55:06 +00:00
Re-bin
4784eb4128 merge origin/main into pr-1704 2026-03-10 18:09:15 +00:00
Re-bin
b0a5435b87 refactor(llm): share transient retry across agent paths 2026-03-10 10:10:37 +00:00
Re-bin
46b31ce7e7 Merge remote-tracking branch 'origin/main' into pr-1512 2026-03-10 09:40:48 +00:00
Renato Machado
85c56d7410 feat: add "restart" command 2026-03-09 01:37:35 +00:00
VITOHJL
274edc5451 fix(compression): prefer provider prompt token usage 2026-03-08 17:25:59 +08:00
VITOHJL
1b16d48390 fix(loop): update _cumulative_tokens in _save_turn and preserve it in compression methods 2026-03-08 15:26:49 +08:00
VITOHJL
a984e0df37 feat(loop): add history message count logging in compression 2026-03-08 15:23:55 +08:00
VITOHJL
dbc518098e refactor: implement token-based context compression mechanism
Major changes:
- Replace message-count-based memory window with token-budget-based compression
- Add max_tokens_input, compression_start_ratio, compression_target_ratio config
- Implement _maybe_compress_history() that triggers based on prompt token usage
- Use _build_compressed_history_view() to provide compressed history to LLM
- Refactor MemoryStore.consolidate() -> consolidate_chunk() for chunk-based compression
- Remove last_consolidated from Session, use _compressed_until metadata instead
- Add background compression scheduling to avoid blocking message processing

Key improvements:
- Compression now based on actual token usage, not arbitrary message counts
- Better handling of long conversations with large context windows
- Non-destructive compression: old messages remain in session, but excluded from prompt
- Automatic compression when history exceeds configured token thresholds
2026-03-08 14:20:16 +08:00
Re-bin
43fc59da00 fix: hide internal reasoning in progress 2026-03-07 14:53:14 +00:00
VITOHJL
cf76011c1a fix: hide reasoning_content from user progress updates 2026-03-07 17:09:59 +08:00
Re-bin
d32c6f946c fix(telegram): pin ptb>=22.6, fix double progress, clean up stale hatch config 2026-03-05 15:17:30 +00:00
Sergio Sánchez Vallés
33f59d8a37 fix(agent): separate reasoning and tool hints to respect channel config 2026-03-05 00:45:15 +01:00
Sergio Sánchez Vallés
c27d2b1522 fix(agent): prevent tool hints from overwriting reasoning in streaming drafts 2026-03-05 00:33:27 +01:00
Sergio Sánchez Vallés
61f658e045 add reasoning content to on progress message 2026-03-04 12:11:18 +01:00
Kiplangatkorir
d0c6479186 feat: add LLM retry with exponential backoff for transient errors
provider.chat() had no retry logic — a transient 429 rate limit,
502 gateway error, or network timeout would permanently fail the
entire message. For a system running cron jobs and heartbeats 24/7,
even a brief provider blip causes lost tasks.

Adds _chat_with_retry() that:
- Retries up to 3 times with 1s/2s/4s exponential backoff
- Only retries transient errors (429, 5xx, timeout, connection)
- Returns immediately on permanent errors (400, 401, etc.)
- Falls through to the final attempt if all retries exhaust
2026-03-04 11:20:50 +03:00
Re-bin
03b83fb79e fix(agent): skip empty multimodal user entries after runtime-context strip 2026-03-03 05:13:17 +00:00
Nikolas de Hor
ad99d5aaa0 fix: merge consecutive user messages into single message
Some LLM providers (Minimax, Dashscope) strictly reject consecutive
messages with the same role. build_messages() was emitting two separate
user messages back-to-back: the runtime context and the actual user
content.

Merge them into a single user message, handling both plain text and
multimodal (image) content. Update _save_turn() to strip the runtime
context prefix from the merged message when persisting to session
history.

Fixes #1414
Fixes #1344
2026-03-03 00:59:58 -03:00
chengyongru
82be2ae1a5 feat(tool): add web search proxy 2026-03-01 16:51:54 +08:00
Re-bin
5ca386ebf5 fix: preserve reasoning_content and thinking_blocks in session history 2026-02-28 17:37:12 +00:00
Re-bin
f9d72e2e74 feat: add reasoning_effort config to enable LLM thinking mode 2026-02-28 17:18:05 +00:00
Re-bin
8410f859f7 refactor: use WeakValueDictionary for consolidation locks — auto-cleanup, no manual pop 2026-02-28 08:26:55 +00:00
Re-bin
89c0f4cae9 refactor: compress tool hint args handling to two lines 2026-02-28 08:06:20 +00:00
Re-bin
90eb90335a Merge remote-tracking branch 'origin/main' into pr-1294 2026-02-28 08:01:04 +00:00
Re-bin
0036116e0b fix: filter empty assistant messages in _save_turn instead of patching at send time 2026-02-28 07:35:07 +00:00