feat: 增强 core/agents 工具和 API
- 新增 loop.py Agent 运行循环 - 优化 memory.py 记忆模块 - 扩展 api/routes.py 接口 - 更新 tools 模块:builtin.py, manager.py, __init__.py - 新增 .env.example 配置示例 - 更新 requirements.txt 依赖 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,19 +21,55 @@ from agents.tools.builtin import (
|
||||
from agents.tools.manager import ToolManager
|
||||
|
||||
|
||||
def create_default_registry() -> ToolRegistry:
|
||||
def create_default_registry(use_sandbox: bool = False) -> ToolRegistry:
|
||||
"""Create a tool registry with default tools.
|
||||
|
||||
Args:
|
||||
use_sandbox: Whether to use sandbox for shell execution
|
||||
|
||||
Returns:
|
||||
Tool registry with built-in tools
|
||||
"""
|
||||
registry = ToolRegistry()
|
||||
# Register built-in tools
|
||||
for tool in get_builtin_tools():
|
||||
for tool in get_builtin_tools(use_sandbox=use_sandbox):
|
||||
registry.register(tool)
|
||||
return registry
|
||||
|
||||
|
||||
# Import sandbox tools from nanobot (optional)
|
||||
try:
|
||||
from nanobot.agent.tools.sandbox_execution import (
|
||||
SandboxType,
|
||||
SandboxCodeExecutionTool,
|
||||
SandboxBashTool,
|
||||
get_sandbox_tools,
|
||||
)
|
||||
from nanobot.agent.tools.bwrap_sandbox import (
|
||||
BwrapSandbox,
|
||||
get_bwrap_sandbox,
|
||||
execute_in_bwrap,
|
||||
)
|
||||
from nanobot.agent.tools.gvisor_sandbox import (
|
||||
GvisorSandbox,
|
||||
get_gvisor_sandbox,
|
||||
execute_in_gvisor,
|
||||
)
|
||||
SANDBOX_AVAILABLE = True
|
||||
except ImportError as e:
|
||||
SandboxType = None
|
||||
SandboxCodeExecutionTool = None
|
||||
SandboxBashTool = None
|
||||
get_sandbox_tools = None
|
||||
BwrapSandbox = None
|
||||
get_bwrap_sandbox = None
|
||||
execute_in_bwrap = None
|
||||
GvisorSandbox = None
|
||||
get_gvisor_sandbox = None
|
||||
execute_in_gvisor = None
|
||||
SANDBOX_AVAILABLE = False
|
||||
|
||||
|
||||
__all__ = [
|
||||
"Tool",
|
||||
"ToolRegistry",
|
||||
@@ -48,4 +84,16 @@ __all__ = [
|
||||
"CalculatorTool",
|
||||
"GetTimeTool",
|
||||
"BashTool",
|
||||
# Sandbox tools
|
||||
"SANDBOX_AVAILABLE",
|
||||
"SandboxType",
|
||||
"SandboxCodeExecutionTool",
|
||||
"SandboxBashTool",
|
||||
"get_sandbox_tools",
|
||||
"BwrapSandbox",
|
||||
"GvisorSandbox",
|
||||
"get_bwrap_sandbox",
|
||||
"get_gvisor_sandbox",
|
||||
"execute_in_bwrap",
|
||||
"execute_in_gvisor",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user