haive.agents.discovery.dynamic_tool_selector ============================================ .. py:module:: haive.agents.discovery.dynamic_tool_selector .. autoapi-nested-parse:: Dynamic Tool Selector implementing LangGraph-style tool management patterns. This module implements sophisticated tool selection and management patterns inspired by LangGraph's many-tools approach, providing dynamic tool binding, context-aware selection, and intelligent tool routing. Key Features: - Dynamic tool selection and binding like LangGraph - Context-aware tool recommendation - Intelligent tool routing and management - State-aware tool selection - Tool usage learning and optimization Classes ------- .. autoapisummary:: haive.agents.discovery.dynamic_tool_selector.ContextAwareSelector haive.agents.discovery.dynamic_tool_selector.ContextAwareState haive.agents.discovery.dynamic_tool_selector.DynamicToolSelector haive.agents.discovery.dynamic_tool_selector.LangGraphStyleSelector haive.agents.discovery.dynamic_tool_selector.SelectionMode haive.agents.discovery.dynamic_tool_selector.ToolBindingStrategy haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult haive.agents.discovery.dynamic_tool_selector.ToolSelectionStrategy haive.agents.discovery.dynamic_tool_selector.ToolUsageStats Functions --------- .. autoapisummary:: haive.agents.discovery.dynamic_tool_selector.create_context_aware_selector haive.agents.discovery.dynamic_tool_selector.create_dynamic_tool_selector haive.agents.discovery.dynamic_tool_selector.create_langgraph_style_selector Module Contents --------------- .. py:class:: ContextAwareSelector(**kwargs) Bases: :py:obj:`DynamicToolSelector` Context-aware tool selector that considers conversation history. Init . :returns: Add return description] :rtype: [TODO .. py:method:: select_with_conversation_context(query, conversation_history, user_preferences = None) :async: Select tools considering full conversation context. .. py:class:: ContextAwareState(/, **data) Bases: :py:obj:`pydantic.BaseModel` State information for context-aware tool selection. Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name. .. py:class:: DynamicToolSelector(/, **data) Bases: :py:obj:`haive.core.common.mixins.tool_route_mixin.ToolRouteMixin` Dynamic tool selector implementing LangGraph-style patterns. This class provides sophisticated tool selection capabilities that adapt to query content, context, and usage patterns, similar to LangGraph's approach to handling many tools. Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name. .. py:method:: analyze_tool_performance() :async: Analyze tool performance and provide insights. .. py:method:: bind_tools_to_llm(llm_instance, selected_tools, strategy = None) :async: Bind selected tools to LLM instance using specified strategy. This implements the LangGraph pattern of dynamically binding tools to the language model based on the current query context. .. py:method:: iterative_tool_refinement(initial_query, llm_response, execution_results, max_iterations = 3) :async: Iteratively refine tool selection based on execution feedback. This implements an advanced pattern where tool selection is refined based on the results of previous tool executions, similar to LangGraph's iterative approaches. .. py:method:: select_tools_for_query(query, available_tools = None, context = None, force_refresh = False) :async: Select optimal tools for a given query using LangGraph-style selection. This is the main entry point for tool selection, implementing the LangGraph pattern of dynamically selecting relevant tools based on query content and context. .. py:method:: setup_selector() Setup the tool selector with default components. .. py:class:: LangGraphStyleSelector(/, **data) Bases: :py:obj:`DynamicToolSelector` LangGraph-style tool selector with state-based selection. This class specifically implements the LangGraph pattern of using state to determine tool selection and binding. Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name. .. py:method:: create_tool_selection_node() Create a node function for LangGraph that selects tools. This returns a function that can be used as a node in a LangGraph workflow for dynamic tool selection. .. py:method:: select_tools_with_state(state, available_tools = None) :async: Select tools based on LangGraph-style state. This method implements the LangGraph pattern where tool selection is based on the current state of the conversation/workflow. .. py:class:: SelectionMode Bases: :py:obj:`str`, :py:obj:`enum.Enum` Tool selection modes. Initialize self. See help(type(self)) for accurate signature. .. py:class:: ToolBindingStrategy Bases: :py:obj:`str`, :py:obj:`enum.Enum` Strategies for binding tools to LLM. Initialize self. See help(type(self)) for accurate signature. .. py:class:: ToolSelectionResult(/, **data) Bases: :py:obj:`pydantic.BaseModel` Result of tool selection process. Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name. .. py:class:: ToolSelectionStrategy Bases: :py:obj:`Protocol` Protocol for tool selection strategies. .. py:method:: select_tools(query, available_tools, context, max_tools = 5) :async: Select tools based on strategy. .. py:class:: ToolUsageStats(/, **data) Bases: :py:obj:`pydantic.BaseModel` Statistics for tool usage and performance. Create a new model by parsing and validating input data from keyword arguments. Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. `self` is explicitly positional-only to allow `self` as a field name. .. py:function:: create_context_aware_selector(max_tools = 5, min_confidence = 0.7) Create a context-aware tool selector. .. py:function:: create_dynamic_tool_selector(selection_mode = SelectionMode.DYNAMIC, max_tools = 5, semantic_discovery = None) Create a dynamic tool selector with sensible defaults. .. py:function:: create_langgraph_style_selector(max_tools = 5, learning_enabled = True) Create a LangGraph-style tool selector.