Merge branch 'main' into pr-1107
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import base64
|
||||
import mimetypes
|
||||
import platform
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -72,10 +74,6 @@ Skills with available="false" need dependencies installed first - you can try in
|
||||
|
||||
def _get_identity(self) -> str:
|
||||
"""Get the core identity section."""
|
||||
from datetime import datetime
|
||||
import time as _time
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M (%A)")
|
||||
tz = _time.strftime("%Z") or "UTC"
|
||||
workspace_path = str(self.workspace.expanduser().resolve())
|
||||
system = platform.system()
|
||||
runtime = f"{'macOS' if system == 'Darwin' else system} {platform.machine()}, Python {platform.python_version()}"
|
||||
@@ -84,9 +82,6 @@ Skills with available="false" need dependencies installed first - you can try in
|
||||
|
||||
You are nanobot, a helpful AI assistant.
|
||||
|
||||
## Current Time
|
||||
{now} ({tz})
|
||||
|
||||
## Runtime
|
||||
{runtime}
|
||||
|
||||
@@ -108,6 +103,23 @@ Reply directly with text for conversations. Only use the 'message' tool to send
|
||||
## Memory
|
||||
- Remember important facts: write to {workspace_path}/memory/MEMORY.md
|
||||
- Recall past events: grep {workspace_path}/memory/HISTORY.md"""
|
||||
|
||||
@staticmethod
|
||||
def _inject_runtime_context(
|
||||
user_content: str | list[dict[str, Any]],
|
||||
channel: str | None,
|
||||
chat_id: str | None,
|
||||
) -> str | list[dict[str, Any]]:
|
||||
"""Append dynamic runtime context to the tail of the user message."""
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M (%A)")
|
||||
tz = time.strftime("%Z") or "UTC"
|
||||
lines = [f"Current Time: {now} ({tz})"]
|
||||
if channel and chat_id:
|
||||
lines += [f"Channel: {channel}", f"Chat ID: {chat_id}"]
|
||||
block = "[Runtime Context]\n" + "\n".join(lines)
|
||||
if isinstance(user_content, str):
|
||||
return f"{user_content}\n\n{block}"
|
||||
return [*user_content, {"type": "text", "text": block}]
|
||||
|
||||
def _load_bootstrap_files(self) -> str:
|
||||
"""Load all bootstrap files from workspace."""
|
||||
@@ -148,8 +160,6 @@ Reply directly with text for conversations. Only use the 'message' tool to send
|
||||
|
||||
# System prompt
|
||||
system_prompt = self.build_system_prompt(skill_names)
|
||||
if channel and chat_id:
|
||||
system_prompt += f"\n\n## Current Session\nChannel: {channel}\nChat ID: {chat_id}"
|
||||
messages.append({"role": "system", "content": system_prompt})
|
||||
|
||||
# History
|
||||
@@ -157,6 +167,7 @@ Reply directly with text for conversations. Only use the 'message' tool to send
|
||||
|
||||
# Current message (with optional image attachments)
|
||||
user_content = self._build_user_content(current_message, media)
|
||||
user_content = self._inject_runtime_context(user_content, channel, chat_id)
|
||||
messages.append({"role": "user", "content": user_content})
|
||||
|
||||
return messages
|
||||
|
||||
@@ -36,19 +36,7 @@ class ToolRegistry:
|
||||
return [tool.to_schema() for tool in self._tools.values()]
|
||||
|
||||
async def execute(self, name: str, params: dict[str, Any]) -> str:
|
||||
"""
|
||||
Execute a tool by name with given parameters.
|
||||
|
||||
Args:
|
||||
name: Tool name.
|
||||
params: Tool parameters.
|
||||
|
||||
Returns:
|
||||
Tool execution result as string.
|
||||
|
||||
Raises:
|
||||
KeyError: If tool not found.
|
||||
"""
|
||||
"""Execute a tool by name with given parameters."""
|
||||
_HINT = "\n\n[Analyze the error above and try a different approach.]"
|
||||
|
||||
tool = self._tools.get(name)
|
||||
|
||||
@@ -9,12 +9,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class SpawnTool(Tool):
|
||||
"""
|
||||
Tool to spawn a subagent for background task execution.
|
||||
|
||||
The subagent runs asynchronously and announces its result back
|
||||
to the main agent when complete.
|
||||
"""
|
||||
"""Tool to spawn a subagent for background task execution."""
|
||||
|
||||
def __init__(self, manager: "SubagentManager"):
|
||||
self._manager = manager
|
||||
|
||||
@@ -58,12 +58,16 @@ class WebSearchTool(Tool):
|
||||
}
|
||||
|
||||
def __init__(self, api_key: str | None = None, max_results: int = 5):
|
||||
self.api_key = api_key
|
||||
self._init_api_key = api_key
|
||||
self.max_results = max_results
|
||||
|
||||
@property
|
||||
def api_key(self) -> str:
|
||||
"""Resolve API key at call time so env/config changes are picked up."""
|
||||
return self._init_api_key or os.environ.get("BRAVE_API_KEY", "")
|
||||
|
||||
async def execute(self, query: str, count: int | None = None, **kwargs: Any) -> str:
|
||||
api_key = self.api_key or os.environ.get("BRAVE_API_KEY", "")
|
||||
if not api_key:
|
||||
if not self.api_key:
|
||||
return (
|
||||
"Error: Brave Search API key not configured. "
|
||||
"Set it in ~/.nanobot/config.json under tools.web.search.apiKey "
|
||||
|
||||
Reference in New Issue
Block a user