agents.discovery.dynamic_tool_selector¶
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¶
Context-aware tool selector that considers conversation history. |
|
State information for context-aware tool selection. |
|
Dynamic tool selector implementing LangGraph-style patterns. |
|
LangGraph-style tool selector with state-based selection. |
|
Tool selection modes. |
|
Strategies for binding tools to LLM. |
|
Result of tool selection process. |
|
Protocol for tool selection strategies. |
|
Statistics for tool usage and performance. |
Functions¶
|
Create a context-aware tool selector. |
|
Create a dynamic tool selector with sensible defaults. |
|
Create a LangGraph-style tool selector. |
Module Contents¶
- class agents.discovery.dynamic_tool_selector.ContextAwareSelector(**kwargs)¶
Bases:
DynamicToolSelector
Context-aware tool selector that considers conversation history.
Init .
- Returns:
Add return description]
- Return type:
[TODO
- async select_with_conversation_context(query, conversation_history, user_preferences=None)¶
Select tools considering full conversation context.
- Parameters:
- Return type:
- class agents.discovery.dynamic_tool_selector.ContextAwareState(/, **data)¶
Bases:
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.
- Parameters:
data (Any)
- class agents.discovery.dynamic_tool_selector.DynamicToolSelector(/, **data)¶
Bases:
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.
- Parameters:
data (Any)
- async analyze_tool_performance()¶
Analyze tool performance and provide insights.
- async bind_tools_to_llm(llm_instance, selected_tools, strategy=None)¶
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.
- Parameters:
llm_instance (Any)
selected_tools (list[langchain_core.tools.BaseTool])
strategy (ToolBindingStrategy)
- Return type:
Any
- async iterative_tool_refinement(initial_query, llm_response, execution_results, max_iterations=3)¶
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.
- async select_tools_for_query(query, available_tools=None, context=None, force_refresh=False)¶
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.
- setup_selector()¶
Setup the tool selector with default components.
- Return type:
- class agents.discovery.dynamic_tool_selector.LangGraphStyleSelector(/, **data)¶
Bases:
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.
- Parameters:
data (Any)
- 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.
- Return type:
- async select_tools_with_state(state, available_tools=None)¶
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.
- Parameters:
- Return type:
- class agents.discovery.dynamic_tool_selector.SelectionMode¶
-
Tool selection modes.
Initialize self. See help(type(self)) for accurate signature.
- class agents.discovery.dynamic_tool_selector.ToolBindingStrategy¶
-
Strategies for binding tools to LLM.
Initialize self. See help(type(self)) for accurate signature.
- class agents.discovery.dynamic_tool_selector.ToolSelectionResult(/, **data)¶
Bases:
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.
- Parameters:
data (Any)
- class agents.discovery.dynamic_tool_selector.ToolSelectionStrategy¶
Bases:
Protocol
Protocol for tool selection strategies.
- async select_tools(query, available_tools, context, max_tools=5)¶
Select tools based on strategy.
- Parameters:
query (str)
available_tools (list[haive.core.registry.ComponentMetadata])
context (ContextAwareState)
max_tools (int)
- Return type:
- class agents.discovery.dynamic_tool_selector.ToolUsageStats(/, **data)¶
Bases:
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.
- Parameters:
data (Any)
- agents.discovery.dynamic_tool_selector.create_context_aware_selector(max_tools=5, min_confidence=0.7)¶
Create a context-aware tool selector.
- Parameters:
- Return type:
- agents.discovery.dynamic_tool_selector.create_dynamic_tool_selector(selection_mode=SelectionMode.DYNAMIC, max_tools=5, semantic_discovery=None)¶
Create a dynamic tool selector with sensible defaults.
- Parameters:
selection_mode (SelectionMode)
max_tools (int)
semantic_discovery (SemanticDiscoveryEngine | None)
- Return type:
- agents.discovery.dynamic_tool_selector.create_langgraph_style_selector(max_tools=5, learning_enabled=True)¶
Create a LangGraph-style tool selector.
- Parameters:
- Return type: