Uses the main agent's existing LLM provider to extract facts from
conversations, then stores them with infer=False — bypassing mem0's
default GPT-nano call.
- extract_facts(): sends conversation to provider.chat() with one-liner prompt
- store_facts(): stores each fact via mem0 with infer=False
- consolidate(): calls extract_facts + store_facts instead of add_conversation
Instead of hacking mem0's provider system, use the main agent's
existing LLM (already running, already paid for) to extract facts
from conversations, then store them with infer=False.
- extract_facts(): sends conversation to provider.chat() with extraction prompt
- store_facts(): stores each fact via mem0 with infer=False
- consolidate(): calls extract_facts + store_facts instead of add_conversation
- No new files, no Dockerfile changes, no mem0 package patches
**Root cause**: mem0 was being regenerated fresh each turn but never saved
to session, causing it to appear at different positions in the message
history and invalidating the cache prefix.
**Changes**:
1. Save mem0 injections to session (loop.py lines 574-581, 772-781)
- Fixed array indices: mem0 is at turn_start-3 and turn_start-2
- Makes mem0 part of immutable history at stable position
2. Add 4th cache breakpoint on message history (anthropic_oauth.py lines 340-368)
- BP3: Second-to-last user message (reuses BP4 from previous turn)
- BP4: Last user message (becomes BP3 next turn)
3. Raise clear_tool_uses trigger to 195k tokens (loop.py lines 52-57)
- Avoids premature cache invalidation for low-tool-use conversations
**Impact**: Cache writes dropped from ~30k to ~300 tokens per turn,
cache reads increased from 12k to 44k (reading full message history).
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When the LLM sends heredoc commands (cat << 'EOF'), the semicolon
sentinel (EOF; echo '<<exit>>') prevents bash from recognizing the
terminator, causing the session to hang until the 120s timeout.
Confirmed in production logs: the exact command that caused the hang.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add pool timeout (30s) to httpx client
- Add _reset_client() for connection error recovery
- Add _diagnose_connectivity() for ConnectTimeout debugging
- Catch ConnectTimeout/PoolTimeout specifically with diagnostics
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The old implementation used subprocess.Popen with asyncio.to_thread(readline)
in a loop with 1s timeouts. Each timed-out readline leaked a thread into the
default ThreadPoolExecutor. After ~20 leaked threads (from slow commands like
ffmpeg), the pool was completely exhausted — blocking DNS resolution and all
httpx connections indefinitely.
Rewritten to match Anthropic's reference implementation from
anthropic-quickstarts: asyncio.create_subprocess_shell + direct buffer
polling with asyncio.sleep(0.2). Zero threads used.
Also remove obsolete beta_flag from EditTool (no longer needed).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Windows 11 VM configuration was deleted, causing API requests with
the computer tool to hang indefinitely. Commenting out computer tool
registration until VM is restored.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add logger.exception() to capture full traceback
- Show exception type and message in error response
- Handle cases where str(e) is empty
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Log mem0_config keys passed from CLI to AgentLoop
- Log config keys received by Mem0MemoryStore
- Log extracted keys for MemoryConfig
- Log vector store provider after MemoryConfig creation
- Log facts extraction count in add_conversation
This instrumentation will reveal where the config chain breaks.
- Keep tool results (truncated to 2000 chars) sent as role: "user"
instead of skipping them entirely. mem0's parse_messages() ignores
"tool" role, and tool output often contains useful facts (file
reads, search results, web pages).
- Fix loop.py to call memory.consolidate() and return early when
using mem0, preventing fallthrough to old MemoryStore logic.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Dict comprehension with dict values fails as unhashable.
Replace with explicit loop to extract config fields.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fix A: Message pre-filtering in consolidate()
- Skip tool result messages (bash output, JSON blobs)
- Skip system messages (boilerplate instructions)
- Normalize Anthropic list-format content to plain text
- Skip trivially short messages (<10 chars like /new)
Fix B: Custom extraction prompt tuned for nanobot
- Extract from BOTH user and assistant messages
- 6 comprehensive examples (3 positive, 3 negative)
- Version 1.0 with date stamp
- Handles research, debugging, and technical work patterns
Expected improvement: 0 facts → 15-30 facts per session
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Import MemoryConfig from mem0.configs.base
- Create MemoryConfig object before passing to Memory()
- Fixes AttributeError: 'dict' object has no attribute 'custom_fact_extraction_prompt'
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Install nanobot with [mem0] extras
- Enables mem0ai and its dependencies in production build
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- New Mem0MemoryStore for semantic search with embeddings
- Update ContextBuilder to support mem0 backend
- Add mem0 config to schema
- Pass mem0_config through AgentLoop and CLI
- Add optional dependency mem0ai
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The memory.py file was added but not exported in __init__.py,
causing ImportError when enable_memory_tool is True.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Change enable_memory_tool default from False to True
- Update tests to reflect new default behavior
- Since this is a personal instance with no other users, opt-out
makes more sense than opt-in for a requested feature
- Add enable_memory_tool parameter to AgentLoop.__init__
- Memory tool only registered when flag is True
- 2 new integration tests in test_memory_integration.py, all passing
- Add enable_memory_tool field to ToolsConfig (default: False)
- Supports both snake_case and camelCase variants
- 3 new tests in test_memory_config.py, all passing
- Insert: add text at specific line number with validation
- Delete: remove files or directories recursively
- Rename: move/rename with collision detection
- All commands follow path security and CLIResult pattern
- 6 new tests in test_memory_commands.py, all passing
- Total 34 memory tests passing
Adds missing Callable and Awaitable imports from typing module.
These were referenced in type hints but not imported, causing
NameError at runtime.
Introduced in: e1987c7 (correlation store feature)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Removes leftover git conflict marker from queue.py line 92 that was
preventing module import and container startup.
Root cause: Merge conflict in e1987c7 was not fully resolved.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Switch from sentence-boundary splitting to upstream's simpler approach
- Uses max_len=4000 (safer buffer vs 4096 limit)
- Split priority: line breaks → spaces → hard cut
- Battle-tested implementation from HKUDS/nanobot upstream
- Simpler, more maintainable code
- Works better for both prose and code/logs
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add _send_text_chunks method to split messages at sentence boundaries
- Messages exceeding Telegram's 4096 character limit now send as multiple messages
- Per design doc: docs/plans/2026-02-27-openclaw-telegram-features-design.md
- All new tests pass (4/4), no regressions
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Complete implementation of all three native Anthropic tools:
- bash_20250124: Shell command execution
- text_editor_20250124: File editing operations
- computer_20251124: VNC desktop control (all 17 actions)
Includes provider updates, test improvements, and registry changes.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Registry now supports executing both native Anthropic tools (via __call__)
and function tools (via execute). Native tools return ToolResult/CLIResult
objects instead of strings.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add test confirming BashTool20250124, EditTool20250728, and
ComputerTool20251124 are registered in AgentLoop on initialization.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verify that screenshots from computer tool are tracked in
media_paths_for_turn and included in OutboundMessage.media.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Apply same result type handling logic to _process_system_message
to support native tools in subagent/system contexts.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replaced by BashTool20250124 and EditTool20250728 which provide
better functionality via model-trained behaviors.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
BashTool20250124, EditTool20250728, and ComputerTool20251124 are now
automatically registered alongside existing function tools.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Screenshots from computer tool are saved to disk and included in
OutboundMessage.media for channel delivery to users.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comprehensive tests for:
- ToolResult with output field
- ToolResult with error field
- ToolResult with base64_image field
- CLIResult handling
- Legacy string results (backward compatibility)
- Combined output and error fields
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Agent loop now processes ToolResult and CLIResult from native tools,
while maintaining backward compatibility with string results.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
CLIResult now requires exit_code, output, and error fields after
EditTool implementation. Update test to match new signature.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add computer_20251124 for VNC desktop control. Supports keyboard,
mouse, and screenshots via vncdotool.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add test_edit_tool_requires_absolute_path and test_edit_tool_to_params
to complete test coverage per specification.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Make test more specific by expecting exact sorted order
instead of checking both permutations.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>