feat: support skills creator and gemini models

This commit is contained in:
saboteur7
2026-01-30 18:00:10 +08:00
parent 49fb4034c6
commit dd6a9c26bd
30 changed files with 3562 additions and 833 deletions

View File

@@ -162,9 +162,16 @@ class Agent:
# DeepSeek
elif 'deepseek' in model_name:
return 64000
# Gemini models
elif 'gemini' in model_name:
if '2.0' in model_name or 'exp' in model_name:
return 2000000 # Gemini 2.0: 2M tokens
else:
return 1000000 # Gemini 1.5: 1M tokens
# Default conservative value
return 10000
return 128000
def _get_context_reserve_tokens(self) -> int:
"""
@@ -176,9 +183,10 @@ class Agent:
if self.context_reserve_tokens is not None:
return self.context_reserve_tokens
# Reserve ~20% of context window for new requests
# Reserve ~10% of context window, with min 10K and max 200K
context_window = self._get_model_context_window()
return max(4000, int(context_window * 0.2))
reserve = int(context_window * 0.1)
return max(10000, min(200000, reserve))
def _estimate_message_tokens(self, message: dict) -> int:
"""

View File

@@ -111,16 +111,20 @@ class AgentStreamExecutor:
if usage and 'input_tokens' in usage:
current_tokens = usage.get('input_tokens', 0)
context_window = self.agent._get_model_context_window()
reserve_tokens = self.agent.context_reserve_tokens or 20000
# Use configured reserve_tokens or calculate based on context window
reserve_tokens = self.agent._get_context_reserve_tokens()
# Use smaller soft_threshold to trigger flush earlier (e.g., at 50K tokens)
soft_threshold = 10000 # Trigger 10K tokens before limit
if self.agent.memory_manager.should_flush_memory(
current_tokens=current_tokens,
context_window=context_window,
reserve_tokens=reserve_tokens
reserve_tokens=reserve_tokens,
soft_threshold=soft_threshold
):
self._emit_event("memory_flush_start", {
"current_tokens": current_tokens,
"threshold": context_window - reserve_tokens - 4000
"threshold": context_window - reserve_tokens - soft_threshold
})
# TODO: Execute memory flush in background
@@ -385,6 +389,14 @@ class AgentStreamExecutor:
"execution_time": execution_time
}
# Auto-refresh skills after skill creation
if tool_name == "bash" and result.status == "success":
command = arguments.get("command", "")
if "init_skill.py" in command and self.agent.skill_manager:
logger.info("🔄 Detected skill creation, refreshing skills...")
self.agent.refresh_skills()
logger.info(f"✅ Skills refreshed! Now have {len(self.agent.skill_manager.skills)} skills")
self._emit_event("tool_execution_end", {
"tool_call_id": tool_id,
"tool_name": tool_name,