haive.core.engine.tool.factoriesΒΆ

Tool factory functions for creating specialized tools.

This module provides factory functions for creating different types of tools including retriever tools, structured output tools, and validation tools.

FunctionsΒΆ

create_interruptible_tool(func[, name, description, ...])

Create a tool that can be interrupted.

create_retriever_tool(retriever, name, description, *)

Create a tool to do retrieval of documents.

create_state_tool(func[, name, description, ...])

Create a tool that interacts with state.

create_structured_output_tool(func, name, description, ...)

Create a tool that produces structured output.

create_validation_tool(validator_func, name, ...[, ...])

Create a tool for validation.

Module ContentsΒΆ

haive.core.engine.tool.factories.create_interruptible_tool(func, name=None, description=None, *, interrupt_message='Tool execution interrupted')ΒΆ

Create a tool that can be interrupted.

Can wrap existing tools to add interruption capability.

Parameters:
  • func (collections.abc.Callable[Ellipsis, Any] | langchain_core.tools.StructuredTool | BaseTool) – The function or existing tool to wrap

  • name (str | None) – Tool name (uses existing if wrapping)

  • description (str | None) – Tool description (uses existing if wrapping)

  • interrupt_message (str) – Message to show when interrupted

Returns:

A StructuredTool with interruption support

Return type:

langchain_core.tools.StructuredTool

haive.core.engine.tool.factories.create_retriever_tool(retriever, name, description, *, document_prompt=None, document_separator='\n\n', response_format='content')ΒΆ

Create a tool to do retrieval of documents.

This wraps the LangChain create_retriever_tool and adds proper tool capabilities metadata.

Parameters:
  • retriever (langchain_core.retrievers.BaseRetriever) – The retriever to use for document retrieval

  • name (str) – The name for the tool

  • description (str) – The description for the tool

  • document_prompt (langchain_core.prompts.BasePromptTemplate | None) – Optional prompt to format documents

  • document_separator (str) – Separator between documents

  • response_format (Literal['content', 'content_and_artifact']) – Format for tool response

Returns:

A StructuredTool configured for retrieval

Return type:

langchain_core.tools.StructuredTool

haive.core.engine.tool.factories.create_state_tool(func, name=None, description=None, *, reads_state=False, writes_state=False, state_keys=None)ΒΆ

Create a tool that interacts with state.

This creates a tool with explicit state interaction declarations. Can wrap existing tools or create new ones.

Parameters:
  • func (collections.abc.Callable[Ellipsis, Any] | langchain_core.tools.StructuredTool | BaseTool) – The function or existing tool to wrap

  • name (str | None) – Tool name (uses existing if wrapping)

  • description (str | None) – Tool description (uses existing if wrapping)

  • reads_state (bool) – Whether tool reads from state

  • writes_state (bool) – Whether tool writes to state

  • state_keys (list[str] | None) – Specific state keys the tool interacts with

Returns:

A StructuredTool with state interaction metadata

Return type:

langchain_core.tools.StructuredTool

haive.core.engine.tool.factories.create_structured_output_tool(func, name, description, output_model, *, infer_schema=True)ΒΆ

Create a tool that produces structured output.

This creates a tool from a function that guarantees structured output according to the provided Pydantic model.

Parameters:
  • func (collections.abc.Callable[Ellipsis, Any]) – The function to wrap as a tool

  • name (str) – Tool name

  • description (str) – Tool description

  • output_model (type[pydantic.BaseModel]) – Pydantic model for output validation

  • infer_schema (bool) – Whether to infer input schema from function

Returns:

A StructuredTool with structured output guarantees

Return type:

langchain_core.tools.StructuredTool

haive.core.engine.tool.factories.create_validation_tool(validator_func, name, description, *, input_model=None, error_on_invalid=False)ΒΆ

Create a tool for validation.

This creates a tool that validates input according to custom logic and returns validation results.

Parameters:
  • validator_func (collections.abc.Callable[[Any], bool | tuple[bool, str]]) – Function that validates input, returns bool or (bool, message)

  • name (str) – Tool name

  • description (str) – Tool description

  • input_model (type[pydantic.BaseModel] | None) – Optional Pydantic model for input validation

  • error_on_invalid (bool) – Whether to raise exception on invalid input

Returns:

A StructuredTool configured for validation

Return type:

langchain_core.tools.StructuredTool