ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
System state tracking for the coding agent
|
||||
"""
|
||||
|
||||
import os
|
||||
import platform
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict, Any, List
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@dataclass
|
||||
class SystemState:
|
||||
"""System state tracking for system hints"""
|
||||
current_directory: str = field(default_factory=lambda: os.getcwd())
|
||||
tool_call_counts: Dict[str, int] = field(default_factory=dict)
|
||||
todos: List[Dict[str, Any]] = field(default_factory=list)
|
||||
shell_sessions: Dict[str, Any] = field(default_factory=dict)
|
||||
default_shell_id: str = "default"
|
||||
# Byte offset already returned by BashOutput, per bash_id, so each call can
|
||||
# return "only new output since the last check" as the tool documents.
|
||||
bash_output_offsets: Dict[str, int] = field(default_factory=dict)
|
||||
os_type: str = field(default_factory=lambda: platform.system())
|
||||
python_version: str = field(default_factory=lambda: f"Python {platform.python_version()}")
|
||||
|
||||
def get_system_hint(self) -> str:
|
||||
"""Generate system hint message to append to context"""
|
||||
hint_parts = []
|
||||
|
||||
# Environment information
|
||||
hint_parts.append("# System State")
|
||||
hint_parts.append(f"Current Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
||||
hint_parts.append(f"Working Directory: {self.current_directory}")
|
||||
hint_parts.append(f"OS: {self.os_type}")
|
||||
hint_parts.append(f"Python: {self.python_version}")
|
||||
|
||||
# Tool call statistics
|
||||
if self.tool_call_counts:
|
||||
hint_parts.append("\n# Tool Call Statistics")
|
||||
for tool, count in sorted(self.tool_call_counts.items()):
|
||||
hint_parts.append(f"- {tool}: {count} calls")
|
||||
if count >= 3:
|
||||
hint_parts.append(f" ⚠️ Tool '{tool}' has been called {count} times. Consider alternative approaches.")
|
||||
|
||||
# TODO list
|
||||
if self.todos:
|
||||
hint_parts.append("\n# Current TODO List")
|
||||
for todo in self.todos:
|
||||
status_icon = {"pending": "⬜", "in_progress": "🔄", "completed": "✅"}[todo["status"]]
|
||||
hint_parts.append(f"{status_icon} [{todo['id']}] {todo['content']} ({todo['status']})")
|
||||
|
||||
return "\n".join(hint_parts)
|
||||
|
||||
Reference in New Issue
Block a user