添加 DEFAULT_TEAM_NODE_MAX_TOOL_ITERATIONS 配置项以控制团队节点的最大工具迭代次数, 并修改 LocalAgentRunner 中的逻辑来使用此默认值当 envelope 中未指定时。 fix(runtime): 修复团队节点运行成功判断逻辑 更新运行成功判断条件,将 finish_reason 为 "max_tool_iterations_finalized" 的情况 视为运行失败,并添加对原始工具调用输出的检测,避免将其误判为成功完成。 feat(mcp): 添加团队工作流MCP工具类别支持 增加新的本地MCP工具类别 "team_workflow" 及其对应的工具创建功能, 为团队工作流提供本地工具支持。 refactor(engine): 调整AgentLoop最大工具迭代次数设置 将 AgentProfile 中的默认 max_tool_iterations 从 30 增加到 100, 同时移除 TaskExecutionPlanner 构造函数中的重复参数传递。 perf(mcp): 优化MCP连接管理避免重复连接 添加 mcp_connected 标志来跟踪MCP连接状态,确保 connect_all 只执行一次, 提高性能并避免不必要的重复连接。 refactor(skills): 移除技能团队模板相关功能 移除与技能团队模板相关的代码,包括解析、存储和处理逻辑, 简化技能记录结构和加载流程。 feat(process): 增强会话过程投影器功能 添加技能激活快照事件处理,改进团队运行完成消息显示, 并增强技能激活事件的时间戳记录功能。 refactor(tasks): 简化任务尝试编排器团队执行逻辑 移除团队执行相关代码,将所有任务统一按单步执行处理, 简化任务编排器的复杂度并提升执行效率。 fix(evidence): 修复节点证据评估中需求验证逻辑 更新节点证据评估逻辑,跳过自然语言证据需求的确定性验证, 只执行机器可读的需求验证,避免因自然语言需求导致的节点失败。
121 lines
3.4 KiB
Python
121 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from types import SimpleNamespace
|
|
|
|
from beaver.engine.providers.base import LLMProvider, LLMResponse
|
|
from beaver.engine.providers.factory import ProviderBundle
|
|
from beaver.tasks import TaskExecutionPlanner, TaskRecord
|
|
|
|
|
|
class PlannerProvider(LLMProvider):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
self.calls = 0
|
|
|
|
async def chat(
|
|
self,
|
|
messages: list[dict],
|
|
tools: list[dict] | None = None,
|
|
model: str | None = None,
|
|
max_tokens: int = 4096,
|
|
temperature: float = 0.7,
|
|
) -> LLMResponse:
|
|
self.calls += 1
|
|
return LLMResponse(
|
|
content='{"mode":"team"}',
|
|
finish_reason="stop",
|
|
provider_name="stub",
|
|
model="stub-model",
|
|
)
|
|
|
|
def get_default_model(self) -> str:
|
|
return "stub-model"
|
|
|
|
|
|
def _task() -> TaskRecord:
|
|
return TaskRecord(
|
|
task_id="task-1",
|
|
session_id="session-1",
|
|
description="implement workflow",
|
|
goal="implement workflow",
|
|
constraints=[],
|
|
priority=0,
|
|
status="open",
|
|
creator="test",
|
|
created_at="now",
|
|
updated_at="now",
|
|
)
|
|
|
|
|
|
def _bundle(provider: PlannerProvider) -> ProviderBundle:
|
|
return ProviderBundle(
|
|
main_runtime=SimpleNamespace(model="stub-model", provider_name="stub"),
|
|
main_provider=provider,
|
|
)
|
|
|
|
|
|
def test_planner_skips_provider_for_simple_task() -> None:
|
|
provider = PlannerProvider()
|
|
task = _task()
|
|
task.description = "查询深圳天气"
|
|
task.goal = "查询深圳天气"
|
|
|
|
plan = asyncio.run(
|
|
TaskExecutionPlanner().plan(
|
|
task=task,
|
|
user_message="帮我查一下今天深圳天气",
|
|
attempt_index=1,
|
|
provider_bundle=_bundle(provider),
|
|
)
|
|
)
|
|
|
|
assert plan.mode == "single"
|
|
assert plan.graph is None
|
|
assert plan.reason == "planner_skipped_simple_task"
|
|
assert provider.calls == 0
|
|
|
|
|
|
def test_planner_replaces_team_planning_with_workflow_tools_without_provider_call() -> None:
|
|
provider = PlannerProvider()
|
|
|
|
plan = asyncio.run(
|
|
TaskExecutionPlanner().plan(
|
|
task=_task(),
|
|
user_message="research and compare workflow options",
|
|
attempt_index=1,
|
|
provider_bundle=_bundle(provider),
|
|
skill_summaries=["docker-debug: Use docker logs before editing config."],
|
|
tool_hints=["terminal", "search_files"],
|
|
)
|
|
)
|
|
|
|
assert not plan.is_team
|
|
assert plan.mode == "single"
|
|
assert plan.graph is None
|
|
assert plan.reason == "planner_team_replaced_by_workflow_tools"
|
|
assert plan.final_synthesis_instruction == ""
|
|
assert provider.calls == 0
|
|
|
|
|
|
def test_planner_can_be_disabled_by_environment(monkeypatch) -> None:
|
|
monkeypatch.setenv("BEAVER_AGENT_TEAM_ENABLED", "0")
|
|
provider = PlannerProvider()
|
|
|
|
plan = asyncio.run(
|
|
TaskExecutionPlanner().plan(
|
|
task=_task(),
|
|
user_message="research and compare workflow options",
|
|
attempt_index=1,
|
|
provider_bundle=_bundle(provider),
|
|
)
|
|
)
|
|
|
|
assert plan.mode == "single"
|
|
assert plan.reason == "planner_disabled_by_environment"
|
|
assert provider.calls == 0
|
|
|
|
|
|
def test_planner_no_longer_exposes_json_to_team_graph_parser() -> None:
|
|
assert not hasattr(TaskExecutionPlanner(), "from_json")
|