Skip to content

SpringBeanToolCallbackResolver has a problem with bean cache inside #2399

Open
@Forest-Fairy

Description

@Forest-Fairy

This resolver will resolve and cache a tool but what will happen if a tool bean has been unregistered?
`
@OverRide
public ToolCallback resolve(String toolName) {
Assert.hasText(toolName, "toolName cannot be null or empty");

	logger.debug("ToolCallback resolution attempt from Spring application context");

	ToolCallback resolvedToolCallback = toolCallbacksCache.get(toolName);

	if (resolvedToolCallback != null) {
		return resolvedToolCallback;
	}

	ResolvableType toolType = TypeResolverHelper.resolveBeanType(applicationContext, toolName);
	ResolvableType toolInputType = (ResolvableType.forType(Supplier.class).isAssignableFrom(toolType))
			? ResolvableType.forType(Void.class) : TypeResolverHelper.getFunctionArgumentType(toolType, 0);

	String toolDescription = resolveToolDescription(toolName, toolInputType.toClass());
	Object bean = applicationContext.getBean(toolName);

	resolvedToolCallback = buildToolCallback(toolName, toolType, toolInputType, toolDescription, bean);

	toolCallbacksCache.put(toolName, resolvedToolCallback);

	return resolvedToolCallback;
}

`
I think it has better to implement ApplicationEventListener interface in order to remove the cache when bean has been removed in application context

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions