Skip to content
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
Aletech-Solutions merged 9 commits into
mainfrom
feat/tooling
Oct 29, 2025
Merged

Feat (2.1.10): add Agent mode and handlers for tools.#6
Aletech-Solutions merged 9 commits into
mainfrom
feat/tooling

Conversation

@Aletech-Solutions

Copy link
Copy Markdown
Contributor

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

- 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!
@Aletech-Solutions
Aletech-Solutions merged commit 3dd3e4e into main Oct 29, 2025
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants