Tool#
- class scikitplot.agent.Tool(name, function, description='', parameters=None, effect=ToolEffect.READ, scopes=frozenset({}), cost=1.0, idempotent=None)[source]#
One callable tool and the facts the gate chain decides on.
- Parameters:
- namestr
1 to 64 characters,
[A-Za-z_][A-Za-z0-9_-]*: the name a planner uses to call it.- functioncallable
Called with the validated arguments as keyword arguments. It must return a JSON value (see
plain); anything else is reported astool_result_not_json.- descriptionstr, default=””
What the tool does, for the planner.
- parametersmapping or None, default=None
The JSON Schema of the arguments, in the subset of
scikitplot.agent._schema; its root is a closed object.Noneis a tool without arguments.- effectToolEffect or str, default=”read”
Its kind of effect.
- scopesiterable of str, default=()
Scopes a policy must grant before the tool runs (
"corpus:read").- costfloat, default=1.0
Budget units one call costs, in the caller’s unit (Budget gate).
- idempotentbool or None, default=None
Whether a call may be repeated with the same effect.
NoneisTruefor areadtool andFalseotherwise. A call of a non-idempotent tool that was in flight when a run stopped is not repeated at resume (tool_interrupted).
- Raises:
- TypeError
If a field has the wrong type.
- ValueError
If
nameor a scope is malformed, orcostis negative or not finite.- SchemaError
If
parametersis outside the supported subset, or does not fit the function’s signature: a property the function cannot take as a keyword, or a parameter without a default that the schema does not require.
- Parameters:
Examples
>>> from scikitplot.agent import Tool >>> def add(a, b=0): ... return a + b >>> tool = Tool( ... "add", ... add, ... parameters={ ... "type": "object", ... "properties": {"a": {"type": "integer"}, "b": {"type": "integer"}}, ... "required": ["a"], ... "additionalProperties": False, ... }, ... ) >>> tool.effect.value, tool.idempotent ('read', True)
- effect: ToolEffect = 'read'[source]#