__init__.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # 必须要在这里导入模块,以便对应的模块执行register_toolkit
  2. from typing import Sequence, List
  3. from pqai_agent.logging_service import logger
  4. from pqai_agent.toolkit.tool_registry import ToolRegistry
  5. from pqai_agent.toolkit.image_describer import ImageDescriber
  6. from pqai_agent.toolkit.message_notifier import MessageNotifier
  7. from pqai_agent.toolkit.pq_video_searcher import PQVideoSearcher
  8. global_tool_map = ToolRegistry.tool_map
  9. def get_tool(tool_name: str) -> 'FunctionTool':
  10. """
  11. Retrieve a tool by its name from the global tool map.
  12. Args:
  13. tool_name (str): The name of the tool to retrieve.
  14. Returns:
  15. FunctionTool: The tool instance if found, otherwise None.
  16. """
  17. return global_tool_map.get(tool_name, None)
  18. def get_tools(tool_names: Sequence[str]) -> List['FunctionTool']:
  19. """
  20. Retrieve multiple tools by their names from the global tool map.
  21. Args:
  22. tool_names (Sequence[str]): A sequence of tool names to retrieve.
  23. Returns:
  24. Sequence[FunctionTool]: A sequence of tool instances corresponding to the provided names.
  25. """
  26. ret = []
  27. for name in tool_names:
  28. tool = get_tool(name)
  29. if tool is not None:
  30. ret.append(tool)
  31. else:
  32. logger.warning(f"Tool '{name}' not found in the global tool map.")
  33. return ret