jianmu.tool¶
适用对象:工具作者 / Agent 应用开发者 / 执行层维护者
是否必读:是
相关模块:jianmu.execution, jianmu.guard, jianmu.node
1. 模块职责¶
jianmu.tool 是工具系统的公开入口,负责暴露工具基类、函数装饰器、工具集合门面和常用内置工具。
这是“声明工具”和“把工具接到 Agent/节点里”的主入口。
2. 适合查什么¶
- 核心对象:
Tool、ToolCall、ToolResult - 工具节点:
jianmu.node.ToolNode - 工具集合:
ToolSet - 装饰器:
tool、FunctionTool - 高级扩展:
ToolProvider - 内置工具:
CalculatorTool、PythonREPLTool、FileReadTool
3. 注意事项¶
HTTPTool、DuckDuckGoSearchTool依赖可选包- 声明工具时优先依赖
Tool/tool/ToolSet,不要直接耦合内部 runner - 真正的执行隔离、审批和沙箱逻辑主要属于
jianmu.execution与jianmu.guard
4. builtin 路径说明¶
jianmu.tool.builtin 表示“这些工具当前由框架内建提供”,它更像源码组织层,而不是推荐用户长期依赖的主导入层。
因此新代码应优先写成:
from jianmu.tool import CalculatorToolfrom jianmu.tool import PythonREPLToolfrom jianmu.tool import FileReadTool
而不是默认写成:
from jianmu.tool.builtin import CalculatorToolfrom jianmu.tool.builtin import PythonREPLTool
如果未来内建工具的文件布局调整,jianmu.tool 这一层更容易保持稳定。
5. 最小示例¶
from jianmu.tool import tool
@tool
def echo(input: str) -> str:
"""Return the input unchanged."""
return input
tools = [echo]
6. 常见入口¶
- 想快速把函数暴露成工具:看
tool/FunctionTool - 想写类式工具:看
Tool - 想组合和执行一组工具:看
ToolSet - 想接入动态工具来源:看
ToolProvider - 想执行 agent 发出的工具调用:看
ToolExecutor
7. API 参考¶
tool
¶
jianmu tools module - Tool base class and built-in tools.
ParallelDecision
dataclass
¶
Explain whether one concrete tool call may run concurrently.
Tool
¶
Bases: ABC
Base class for callable tools exposed to agents and workflow nodes.
Subclass Tool when you want a reusable, named capability that can be:
- called directly by
ToolExecutor - exposed to an LLM as function-calling schema
- wrapped into a workflow node via
as_node()
Minimal example::
class EchoTool(Tool):
name = "echo"
description = "Return the input text unchanged."
def run(self, input: str) -> str:
return input
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
str
|
Public tool name exposed to agents and executors. |
description |
str
|
Human-readable tool description. |
input_schema |
Dict[str, Any]
|
JSON schema describing accepted tool inputs. |
output_schema |
Dict[str, Any]
|
JSON schema describing tool outputs. |
parallel_safe |
bool
|
Whether the tool may execute concurrently with peers. |
effect_tags |
tuple[str, ...]
|
Normalized side-effect tags used by orchestration logic. |
run
abstractmethod
¶
Execute the tool with given input.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input
|
Any
|
Parsed tool input. For function-style tools this may be a structured dictionary rather than a raw string. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Any
|
Tool result to be converted into an observation. |
源代码位于: jianmu/tool/base.py
execute
async
¶
execute(
args: Any,
*,
injected: Optional[Dict[str, Any]] = None,
prefer_injected: bool = True,
runner: Optional[Any] = None,
runner_event_context: Optional[Any] = None,
) -> Any
Execute this tool through the shared Jianmu execution contract.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
args
|
Any
|
Explicit tool arguments. |
必需 |
injected
|
Optional[Dict[str, Any]]
|
Optional runtime-injected arguments merged into |
None
|
prefer_injected
|
bool
|
Whether injected values override explicit args. |
True
|
runner
|
Optional[Any]
|
Optional sandbox-aware runner delegated to perform execution. |
None
|
runner_event_context
|
Optional[Any]
|
Optional runtime-event correlation metadata forwarded to the shared runner when present. |
None
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
Tool result produced by the shared execution contract. |
源代码位于: jianmu/tool/base.py
permission_check_for_call
¶
Project one concrete invocation into Permission V2.
Custom tools may override this side-effect-free method. The default
implementation uses the declared permission_action and falls back
to the tool name plus an exact canonical-arguments resource.
源代码位于: jianmu/tool/base.py
parallel_decision_for_call
¶
Return the default concurrency decision for one concrete call.
Subclasses may override this method when concurrency safety depends on the call arguments. The default deliberately preserves Jianmu's previous conservative behavior for runtime-injected and stateful tools. Overrides must be deterministic and side-effect free because planners and observability code may query the decision more than once.
源代码位于: jianmu/tool/base.py
as_node
¶
as_node(
name: Optional[str] = None,
*,
input_key: str = "input",
output_key: str = "output",
execute: Optional[bool] = None,
namespace: str | None = None,
) -> Any
Wrap this tool into a ToolNode for use in a behavior tree.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
Optional[str]
|
Node name override; defaults to |
None
|
input_key
|
str
|
State key from which the tool reads its input. |
'input'
|
output_key
|
str
|
State key to which the tool writes its output. |
'output'
|
execute
|
Optional[bool]
|
Whether the node should run the tool when ticked. |
None
|
namespace
|
str | None
|
Optional state namespace for port resolution. |
None
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
A |
This is useful when the same tool should be available both to LLM agent loops and to explicit workflow branches.
源代码位于: jianmu/tool/base.py
get_description
¶
Resolve the best available description for prompts and schemas.
返回:
| 类型 | 描述 |
|---|---|
str
|
The class-level |
str
|
the cleaned class docstring, or an empty string. |
源代码位于: jianmu/tool/base.py
get_effect_tags
¶
Return normalized effect tags for downstream orchestration logic.
返回:
| 类型 | 描述 |
|---|---|
tuple[str, ...]
|
Normalized effect-tag tuple with empty values removed. |
源代码位于: jianmu/tool/base.py
to_schema
¶
Return the JSON function schema (name/description/parameters).
返回:
| 类型 | 描述 |
|---|---|
Dict[str, Any]
|
Dictionary with |
Dict[str, Any]
|
suitable for OpenAI-style function-calling. |
源代码位于: jianmu/tool/base.py
spec
¶
Return a normalized tool spec for prompts and UIs.
返回:
| 类型 | 描述 |
|---|---|
Dict[str, Any]
|
Dictionary with |
Dict[str, Any]
|
|
源代码位于: jianmu/tool/base.py
ToolSet
dataclass
¶
Facade over a named collection of tools.
ToolSet is the main public entrypoint for assembling tools from:
- builtin tool names
- explicit tool instances
- dynamic
ToolProvidersources
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
tools |
list[Tool]
|
Tool instances in execution and prompt order. |
from_tools
classmethod
¶
Build a tool set from explicit tool instances.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
tools
|
Iterable[Tool] | None
|
Tool instances to include. |
None
|
返回:
| 类型 | 描述 |
|---|---|
'ToolSet'
|
Tool set containing the provided explicit tool instances. |
源代码位于: jianmu/tool/set.py
resolve
classmethod
¶
Resolve builtin/custom tool names into a concrete tool set.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
names
|
list[str]
|
Builtin or custom tool names to resolve. |
必需 |
custom_tools
|
list[Tool] | None
|
Additional tool instances to consider. |
None
|
返回:
| 类型 | 描述 |
|---|---|
'ToolSet'
|
Tool set containing resolved builtin and custom tools. |
源代码位于: jianmu/tool/set.py
from_providers
classmethod
¶
Collect tools from dynamic providers and wrap them as a tool set.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
providers
|
Iterable[ToolProvider]
|
Tool providers to include. |
必需 |
**kwargs
|
Any
|
Provider-specific resolution arguments. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
'ToolSet'
|
Tool set containing the merged provider tools. |
源代码位于: jianmu/tool/set.py
list_builtin_names
classmethod
¶
List builtin tool names visible to the registry.
返回:
| 类型 | 描述 |
|---|---|
list[str]
|
Canonical builtin tool names visible to the registry. |
merge
¶
Return a new tool set merged with explicit tools or other sets.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
*groups
|
Iterable[Tool] | 'ToolSet'
|
Additional tool groups or tool sets to merge. |
()
|
返回:
| 类型 | 描述 |
|---|---|
'ToolSet'
|
New tool set containing the merged tool collection. |
源代码位于: jianmu/tool/set.py
with_tools
¶
Return a new tool set with more explicit tools merged in.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
tools
|
Iterable[Tool]
|
Tool instances to include. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
'ToolSet'
|
New tool set with the provided explicit tools merged in. |
源代码位于: jianmu/tool/set.py
get
¶
Return one tool by name, or None when absent.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Tool name to resolve. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
Tool | None
|
Matching tool instance, or |
源代码位于: jianmu/tool/set.py
execute
async
¶
execute(
name: str,
args: Any,
*,
injected: dict[str, Any] | None = None,
prefer_injected: bool = True,
runner: Any | None = None,
) -> Any
Execute one named tool from this set.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Tool name to execute. |
必需 |
args
|
Any
|
Explicit tool arguments. |
必需 |
injected
|
dict[str, Any] | None
|
Optional runtime-injected arguments. |
None
|
prefer_injected
|
bool
|
Whether injected values override explicit values. |
True
|
runner
|
Any | None
|
Optional delegated execution runner. |
None
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
Tool result produced by the resolved tool. |
引发:
| 类型 | 描述 |
|---|---|
KeyError
|
If a required key is missing. |
源代码位于: jianmu/tool/set.py
is_parallel_safe
¶
Return whether all named tools may run in parallel safely.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
names
|
Iterable[str]
|
Tool names to validate for parallel execution. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
bool
|
|
源代码位于: jianmu/tool/set.py
schemas
¶
Return normalized function-calling schemas for all tools.
返回:
| 类型 | 描述 |
|---|---|
list[dict[str, Any]]
|
Normalized function-calling schemas for all tools in the set. |
specs
¶
Return normalized tool specs for prompts and UIs.
返回:
| 类型 | 描述 |
|---|---|
list[dict[str, Any]]
|
Normalized tool specs for all tools in the set. |
describe
¶
Render a human-readable bullet list for prompt construction.
返回:
| 类型 | 描述 |
|---|---|
str
|
Human-readable bullet list describing the tools. |
源代码位于: jianmu/tool/set.py
names
¶
Return tool names in prompt/execution order.
返回:
| 类型 | 描述 |
|---|---|
list[str]
|
Tool names in execution and prompt order. |
BuiltinToolProvider
¶
Bases: BaseToolProvider
Builtin Jianmu tool registry and lazy resolution provider.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
_builtins |
Dict[str, Type[Tool]]
|
Canonical builtin tool registry keyed by tool name. |
_aliases |
Dict[str, str]
|
Alias mapping from alternate names to canonical builtin names. |
_builtins_loaded |
Whether lazy builtin registration has completed. |
aliases
classmethod
¶
Return the current alias-to-canonical tool name mapping.
返回:
| 类型 | 描述 |
|---|---|
Dict[str, str]
|
The resulting |
register_tool
classmethod
¶
Register a builtin tool class under its canonical name.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Canonical builtin tool name. |
必需 |
tool_cls
|
Type[Tool]
|
Tool class registered under the canonical name. |
必需 |
源代码位于: jianmu/tool/provider.py
register_alias
classmethod
¶
Register an alias that resolves to a canonical builtin tool name.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
alias
|
str
|
Alternate name that should resolve to a builtin tool. |
必需 |
canonical
|
str
|
Canonical builtin tool name referenced by the alias. |
必需 |
源代码位于: jianmu/tool/provider.py
canonical_tool_name
classmethod
¶
Resolve an input name through the alias table when available.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Requested tool name or alias. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
str
|
Canonical builtin tool name when an alias exists, otherwise |
源代码位于: jianmu/tool/provider.py
list_builtin_names
classmethod
¶
Return the canonical names of all registered builtin tools.
返回:
| 类型 | 描述 |
|---|---|
List[str]
|
Canonical names of all registered builtin tools. |
源代码位于: jianmu/tool/provider.py
is_builtin_tool_name
classmethod
¶
Return whether the provided name resolves to a builtin tool.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Requested tool name or alias. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
bool
|
|
源代码位于: jianmu/tool/provider.py
resolve_named_tools
classmethod
¶
resolve_named_tools(
tool_names: List[str],
*,
custom_tools: List[Tool] | None = None,
) -> List[Tool]
Resolve named builtin and custom tools into instantiated tool objects.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
tool_names
|
List[str]
|
Tool names to resolve. |
必需 |
custom_tools
|
List[Tool] | None
|
Additional tool instances to consider. |
None
|
返回:
| 类型 | 描述 |
|---|---|
List[Tool]
|
Instantiated tool objects with deterministic name-based deduplication. |
源代码位于: jianmu/tool/provider.py
get_tools
classmethod
¶
Return builtin tools, optionally narrowed to the requested names.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
**kwargs
|
Any
|
Optional |
{}
|
返回:
| 类型 | 描述 |
|---|---|
list[Tool]
|
Builtin tools, optionally narrowed to the requested names. |
源代码位于: jianmu/tool/provider.py
ToolProvider
¶
Bases: Protocol
Lifecycle and resolution contract for dynamic tool sources.
Implement a provider when the available tool set depends on runtime context, external connections, or lazy initialization. Static tool lists do not need a provider; pass them directly to presets or executors instead.
BaseToolProvider
¶
No-op lifecycle base class shared by single/multi-agent tool providers.
initialize
async
¶
SuspendedToolCall
dataclass
¶
SuspendedToolCall(
tool: str,
arguments: Any = None,
tool_call_id: str = "",
request_id: str = "",
)
Persisted description of one suspended tool call.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
tool |
str
|
Canonical tool name associated with the suspension. |
arguments |
Any
|
Serialized arguments for the suspended tool call. |
tool_call_id |
str
|
Stable tool-call identifier when available. |
request_id |
str
|
Suspension request identifier associated with the tool call. |
from_dict
classmethod
¶
Parse one persisted suspended tool-call record.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
dict[str, Any] | None
|
Serialized suspended tool-call payload. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
'SuspendedToolCall | None'
|
Parsed suspended tool call, or |
源代码位于: jianmu/tool/resume.py
to_dict
¶
Serialize one suspended tool-call record.
返回:
| 类型 | 描述 |
|---|---|
dict[str, Any]
|
Dictionary payload suitable for runtime metadata storage. |
源代码位于: jianmu/tool/resume.py
SuspendedToolCallStore
¶
Interaction-bound store for suspended tool-call metadata.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
_interaction |
Interaction object used to read and write runtime metadata. |
Bind the store to one interaction instance.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
interaction
|
Any
|
Interaction object exposing runtime metadata helpers. |
必需 |
源代码位于: jianmu/tool/resume.py
read
¶
Return the persisted suspended tool call from runtime metadata.
返回:
| 类型 | 描述 |
|---|---|
SuspendedToolCall | None
|
Stored suspended tool call, or |
源代码位于: jianmu/tool/resume.py
write
¶
Persist one suspended tool call into runtime metadata.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
action
|
ToolCall
|
Tool call to persist. |
必需 |
request_id
|
str
|
Suspension request identifier associated with the call. |
''
|
源代码位于: jianmu/tool/resume.py
clear
¶
Remove the persisted suspended tool call from runtime metadata.
restore_actions
¶
Return the suspended tool call as the only action when one is persisted.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
actions
|
list[ToolCall]
|
Current tool-call candidates produced by the model or runtime. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
list[ToolCall]
|
Single suspended action when one is persisted, otherwise |
源代码位于: jianmu/tool/resume.py
persist_active
¶
Persist the current active suspension as a suspended tool call.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
actions
|
list[ToolCall]
|
Current tool-call candidates associated with the suspension. |
必需 |
suspended_action
|
ToolCall | None
|
Explicit suspended tool call override. |
None
|
返回:
| 类型 | 描述 |
|---|---|
bool
|
|
源代码位于: jianmu/tool/resume.py
Complete
dataclass
¶
Complete the current ReAct loop without committing an observation.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
state_patch |
Mapping[str, Any]
|
State updates applied before the loop completes. |
status |
Status
|
Final status propagated through ToolExecutor and ReAct. |
Observe
dataclass
¶
Signal that a tool result should be observed and ReAct should continue.
ToolCallBatch
dataclass
¶
One adjacent group of tool calls sharing an execution strategy.
ToolCall
dataclass
¶
Parsed tool-call request produced by an LLM response.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
str
|
Normalized tool name requested by the model. |
arguments |
Any
|
Parsed tool arguments payload, usually a dict or list. |
id |
Optional[str]
|
Optional provider-specific tool call identifier. |
from_dict
staticmethod
¶
Parse a raw tool-call payload into a normalized ToolCall.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
data
|
dict
|
Raw dictionary from a provider response, expected to contain
|
必需 |
返回:
| 类型 | 描述 |
|---|---|
Optional['ToolCall']
|
Normalized |
Optional['ToolCall']
|
or |
源代码位于: jianmu/tool/types.py
from_list
classmethod
¶
Normalize a raw action list into concrete ToolCall objects.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
items
|
Any
|
Items to process. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
list['ToolCall']
|
The resulting list of values. |
源代码位于: jianmu/tool/types.py
to_dict
¶
Convert the tool call into a plain dictionary payload.
返回:
| 类型 | 描述 |
|---|---|
dict
|
Dictionary with |
源代码位于: jianmu/tool/types.py
ToolResult
dataclass
¶
Normalized outcome of a tool execution.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
tool |
str
|
Name of the tool that was executed. |
ok |
bool
|
Whether the tool run completed successfully. |
output |
Any
|
Arbitrary tool output payload returned on success. |
error |
str | None
|
Human-readable error message returned on failure. |
from_raw
classmethod
¶
Normalize a raw tool outcome into a standard ToolResult.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
tool
|
str
|
The |
必需 |
raw
|
Any
|
The |
None
|
error
|
str | None
|
The |
None
|
返回:
| 类型 | 描述 |
|---|---|
'ToolResult'
|
The resulting |
源代码位于: jianmu/tool/types.py
to_dict
¶
Convert the tool result into a plain dictionary payload.
返回:
| 类型 | 描述 |
|---|---|
dict
|
Dictionary with |
源代码位于: jianmu/tool/types.py
FunctionTool
¶
FunctionTool(
name: str,
description: str,
fn: Callable[..., Any],
input_schema: Optional[dict] = None,
output_schema: Optional[dict] = None,
)
Bases: Tool
Wrap a Python callable as a Tool instance.
FunctionTool is the implementation returned by @tool. It preserves
the wrapped callable's name/docstring-derived metadata and can expose sync
or async functions through the common Tool interface.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
Public tool name exposed to callers. |
|
description |
Human-readable tool description. |
|
_fn |
Wrapped Python callable executed by the tool. |
Wrap a callable and optional schemas as a Tool object.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
name
|
str
|
Public tool name exposed to agents. |
必需 |
description
|
str
|
Human-readable tool description. |
必需 |
fn
|
Callable[..., Any]
|
Wrapped callable. |
必需 |
input_schema
|
Optional[dict]
|
Optional explicit JSON Schema for inputs. |
None
|
output_schema
|
Optional[dict]
|
Optional explicit JSON Schema for outputs. |
None
|
源代码位于: jianmu/tool/decorator.py
run
¶
Execute the wrapped callable.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to the wrapped function. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to the wrapped function. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
Any
|
The return value of the wrapped function. |
源代码位于: jianmu/tool/decorator.py
CalculatorTool
¶
Bases: Tool
Evaluate a math expression like 2+2 or 3*4-5.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
Public tool name exposed to callers. |
|
description |
Human-readable tool description. |
|
input_schema |
JSON schema describing the accepted expression input. |
|
output_schema |
JSON schema describing the result output. |
run
¶
Evaluate a restricted arithmetic expression.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
input
|
str
|
The arithmetic expression to evaluate. |
必需 |
返回:
| 类型 | 描述 |
|---|---|
str
|
The evaluation result as a string, or an error message. |
源代码位于: jianmu/tool/builtin/calculator.py
PythonREPLTool
¶
PythonREPLTool(
timeout: float = 30.0,
max_output_length: int = 10000,
allowed_modules: Optional[list] = None,
globals_dict: Optional[Dict[str, Any]] = None,
)
Bases: Tool
Execute Python code and return the output.
WARNING: This tool executes arbitrary Python code. Use with caution and consider sandboxing in production environments.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
timeout |
Maximum execution time in seconds. |
|
max_output_length |
Maximum output length returned to callers. |
|
allowed_modules |
Optional allowlist of permitted module names. |
|
_globals |
Global namespace used for code execution. |
|
_locals |
Dict[str, Any]
|
Local namespace preserved across executions. |
Initialize the Python REPL tool.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
timeout
|
float
|
Maximum execution time in seconds. |
30.0
|
max_output_length
|
int
|
Maximum output string length. |
10000
|
allowed_modules
|
Optional[list]
|
Optional list of allowed module names. |
None
|
globals_dict
|
Optional[Dict[str, Any]]
|
Optional globals dictionary for code execution. |
None
|
源代码位于: jianmu/tool/builtin/python_repl.py
run
async
¶
Execute Python code asynchronously with timeout.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
code
|
str | None
|
The Python code snippet to execute. |
None
|
**kwargs
|
Any
|
Extra parameters. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
str
|
The execution output (stdout/stderr or evaluation value) as a string. |
源代码位于: jianmu/tool/builtin/python_repl.py
FileReadTool
¶
FileReadTool(
max_file_size: int = 1000000,
allowed_extensions: Optional[list] = None,
base_path: Optional[str] = None,
)
Bases: Tool
Read contents of a file.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
max_file_size |
Maximum allowed file size for reads, in bytes. |
|
allowed_extensions |
Optional allowlist of permitted file extensions. |
|
base_path |
Optional root directory restricting accessible paths. |
Initialize the file-read tool.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
max_file_size
|
int
|
Maximum file size in bytes. |
1000000
|
allowed_extensions
|
Optional[list]
|
Optional list of allowed file extensions. |
None
|
base_path
|
Optional[str]
|
Optional base path used to restrict file access. |
None
|
源代码位于: jianmu/tool/builtin/file.py
run
async
¶
Read file contents.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
path
|
str | None
|
Path to the file. |
None
|
encoding
|
str
|
Text encoding of the file. |
'utf-8'
|
**kwargs
|
Any
|
Extra parameters. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
str
|
The text contents of the file. |
源代码位于: jianmu/tool/builtin/file.py
extract_path
staticmethod
¶
Return the normalized file path from one tool-call payload.
FileWriteTool
¶
FileWriteTool(
max_content_size: int = 1000000,
allowed_extensions: Optional[list] = None,
base_path: Optional[str] = None,
create_dirs: bool = True,
)
Bases: Tool
Write contents to a file.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
max_content_size |
Maximum allowed content size for writes, in bytes. |
|
allowed_extensions |
Optional allowlist of permitted file extensions. |
|
base_path |
Optional root directory restricting accessible paths. |
|
create_dirs |
Whether missing parent directories are created automatically. |
Initialize the file-write tool.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
max_content_size
|
int
|
Maximum content size in bytes. |
1000000
|
allowed_extensions
|
Optional[list]
|
Optional list of allowed file extensions. |
None
|
base_path
|
Optional[str]
|
Optional base path used to restrict file access. |
None
|
create_dirs
|
bool
|
Whether missing parent directories should be created. |
True
|
源代码位于: jianmu/tool/builtin/file.py
run
async
¶
run(
path: str | None = None,
content: str | None = None,
append: bool = False,
**kwargs: Any,
) -> str
Write or append UTF-8 content to a validated file path.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
path
|
str | None
|
Path to the file. |
None
|
content
|
str | None
|
The text content to write. |
None
|
append
|
bool
|
Whether to append rather than overwrite. |
False
|
**kwargs
|
Any
|
Extra parameters. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
str
|
A status message indicating success or failure. |
源代码位于: jianmu/tool/builtin/file.py
extract_path
staticmethod
¶
Return the normalized file path from one tool-call payload.
HTTPTool
¶
HTTPTool(
timeout: float = 30.0,
max_response_length: int = 50000,
default_headers: Optional[Dict[str, str]] = None,
retries: int = 3,
)
Bases: Tool
Make HTTP requests to external APIs.
Supports GET, POST, PUT, DELETE methods with JSON payloads.
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
timeout |
Per-request timeout in seconds. |
|
max_response_length |
Maximum response-body length returned to callers. |
|
default_headers |
Default headers merged into every request. |
|
retries |
Default retry count for transient request failures. |
Initialize the HTTP tool.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
timeout
|
float
|
Request timeout in seconds. |
30.0
|
max_response_length
|
int
|
Maximum response-body length returned to callers. |
50000
|
default_headers
|
Optional[Dict[str, str]]
|
Default headers included in all requests. |
None
|
retries
|
int
|
Default retry count for transient failures. |
3
|
源代码位于: jianmu/tool/builtin/http.py
parallel_decision_for_call
¶
Allow concurrent HTTP calls only when their method is read-only.
源代码位于: jianmu/tool/builtin/http.py
run
async
¶
run(
url: str | None = None,
method: str = "GET",
headers: Optional[Dict[str, str]] = None,
body: Optional[Dict[str, Any]] = None,
retries: Optional[int] = None,
**kwargs: Any,
) -> str
Make an HTTP request.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
url
|
str | None
|
The destination URL. |
None
|
method
|
str
|
HTTP method (e.g. GET, POST). |
'GET'
|
headers
|
Optional[Dict[str, str]]
|
Optional dictionary of HTTP headers. |
None
|
body
|
Optional[Dict[str, Any]]
|
Optional dictionary to send as JSON body. |
None
|
retries
|
Optional[int]
|
Number of retry attempts. |
None
|
**kwargs
|
Any
|
Extra parameters. |
{}
|
返回:
| 类型 | 描述 |
|---|---|
str
|
The HTTP response status and body as a string. |
源代码位于: jianmu/tool/builtin/http.py
DuckDuckGoSearchTool
¶
Bases: Tool
DuckDuckGo web search (no API key required).
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
name |
Public tool name exposed to callers. |
|
description |
Human-readable tool description. |
|
_ddgs_cls |
Lazily imported DuckDuckGo client class. |
Resolve the DuckDuckGo client dependency lazily.
源代码位于: jianmu/tool/builtin/duckduckgo.py
run
async
¶
Execute search via DDG.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
query
|
str
|
The search query string. |
必需 |
max_results
|
int
|
The maximum number of search results to return. |
5
|
返回:
| 类型 | 描述 |
|---|---|
str
|
The search results formatted as a string. |
源代码位于: jianmu/tool/builtin/duckduckgo.py
tool
¶
tool(
_func: Optional[Callable[..., Any]] = None,
*,
name: Optional[str] = None,
description: Optional[str] = None,
input_schema: Optional[dict] = None,
output_schema: Optional[dict] = None,
) -> (
FunctionTool
| Callable[[Callable[..., Any]], FunctionTool]
)
Decorator to wrap a function into a Tool instance.
Can be used with or without arguments::
@tool
def my_tool(input): ...
@tool(name="custom")
def my_tool(input): ...
The wrapped function becomes a first-class Tool object, so it can be
passed directly into ToolExecutor or converted to JSON tool schema for
model providers.
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
_func
|
Optional[Callable[..., Any]]
|
The function to wrap when used without parentheses. |
None
|
name
|
Optional[str]
|
Optional tool name override (defaults to the function name). |
None
|
description
|
Optional[str]
|
Optional description override (defaults to docstring). |
None
|
input_schema
|
Optional[dict]
|
Optional JSON Schema for the tool input. |
None
|
output_schema
|
Optional[dict]
|
Optional JSON Schema for the tool output. |
None
|
返回:
| 类型 | 描述 |
|---|---|
FunctionTool | Callable[[Callable[..., Any]], FunctionTool]
|
A |
FunctionTool | Callable[[Callable[..., Any]], FunctionTool]
|
that produces one. |