mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-31 06:20:12 +03:00
- Added `temperature` parameter to Chat API documentation with implementation notes - Improved code formatting in context_manager.py with consistent string quotes and line breaks - Added section on future runtime LLM parameter override capabilities - Updated API schemas to include temperature parameter (currently unused but reserved for future implementation)
Deprecated Context Manager
This directory contains the advanced context management implementation that has been replaced with a simplified version.
What's in Here
- context_manager.py (~650 lines)
- Accurate token counting using tiktoken
- Tool definition token estimation
- Custom message trimming with AIMessage + ToolMessage pairing
- Detailed logging and diagnostics
Why Was It Moved?
The advanced implementation was over-engineered for the current use case:
| Feature | Complexity | Necessity | Current Status |
|---|---|---|---|
| Template injection | Low | ✅ Essential | Kept (in new version) |
| Token counting (tiktoken) | High | ❓ Optional | Moved here |
| Message trimming | Medium | ❓ Optional | Simplified (LangChain native) |
| Tool token estimation | High | ❓ Optional | Moved here |
| AIMessage/ToolMessage pairing | High | ✅ Important | Moved here |
| 3 strategies (conservative/balanced/aggressive) | Low | ✅ Useful | Kept (in new version) |
When to Use This Implementation
Use the deprecated version if:
-
You need accurate token counting
- Your model has strict token limits
- You need to know exact token usage
- You're working with cost-sensitive applications
-
You have many tools
- Tool definitions consume significant tokens (500-1500 per tool)
- You need to account for tool tokens in context limit
-
You need AIMessage + ToolMessage pairing
- Your LLM requires tool calls and results to stay together
- You've encountered errors from orphaned ToolMessages
-
You need detailed diagnostics
- Debugging context limit issues
- Optimizing token usage
- Fine-tuning context strategy
Use the current simplified version if:
- ✅ You just need topology injection
- ✅ Your model has large context (128K+ tokens)
- ✅ Conversations are typically short (<50 turns)
- ✅ You don't need exact token counts
How to Restore the Advanced Version
If you find you need the advanced features:
# 1. Remove current simplified version
rm gns3server/agent/gns3_copilot/agent/context_manager.py
# 2. Restore from deprecated
cp gns3server/agent/gns3_copilot/deprecated/context_manager.py \
gns3server/agent/gns3_copilot/agent/context_manager.py
Key Differences
Simplified Version (Current)
# ~200 lines
- Uses LangChain's native trim_messages
- Simple token estimation (char count / 4)
- Template injection for topology
- 3 strategies: conservative/balanced/aggressive
Advanced Version (Deprecated)
# ~650 lines
- Custom trimming with AIMessage/ToolMessage pairing
- Accurate tiktoken-based token counting
- Tool definition token estimation
- Detailed logging with token breakdown
- Template injection for topology
- 3 strategies: conservative/balanced/aggressive
Performance Comparison
| Metric | Simplified | Advanced |
|---|---|---|
| Code size | ~200 lines | ~650 lines |
| Token accuracy | ~80% (estimation) | ~95%+ (tiktoken) |
| Trimming safety | Good | Excellent |
| Execution speed | Fast | Slower (tiktoken overhead) |
| Maintenance | Low | High |
Future Considerations
If the simplified version proves insufficient:
- Consider adding tiktoken back (but keep architecture simple)
- Use LangChain's more advanced trim_messages features
- Add optional tool token estimation
- Consider a hybrid approach: simple by default, advanced when needed
Moved: 2025-03-05 Reason: Simplification for current use case Status: Available for future use if needed