Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
Merge origin/main into feat/openai-compatible-session-isolation (resolve conflicts)
Tink37060dea0b7e
diff --cc nanobot/agent/context.pyindex 905562a98,2c648ebfc..86d1291e9--- a/nanobot/agent/context.py+++ b/nanobot/agent/context.py@@@ -71,13 -59,19 +71,26 @@@ Skills with available="false" need depesystem = platform.system()runtime = f"{'macOS' if system == 'Darwin' else system} {platform.machine()}, Python {platform.python_version()}"+ if memory_store is not None:+ mem_path = str(memory_store.memory_file)+ hist_path = str(memory_store.history_file)+ else:+ mem_path = f"{workspace_path}/memory/MEMORY.md"+ hist_path = f"{workspace_path}/memory/HISTORY.md"++ platform_policy = ""+ if system == "Windows":+ platform_policy = """## Platform Policy (Windows)+ - You are running on Windows. Do not assume GNU tools like `grep`, `sed`, or `awk` exist.+ - Prefer Windows-native commands or file tools when they are more reliable.+ - If terminal output is garbled, retry with UTF-8 output enabled.+ """+ else:+ platform_policy = """## Platform Policy (POSIX)+ - You are running on a POSIX system. Prefer UTF-8 and standard shell tools.+ - Use file tools when they are simpler or more reliable than shell commands.+ """+return f"""# nanobot 🐈You are nanobot, a helpful AI assistant.@@@ -87,10 -81,12 +100,12 @@@## WorkspaceYour workspace is at: {workspace_path}-- Long-term memory: {workspace_path}/memory/MEMORY.md (write important facts here)-- History log: {workspace_path}/memory/HISTORY.md (grep-searchable). Each entry starts with [YYYY-MM-DD HH:MM].+- Long-term memory: {mem_path} (write important facts here)+- History log: {hist_path} (grep-searchable). Each entry starts with [YYYY-MM-DD HH:MM].- Custom skills: {workspace_path}/skills/{{skill-name}}/SKILL.md+ {platform_policy}+## nanobot Guidelines- State intent before tool calls, but NEVER predict or claim results before receiving them.- Before modifying a file, read it first. Do not assume files or directories exist.diff --cc nanobot/cli/commands.pyindex 8035b2639,2c8d6d338..727076c53--- a/nanobot/cli/commands.py+++ b/nanobot/cli/commands.py@@@ -250,85 -264,25 +266,104 @@@ def _make_provider(config: Config))+ def _load_runtime_config(config: str | None = None, workspace: str | None = None) -> Config:+ """Load config and optionally override the active workspace."""+ from nanobot.config.loader import load_config, set_config_path++ config_path = None+ if config:+ config_path = Path(config).expanduser().resolve()+ if not config_path.exists():+ console.print(f"[red]Error: Config file not found: {config_path}[/red]")+ raise typer.Exit(1)+ set_config_path(config_path)+ console.print(f"[dim]Using config: {config_path}[/dim]")++ loaded = load_config(config_path)+ if workspace:+ loaded.agents.defaults.workspace = workspace+ return loaded+++# ============================================================================+# OpenAI-Compatible API Server+# ============================================================================+++def serve(+ port: int = typer.Option(8900, "--port", "-p", help="API server port"),+ host: str = typer.Option("0.0.0.0", "--host", "-H", help="Bind address"),+ timeout: float = typer.Option(120.0, "--timeout", "-t", help="Per-request timeout (seconds)"),+ verbose: bool = typer.Option(False, "--verbose", "-v", help="Show nanobot runtime logs"),+):+ """Start the OpenAI-compatible API server (/v1/chat/completions)."""+ try:+ from aiohttp import web # noqa: F401+ except ImportError:+ console.print("[red]aiohttp is required. Install with: pip install aiohttp[/red]")+ raise typer.Exit(1)++ from nanobot.config.loader import load_config+ from nanobot.api.server import create_app+ from loguru import logger++ if verbose:+ logger.enable("nanobot")+ else:+ logger.disable("nanobot")++ config = load_config()+ sync_workspace_templates(config.workspace_path)+ provider = _make_provider(config)++ from nanobot.bus.queue import MessageBus+ from nanobot.agent.loop import AgentLoop+ from nanobot.session.manager import SessionManager++ bus = MessageBus()+ session_manager = SessionManager(config.workspace_path)+ agent_loop = AgentLoop(+ bus=bus,+ provider=provider,+ workspace=config.workspace_path,+ model=config.agents.defaults.model,+ temperature=config.agents.defaults.temperature,+ max_tokens=config.agents.defaults.max_tokens,+ max_iterations=config.agents.defaults.max_tool_iterations,+ memory_window=config.agents.defaults.memory_window,+ reasoning_effort=config.agents.defaults.reasoning_effort,+ brave_api_key=config.tools.web.search.api_key or None,+ web_proxy=config.tools.web.proxy or None,+ exec_config=config.tools.exec,+ restrict_to_workspace=config.tools.restrict_to_workspace,+ session_manager=session_manager,+ mcp_servers=config.tools.mcp_servers,+ channels_config=config.channels,+ )++ model_name = config.agents.defaults.model+ console.print(f"{__logo__} Starting OpenAI-compatible API server")+ console.print(f" [cyan]Endpoint[/cyan] : http://{host}:{port}/v1/chat/completions")+ console.print(f" [cyan]Model[/cyan] : {model_name}")+ console.print(f" [cyan]Timeout[/cyan] : {timeout}s")+ console.print(f" [cyan]Header[/cyan] : x-session-key (required)")+ console.print()++ api_app = create_app(agent_loop, model_name=model_name, request_timeout=timeout)++ async def on_startup(_app):+ await agent_loop._connect_mcp()++ async def on_cleanup(_app):+ await agent_loop.close_mcp()++ api_app.on_startup.append(on_startup)+ api_app.on_cleanup.append(on_cleanup)++ web.run_app(api_app, host=host, port=port, print=lambda msg: logger.info(msg))++# ============================================================================# Gateway / Server# ============================================================================diff --cc nanobot/providers/litellm_provider.pyindex 5a76cb0ea,cb6763594..e913c20b7--- a/nanobot/providers/litellm_provider.py+++ b/nanobot/providers/litellm_provider.py@@@ -1,7 -1,6 +1,8 @@@"""LiteLLM provider implementation for multi-provider support."""+from __future__ import annotations++ import hashlibimport osimport secretsimport string