This repository was archived by the owner on Apr 30, 2026. It is now read-only.
Feat (2.1.10): add Agent mode and handlers for tools. - #6
Merged
Conversation
- Make box width dynamic based on content length - Remove fixed-width spacing that was causing overflow - Adjust padding properly for each line - Ensure box borders align correctly regardless of content length
- Add colorful box around model list (purple borders) - Highlight model numbers in green - Display model names in yellow with gray org prefix - Add visual arrow prompt for selection - Show checkmark/cross for valid/invalid selection feedback
Features: - Created /tools directory for custom tool plugins - Implemented ToolManager for dynamic tool loading - Added convert_to_tool_call() function for NL tool call conversion - Integrated tools system into ChatREPL workflow - Added /tools command to list available tools - Created weather_tool.py as example implementation How it works: 1. Tools are auto-detected from /tools directory 2. User input is checked for tool matches 3. LLM converts natural language to structured tool calls 4. Tool is executed with extracted parameters 5. Result is sent back to LLM for interpretation 6. Formatted response is displayed to user Example usage: - User: 'what is the weather in los angeles now?' - System: Detects weather_tool, executes, returns formatted result Includes: - xandai/utils/tool_manager.py - Core tool management - tools/weather_tool.py - Example weather tool - tools/__init__.py - Tools package initialization - tools/README.md - Tool creation guide - test_tools_system.py - Comprehensive test suite - TOOLS_GUIDE.md - Full documentation and examples - Updated xandai/chat.py with tool integration - Added /tools command to help menu
Major improvements:
1. **Stronger System Prompt**:
- Use <|system|>, <|user|>, <|assistant|> tags for better LLM guidance
- More explicit instructions: 'Your ONLY job is to return a JSON object'
- Clear rules about NO explanations, NO markdown, NO extra text
2. **Robust JSON Extraction**:
- Remove common LLM prefixes ('Here's the JSON:', 'Output:', etc.)
- Extract from markdown code blocks (`json or `)
- Find JSON object even if mixed with other text
- Try multiple regex patterns if simple extraction fails
- Validate JSON before accepting
3. **Better Debug Output**:
- Show raw response length
- Log each extraction step
- Show which method successfully found the JSON
4. **Cleaned up temporary files**:
- Removed debug_tool_prompt.py
- Removed test_real_llm_response.py
- Removed test_tool_detection.py
Why these changes:
The issue was that LLMs (especially smaller models) often don't follow
instructions perfectly and add explanatory text along with JSON. This
makes the JSON parsing fail silently, causing tools to never be invoked.
The new approach:
- Uses chat-style system tags that modern LLMs understand better
- Aggressively searches for JSON in the response
- Handles various formats LLMs might use
- Falls back gracefully if no tool matches
Test with:
xandai --verbose
> what is the weather in los angeles?
You should now see the tool being detected and executed!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the capacity to handle /agent command for chain-of-LLM calls.
Add the capacity to code internal tools (only internal on this version)
TO DO: add the capacity to add custom tools to the code agent