tooluniverse.agentic_tool 模块

class tooluniverse.agentic_tool.AgenticTool[源代码]

基类:BaseTool

基于 JSON 定义配置(包含提示和输入参数)的通用大语言模型(LLM)提示封装器。

STREAM_FLAG_KEY = '_tooluniverse_stream'
static has_any_api_keys()[源代码]

检查所有支持的 API 类型中是否有可用的 API 密钥。

返回值

bool: True if at least one API type has all required keys, False otherwise

__init__(tool_config)[源代码]
name: str
_prompt_template: str
_input_arguments: List[str]
_required_arguments: List[str]
_argument_defaults: Dict[str, str]
_api_type: str
_model_id: str
_temperature: float | None
_return_json: bool
_max_retries: int
_retry_delay: int
return_metadata: bool
_validate_api_key: bool
_fallback_api_type: str | None
_fallback_model_id: str | None
_use_global_fallback: bool
_gemini_model_id: str
_global_fallback_chain: List[Dict[str, str]]
_get_global_fallback_chain()[源代码]

从环境中获取全局回退链,或使用默认值。

_try_initialize_api()[源代码]

尝试初始化主API,若已配置则回退至次要API。

_try_api(api_type, model_id, server_url=None)[源代码]

尝试初始化特定的 API 和模型。

_validate_model_config()[源代码]
run(arguments, stream_callback=None)[源代码]

执行该工具。

默认的 BaseTool 实现接受一个可选的参数映射,以与大多数具体工具实现保持一致,这些工具通常期望输入为一个字典。

参数:
  • arguments (dict, optional) – 工具专用参数

  • stream_callback (callable, optional) – 用于流式响应的回调

  • use_cache (bool, optional) – 是否启用结果缓存

  • validate (bool, optional) – 是否已执行参数验证

备注

这些附加参数(stream_callback、use_cache、validate)由 run_one_function() 传递,用于提供有关执行的上下文。工具可以利用这些参数进行优化或特殊处理。

为了向后兼容,不接受这些参数的工具仍然可以正常运行——它们只会接收到 arguments 参数。

static _iter_chunks(text, size=800)[源代码]
_emit_stream_chunk(chunk, stream_callback)[源代码]
_validate_arguments(arguments)[源代码]
_format_prompt(arguments)[源代码]
get_prompt_preview(arguments)[源代码]
get_model_info()[源代码]
is_available()[源代码]

请检查该工具是否可用。

get_availability_status()[源代码]

获取工具的详细可用性状态。

retry_initialization()[源代码]

尝试重新初始化工具(如果已更新 API 密钥,此操作可能有用)。

get_prompt_template()[源代码]
get_input_arguments()[源代码]
validate_configuration()[源代码]
estimate_token_usage(arguments)[源代码]
_cached_version_hash: str | None