Update .gitignore to exclude additional cache files; enhance tool documentation with optional message ID parameter
This commit is contained in:
175
memory-bank/fixes/tool_docs_update.md
Normal file
175
memory-bank/fixes/tool_docs_update.md
Normal file
@@ -0,0 +1,175 @@
|
||||
# LlamaTools Switch Configuration Fix
|
||||
|
||||
## Issue
|
||||
The bot is showing a warning about the LlamaTools sampling switch configuration having no end strings defined:
|
||||
```
|
||||
[SamplingSwitch] Warning: Config for switch 'llamaTools' has no end strings defined. Switch will only deactivates on an end-of-generation token.
|
||||
```
|
||||
|
||||
## Root Cause Analysis
|
||||
After reviewing the codebase:
|
||||
|
||||
1. Tool System Implementation:
|
||||
- tools.py: Defines core tool capabilities
|
||||
- tool_handler.py: Manages tool execution
|
||||
- event_handler.py: Processes tool usage in responses
|
||||
- system_prompt.yaml: Contains tool usage instructions
|
||||
|
||||
2. Current Implementation Issues:
|
||||
- No explicit tool usage boundaries defined
|
||||
- Natural language patterns used without clear markers
|
||||
- Relies on end-of-generation tokens for deactivation
|
||||
- Tool parsing is purely pattern-based
|
||||
|
||||
3. Configuration Spread:
|
||||
- Tool definitions in tools.py
|
||||
- Usage patterns in tool_handler.py
|
||||
- Instructions in system_prompt.yaml
|
||||
- No centralized switch configuration
|
||||
|
||||
## Detailed Implementation Plan
|
||||
|
||||
1. Add Tool Marker Configuration
|
||||
```python
|
||||
# In tools.py
|
||||
TOOL_MARKERS = {
|
||||
"start": "[TOOL:",
|
||||
"end": "[/TOOL]",
|
||||
"patterns": {
|
||||
"mention": {
|
||||
"start": "[TOOL:mention]",
|
||||
"end": "[/TOOL]"
|
||||
},
|
||||
"reaction": {
|
||||
"start": "[TOOL:reaction]",
|
||||
"end": "[/TOOL]"
|
||||
},
|
||||
"embed": {
|
||||
"start": "[TOOL:embed]",
|
||||
"end": "[/TOOL]"
|
||||
},
|
||||
"thread": {
|
||||
"start": "[TOOL:thread]",
|
||||
"end": "[/TOOL]"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Update Tool Parsing
|
||||
```python
|
||||
# In tool_handler.py
|
||||
def parse_tool_calls(self, response: str, **kwargs) -> Tuple[List[Tuple[str, Dict[str, Any]]], str]:
|
||||
tool_calls = []
|
||||
final_response = response
|
||||
|
||||
for tool_type, markers in TOOL_MARKERS["patterns"].items():
|
||||
pattern = f"{re.escape(markers['start'])}(.*?){re.escape(markers['end'])}"
|
||||
matches = re.finditer(pattern, response, re.DOTALL)
|
||||
|
||||
for match in matches:
|
||||
content = match.group(1).strip()
|
||||
if content:
|
||||
tool_calls.append((tool_type, self._parse_tool_content(tool_type, content)))
|
||||
final_response = final_response.replace(match.group(0), '')
|
||||
|
||||
return tool_calls, final_response.strip(), self.mentioned_users
|
||||
```
|
||||
|
||||
3. Update System Prompt
|
||||
```yaml
|
||||
# Update in system_prompt.yaml
|
||||
tools:
|
||||
content: >
|
||||
"Available Tools:
|
||||
|
||||
1. Mention Users:
|
||||
[TOOL:mention]@username[/TOOL]
|
||||
|
||||
2. React with Emojis:
|
||||
[TOOL:reaction]😠 💀 ⚔️[/TOOL]
|
||||
|
||||
3. Create Embeds:
|
||||
[TOOL:embed]
|
||||
Title here
|
||||
Content here
|
||||
[/TOOL]
|
||||
|
||||
4. Create Threads:
|
||||
[TOOL:thread]Topic or comparison here[/TOOL]"
|
||||
```
|
||||
|
||||
4. Add Tool Validation
|
||||
```python
|
||||
# In tool_handler.py
|
||||
def validate_tool_response(self, response: str) -> bool:
|
||||
"""Validate proper tool marker closure."""
|
||||
stack = []
|
||||
|
||||
# Find all tool markers
|
||||
markers = re.finditer(r'\[(?:TOOL:\w+|\/?TOOL)\]', response)
|
||||
|
||||
for match in markers:
|
||||
marker = match.group(0)
|
||||
if marker.startswith('[TOOL:'):
|
||||
stack.append(marker)
|
||||
elif marker == '[/TOOL]':
|
||||
if not stack:
|
||||
return False # End marker without start
|
||||
stack.pop()
|
||||
|
||||
return len(stack) == 0 # All markers should be properly closed
|
||||
```
|
||||
|
||||
## Testing Requirements
|
||||
|
||||
1. Tool Marker Testing:
|
||||
- Test proper tool section detection
|
||||
- Verify marker closure validation
|
||||
- Check nested tool usage handling
|
||||
|
||||
2. Integration Testing:
|
||||
- Test tool parsing with new markers
|
||||
- Verify response formatting
|
||||
- Check tool execution flow
|
||||
|
||||
3. Edge Cases:
|
||||
- Malformed tool markers
|
||||
- Missing end markers
|
||||
- Invalid tool types
|
||||
- Nested tool usage
|
||||
|
||||
## Implementation Steps
|
||||
|
||||
1. Code Changes:
|
||||
- Implement TOOL_MARKERS configuration
|
||||
- Update parse_tool_calls method
|
||||
- Add validation logic
|
||||
- Update system prompt
|
||||
|
||||
2. Testing:
|
||||
- Unit tests for new functionality
|
||||
- Integration tests with the bot
|
||||
- Edge case validation
|
||||
|
||||
3. Documentation:
|
||||
- Update tool usage documentation
|
||||
- Add examples with new syntax
|
||||
- Document validation rules
|
||||
|
||||
## Status
|
||||
Ready for implementation. Changes have been fully mapped out and documented.
|
||||
|
||||
## Impact
|
||||
These changes will:
|
||||
- Remove the sampling switch warning
|
||||
- Provide explicit tool usage boundaries
|
||||
- Improve parsing reliability
|
||||
- Make tool usage more maintainable
|
||||
- Allow for better error handling
|
||||
|
||||
## Next Steps
|
||||
1. Create implementation PR
|
||||
2. Add unit tests
|
||||
3. Update documentation
|
||||
4. Deploy and monitor
|
||||
Reference in New Issue
Block a user