STATEK
API Reference
Tools

Tools

Tools are Python callables exposed to STATEK jobs. Decorators attach metadata used by prompt formatting, provider tool payloads, and execution.

SymbolImport pathPurposeStability
toolstatek.system or statekMark a callable as an agent toolCore
subtaskstatek.system or statekMark a callable as a subtask factoryCore
error_handlerstatek.system or statekMark a job termination handlerCore
docstr, briefstatek.system or statekPrint LLM-facing documentationCore system tools
panicstatek.systemRaise current task difficultyCore system tool
python_clistatek.systemExecute code in DIRECT chat styleCore system tool
find_sub_task_handlerstatek.system or statekFind completed subtask notificationsCore system tool
docs_stylestatek.system or statekConfigure docstring formattingAdvanced
get_any, get_allstatek.system or statekTool wrappers for future combinationAdvanced

@tool

def tool(
    f=None,
    *,
    system: bool = False,
    target=None,
    error_handler=None,
    hidden: bool = False,
)

Marks a sync or async callable as a STATEK tool.

Parameters

NameDescription
fCallable when used as @tool; omitted when used as @tool(...).
systemClassifies the tool as system-level rather than application-level.
targetOptional ChatStyle or collection of styles for filtering.
error_handlerOptional valid @error_handler callable registered with the tool result.
hiddenExcludes the tool from LLM-facing discovery and provider tool payloads.

Returns: a wrapped callable with STATEK tool metadata.

Raises: TypeError when the error handler protocol is invalid or the callable signature cannot accept STATEK context injection.

from statek import tool
 
@tool
def lookup_order(order_id: str, **kwargs) -> str:
    """Return a short order summary."""
    return f"order={order_id}"

@subtask

def subtask(f=None, *, system: bool = False, target=None)

Marks a callable as a subtask factory. The decorated callable must accept **kwargs and return Job or SubTaskHandler. The wrapper exposes a framework-managed optional id.

Returns: a tool wrapper whose return annotation is SubTaskHandler.

Raises: TypeError for invalid signatures or unsupported return values.

from statek import subtask
from statek.task import create_new_job
 
@subtask
def research_topic(topic: str, **kwargs):
    return create_new_job(researcher, topic=topic)

@error_handler

def error_handler(func: Callable) -> Callable

Marks a callable as a job error handler. A valid handler name starts with _ and accepts (context, error=None).

For cleanup usage, deferred future registration, and critical-error behavior, see Error Handling.

from statek import error_handler, tool
 
@error_handler
def _notify_user(user_id: str, error=None):
    print(f"job failed for {user_id}: {error}")
 
@tool(error_handler=_notify_user)
def reserve_for_user(user_id: str, **kwargs) -> str:
    return user_id

System documentation tools

FunctionSignatureDescription
docstrdocstr(what, method_name=None, **kwargs)Prints detailed documentation for a tool, class, object, or method.
briefbrief(what, method_name=None, **kwargs)Prints short documentation for a tool, class, object, or method.
docs_styledocs_style(f=None, *, brief_types=False)Advanced decorator for adjusting generated docs.

These tools print to the current job console and return None.

See Agent-Exposed Docstring Conventions for supported docstring sections, VARIANTS/:.../TOOL:..., brief signatures, and STATEK-ACL.

Runtime system tools

FunctionSignatureReturnsErrors
panicpanic(**kwargs)NoneRaises RuntimeError outside a job context.
python_clipython_cli(code: str, **kwargs)NoneExecutes through the job step machinery in DIRECT style.
find_sub_task_handlerfind_sub_task_handler(id=None, **kwargs)`SubTaskHandlerNone`
get_anyget_any(*args, **kwargs)CombinedFutureResultRaises from future evaluation when no value is ready.
get_allget_all(*args, **kwargs)CombinedFutureResultRaises from future evaluation when not all values are ready.

Related APIs: Subtasks, Futures, Chat Styles.