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 a tool that can be interrupted. |
|
Create a tool to do retrieval of documents. |
|
Create a tool that interacts with state. |
|
Create a tool that produces structured output. |
|
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