refactor: tool parameter cache (#3703)
This commit is contained in:
@@ -222,7 +222,7 @@ class ToolManager:
|
||||
return parameter_value
|
||||
|
||||
@classmethod
|
||||
def get_agent_tool_runtime(cls, tenant_id: str, agent_tool: AgentToolEntity) -> Tool:
|
||||
def get_agent_tool_runtime(cls, tenant_id: str, app_id: str, agent_tool: AgentToolEntity) -> Tool:
|
||||
"""
|
||||
get the agent tool runtime
|
||||
"""
|
||||
@@ -245,6 +245,7 @@ class ToolManager:
|
||||
tool_runtime=tool_entity,
|
||||
provider_name=agent_tool.provider_id,
|
||||
provider_type=agent_tool.provider_type,
|
||||
identity_id=f'AGENT.{app_id}'
|
||||
)
|
||||
runtime_parameters = encryption_manager.decrypt_tool_parameters(runtime_parameters)
|
||||
|
||||
@@ -252,7 +253,7 @@ class ToolManager:
|
||||
return tool_entity
|
||||
|
||||
@classmethod
|
||||
def get_workflow_tool_runtime(cls, tenant_id: str, workflow_tool: ToolEntity):
|
||||
def get_workflow_tool_runtime(cls, tenant_id: str, app_id: str, node_id: str, workflow_tool: ToolEntity):
|
||||
"""
|
||||
get the workflow tool runtime
|
||||
"""
|
||||
@@ -277,6 +278,7 @@ class ToolManager:
|
||||
tool_runtime=tool_entity,
|
||||
provider_name=workflow_tool.provider_id,
|
||||
provider_type=workflow_tool.provider_type,
|
||||
identity_id=f'WORKFLOW.{app_id}.{node_id}'
|
||||
)
|
||||
|
||||
if runtime_parameters:
|
||||
|
||||
@@ -113,12 +113,13 @@ class ToolParameterConfigurationManager(BaseModel):
|
||||
tool_runtime: Tool
|
||||
provider_name: str
|
||||
provider_type: str
|
||||
identity_id: str
|
||||
|
||||
def _deep_copy(self, parameters: dict[str, Any]) -> dict[str, Any]:
|
||||
"""
|
||||
deep copy parameters
|
||||
"""
|
||||
return {key: value for key, value in parameters.items()}
|
||||
return deepcopy(parameters)
|
||||
|
||||
def _merge_parameters(self) -> list[ToolParameter]:
|
||||
"""
|
||||
@@ -176,6 +177,8 @@ class ToolParameterConfigurationManager(BaseModel):
|
||||
# override parameters
|
||||
current_parameters = self._merge_parameters()
|
||||
|
||||
parameters = self._deep_copy(parameters)
|
||||
|
||||
for parameter in current_parameters:
|
||||
if parameter.form == ToolParameter.ToolParameterForm.FORM and parameter.type == ToolParameter.ToolParameterType.SECRET_INPUT:
|
||||
if parameter.name in parameters:
|
||||
@@ -194,7 +197,8 @@ class ToolParameterConfigurationManager(BaseModel):
|
||||
tenant_id=self.tenant_id,
|
||||
provider=f'{self.provider_type}.{self.provider_name}',
|
||||
tool_name=self.tool_runtime.identity.name,
|
||||
cache_type=ToolParameterCacheType.PARAMETER
|
||||
cache_type=ToolParameterCacheType.PARAMETER,
|
||||
identity_id=self.identity_id
|
||||
)
|
||||
cached_parameters = cache.get()
|
||||
if cached_parameters:
|
||||
@@ -223,7 +227,8 @@ class ToolParameterConfigurationManager(BaseModel):
|
||||
tenant_id=self.tenant_id,
|
||||
provider=f'{self.provider_type}.{self.provider_name}',
|
||||
tool_name=self.tool_runtime.identity.name,
|
||||
cache_type=ToolParameterCacheType.PARAMETER
|
||||
cache_type=ToolParameterCacheType.PARAMETER,
|
||||
identity_id=self.identity_id
|
||||
)
|
||||
cache.delete()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user