集成新的Beaver后端服务到应用实例中,替换原有的nanobot实现。 主要变更包括: - 在Dockerfile和环境配置中添加Beaver相关路径和配置变量 - 更新工作目录结构从.nanobot到.beaver - 实现Beaver引擎加载器,支持配置文件加载和工具组装 - 添加内置工具如ListDirectoryTool、ReadFileTool、SearchFilesTool - 更新消息处理流程,支持通道适配器和网关模式 - 重构技能系统,支持显式工具提示和嵌入式检索 - 改进错误处理和生命周期管理 此变更使应用实例能够使用统一的Beaver后端进行AI代理运行时管理。
108 lines
3.5 KiB
Python
108 lines
3.5 KiB
Python
import json
|
|
|
|
from beaver.engine import AgentLoop, EngineLoader
|
|
from beaver.engine.providers import make_provider_bundle
|
|
from beaver.engine.providers.litellm import LiteLLMProvider
|
|
from beaver.foundation.config import load_config
|
|
|
|
|
|
def test_load_config_reads_current_instance_shape(tmp_path) -> None:
|
|
config_path = tmp_path / "config.json"
|
|
config_path.write_text(
|
|
json.dumps(
|
|
{
|
|
"agents": {
|
|
"defaults": {
|
|
"workspace": str(tmp_path / "workspace"),
|
|
"model": "qwen-plus",
|
|
}
|
|
},
|
|
"providers": {
|
|
"openai": {
|
|
"apiKey": "sk-test",
|
|
"apiBase": "https://oai.example.com/v1",
|
|
"extraHeaders": {"X-Test": "1"},
|
|
}
|
|
},
|
|
"embeddingModel": "text-embedding-v4",
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
config = load_config(config_path=config_path)
|
|
target = config.resolve_provider_target()
|
|
|
|
assert config.default_model == "qwen-plus"
|
|
assert config.default_embedding_model == "text-embedding-v4"
|
|
assert target["provider_name"] == "openai"
|
|
assert target["model"] == "qwen-plus"
|
|
assert target["api_key"] == "sk-test"
|
|
assert target["api_base"] == "https://oai.example.com/v1"
|
|
assert target["extra_headers"] == {"X-Test": "1"}
|
|
|
|
|
|
def test_engine_loader_uses_config_workspace(tmp_path) -> None:
|
|
workspace = tmp_path / "workspace"
|
|
config_path = tmp_path / "config.json"
|
|
config_path.write_text(
|
|
json.dumps(
|
|
{
|
|
"agents": {
|
|
"defaults": {
|
|
"workspace": str(workspace),
|
|
"model": "qwen-plus",
|
|
}
|
|
},
|
|
"providers": {"openai": {"apiKey": "sk-test", "apiBase": "https://oai.example.com/v1"}},
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
loader = EngineLoader(config_path=config_path)
|
|
assert loader.workspace == workspace
|
|
|
|
|
|
def test_agent_loop_config_drives_provider_bundle(tmp_path) -> None:
|
|
workspace = tmp_path / "workspace"
|
|
config_path = tmp_path / "config.json"
|
|
config_path.write_text(
|
|
json.dumps(
|
|
{
|
|
"agents": {
|
|
"defaults": {
|
|
"workspace": str(workspace),
|
|
"model": "qwen-plus",
|
|
}
|
|
},
|
|
"providers": {"openai": {"apiKey": "sk-test", "apiBase": "https://oai.example.com/v1"}},
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
loop = AgentLoop(loader=EngineLoader(config_path=config_path))
|
|
loaded = loop.boot()
|
|
target = loaded.config.resolve_provider_target()
|
|
|
|
assert target["provider_name"] == "openai"
|
|
assert target["model"] == "qwen-plus"
|
|
assert target["api_key"] == "sk-test"
|
|
assert target["api_base"] == "https://oai.example.com/v1"
|
|
loop.close()
|
|
|
|
|
|
def test_openai_compatible_qwen_config_keeps_openai_provider() -> None:
|
|
bundle = make_provider_bundle(
|
|
model="qwen-plus",
|
|
provider_name="openai",
|
|
api_key="sk-test",
|
|
api_base="https://oai.example.com/v1",
|
|
)
|
|
|
|
assert bundle.main_runtime.provider_name == "openai"
|
|
assert bundle.main_runtime.api_base == "https://oai.example.com/v1"
|
|
assert isinstance(bundle.main_provider, LiteLLMProvider)
|
|
assert bundle.main_provider._resolve_model("qwen-plus") == "openai/qwen-plus"
|