feat: filter the low version mcp tool

pull/22036/head
Novice 12 months ago
parent 5d090a01af
commit 13809c883d

@ -85,7 +85,7 @@ class AgentStrategyEntity(BaseModel):
description: I18nObject = Field(..., description="The description of the agent strategy") description: I18nObject = Field(..., description="The description of the agent strategy")
output_schema: Optional[dict] = None output_schema: Optional[dict] = None
features: Optional[list[AgentFeature]] = None features: Optional[list[AgentFeature]] = None
meta_version: Optional[str] = None
# pydantic configs # pydantic configs
model_config = ConfigDict(protected_namespaces=()) model_config = ConfigDict(protected_namespaces=())

@ -15,10 +15,12 @@ class PluginAgentStrategy(BaseAgentStrategy):
tenant_id: str tenant_id: str
declaration: AgentStrategyEntity declaration: AgentStrategyEntity
meta_version: str | None = None
def __init__(self, tenant_id: str, declaration: AgentStrategyEntity): def __init__(self, tenant_id: str, declaration: AgentStrategyEntity, meta_version: str | None):
self.tenant_id = tenant_id self.tenant_id = tenant_id
self.declaration = declaration self.declaration = declaration
self.meta_version = meta_version
def get_parameters(self) -> Sequence[AgentStrategyParameter]: def get_parameters(self) -> Sequence[AgentStrategyParameter]:
return self.declaration.parameters return self.declaration.parameters

@ -2,8 +2,11 @@ import json
from collections.abc import Generator, Mapping, Sequence from collections.abc import Generator, Mapping, Sequence
from typing import Any, Optional, cast from typing import Any, Optional, cast
from packaging.version import Version
from core.agent.entities import AgentToolEntity from core.agent.entities import AgentToolEntity
from core.agent.plugin_entities import AgentStrategyParameter from core.agent.plugin_entities import AgentStrategyParameter
from core.agent.strategy.plugin import PluginAgentStrategy
from core.memory.token_buffer_memory import TokenBufferMemory from core.memory.token_buffer_memory import TokenBufferMemory
from core.model_manager import ModelInstance, ModelManager from core.model_manager import ModelInstance, ModelManager
from core.model_runtime.entities.model_entities import AIModelEntity, ModelType from core.model_runtime.entities.model_entities import AIModelEntity, ModelType
@ -65,12 +68,14 @@ class AgentNode(ToolNode):
agent_parameters=agent_parameters, agent_parameters=agent_parameters,
variable_pool=self.graph_runtime_state.variable_pool, variable_pool=self.graph_runtime_state.variable_pool,
node_data=node_data, node_data=node_data,
strategy=strategy,
) )
parameters_for_log = self._generate_agent_parameters( parameters_for_log = self._generate_agent_parameters(
agent_parameters=agent_parameters, agent_parameters=agent_parameters,
variable_pool=self.graph_runtime_state.variable_pool, variable_pool=self.graph_runtime_state.variable_pool,
node_data=node_data, node_data=node_data,
for_log=True, for_log=True,
strategy=strategy,
) )
# get conversation id # get conversation id
@ -120,6 +125,7 @@ class AgentNode(ToolNode):
variable_pool: VariablePool, variable_pool: VariablePool,
node_data: AgentNodeData, node_data: AgentNodeData,
for_log: bool = False, for_log: bool = False,
strategy: PluginAgentStrategy,
) -> dict[str, Any]: ) -> dict[str, Any]:
""" """
Generate parameters based on the given tool parameters, variable pool, and node data. Generate parameters based on the given tool parameters, variable pool, and node data.
@ -168,7 +174,7 @@ class AgentNode(ToolNode):
if parameter.type == "array[tools]": if parameter.type == "array[tools]":
value = cast(list[dict[str, Any]], value) value = cast(list[dict[str, Any]], value)
value = [tool for tool in value if tool.get("enabled", False)] value = [tool for tool in value if tool.get("enabled", False)]
value = self._filter_mcp_type_tool(strategy, value)
for tool in value: for tool in value:
if "schemas" in tool: if "schemas" in tool:
tool.pop("schemas") tool.pop("schemas")
@ -360,3 +366,16 @@ class AgentNode(ToolNode):
if feature.value not in AgentOldVersionModelFeatures: if feature.value not in AgentOldVersionModelFeatures:
model_schema.features.remove(feature) model_schema.features.remove(feature)
return model_schema return model_schema
def _filter_mcp_type_tool(self, strategy: PluginAgentStrategy, tools: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""
Filter MCP type tool
:param strategy: plugin agent strategy
:param tool: tool
:return: filtered tool dict
"""
meta_version = strategy.meta_version
if meta_version and Version(meta_version) > Version("0.0.1"):
return tools
else:
return [tool for tool in tools if tool.get("type") != ToolProviderType.MCP.value]

@ -10,6 +10,6 @@ def get_plugin_agent_strategy(
agent_provider = manager.fetch_agent_strategy_provider(tenant_id, agent_strategy_provider_name) agent_provider = manager.fetch_agent_strategy_provider(tenant_id, agent_strategy_provider_name)
for agent_strategy in agent_provider.declaration.strategies: for agent_strategy in agent_provider.declaration.strategies:
if agent_strategy.identity.name == agent_strategy_name: if agent_strategy.identity.name == agent_strategy_name:
return PluginAgentStrategy(tenant_id, agent_strategy) return PluginAgentStrategy(tenant_id, agent_strategy, agent_provider.meta.version)
raise ValueError(f"Agent strategy {agent_strategy_name} not found") raise ValueError(f"Agent strategy {agent_strategy_name} not found")

Loading…
Cancel
Save