H.Tool behaviour (H v0.3.0)

Copy Markdown View Source

Behaviour and JSON Schema validation helper for durable tools in H.

The coordinator binds the built-in coding tools' working directory before acquiring a lease or calling execute/2. Workers use the bound context.env. Read Security boundaries on hiness.dev before exposing host tools to external context.

Summary

Functions

Validates decoded JSON tool arguments against tool_mod.parameters_schema/0 via cached JSV root.

Types

context()

@type context() :: %{
  :env => H.ExecutionEnv.t(),
  :session_id => String.t(),
  :conversation_id => pos_integer(),
  optional(:task_id) => pos_integer(),
  optional(:scan_entries) => (map() -> {:ok, map()} | {:error, term()}),
  optional(:on_output) => (String.t(), non_neg_integer() -> any()),
  optional(:timeout_ms) => pos_integer()
}

tool_output()

@type tool_output() :: %{
  content: [map()],
  details: map(),
  is_error: boolean(),
  diagnostic: nil | String.t()
}

Callbacks

description()

@callback description() :: String.t()

execute(args, context)

@callback execute(args :: map(), context()) ::
  {:ok, tool_output()} | {:error, tool_output()}

mutating?()

@callback mutating?() :: boolean()

name()

@callback name() :: String.t()

parameters_schema()

@callback parameters_schema() :: map()

replay()

@callback replay() :: :safe | :unsafe

Functions

validate_args(tool_mod, args)

@spec validate_args(module(), term()) :: {:ok, map()} | {:error, String.t()}

Validates decoded JSON tool arguments against tool_mod.parameters_schema/0 via cached JSV root.