agents.discovery.selection_strategies

Tool selection strategies for dynamic tool selection.

This module implements various strategies for selecting tools based on different criteria and approaches, providing flexibility in how tools are chosen for different contexts and use cases.

Classes

AdaptiveSelectionStrategy

Adaptive selection that learns from usage patterns.

BaseSelectionStrategy

Base class for tool selection strategies.

CapabilityBasedStrategy

Capability-based tool selection.

ContextualSelectionStrategy

Context-aware tool selection considering conversation history.

EnsembleSelectionStrategy

Ensemble strategy combining multiple selection approaches.

LearningSelectionStrategy

Selection strategy that learns from user feedback and tool performance.

SemanticSelectionStrategy

Semantic similarity-based tool selection.

Functions

create_selection_strategy(strategy_name, **kwargs)

Create a selection strategy by name.

Module Contents

class agents.discovery.selection_strategies.AdaptiveSelectionStrategy(learning_rate=0.1)

Bases: BaseSelectionStrategy

Adaptive selection that learns from usage patterns.

Init .

Parameters:

learning_rate (float) – [TODO: Add description]

async select_tools(query, available_tools, context, max_tools=5)

Select tools using adaptive learning.

Parameters:
  • query (str)

  • available_tools (list[haive.agents.discovery.semantic_discovery.ComponentMetadata])

  • context (haive.agents.discovery.dynamic_tool_selector.ContextAwareState)

  • max_tools (int)

Return type:

haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult

update_performance(tool_name, success)

Update tool performance based on execution results.

Parameters:
Return type:

None

class agents.discovery.selection_strategies.BaseSelectionStrategy

Bases: abc.ABC

Base class for tool selection strategies.

abstractmethod select_tools(query, available_tools, context, max_tools=5)
Async:

Parameters:
  • query (str)

  • available_tools (list[haive.agents.discovery.semantic_discovery.ComponentMetadata])

  • context (haive.agents.discovery.dynamic_tool_selector.ContextAwareState)

  • max_tools (int)

Return type:

haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult

Select tools based on strategy.

class agents.discovery.selection_strategies.CapabilityBasedStrategy(capability_weights=None)

Bases: BaseSelectionStrategy

Capability-based tool selection.

Init .

Parameters:

capability_weights (dict[str, float] | None) – [TODO: Add description]

async select_tools(query, available_tools, context, max_tools=5)

Select tools based on capability matching.

Parameters:
  • query (str)

  • available_tools (list[haive.agents.discovery.semantic_discovery.ComponentMetadata])

  • context (haive.agents.discovery.dynamic_tool_selector.ContextAwareState)

  • max_tools (int)

Return type:

haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult

class agents.discovery.selection_strategies.ContextualSelectionStrategy(context_weight=0.3)

Bases: BaseSelectionStrategy

Context-aware tool selection considering conversation history.

Init .

Parameters:

context_weight (float) – [TODO: Add description]

async select_tools(query, available_tools, context, max_tools=5)

Select tools considering full context.

Parameters:
  • query (str)

  • available_tools (list[haive.agents.discovery.semantic_discovery.ComponentMetadata])

  • context (haive.agents.discovery.dynamic_tool_selector.ContextAwareState)

  • max_tools (int)

Return type:

haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult

class agents.discovery.selection_strategies.EnsembleSelectionStrategy(strategies=None)

Bases: BaseSelectionStrategy

Ensemble strategy combining multiple selection approaches.

Init .

Parameters:

strategies (list[BaseSelectionStrategy] | None) – [TODO: Add description]

async select_tools(query, available_tools, context, max_tools=5)

Select tools using ensemble of strategies.

Parameters:
  • query (str)

  • available_tools (list[haive.agents.discovery.semantic_discovery.ComponentMetadata])

  • context (haive.agents.discovery.dynamic_tool_selector.ContextAwareState)

  • max_tools (int)

Return type:

haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult

class agents.discovery.selection_strategies.LearningSelectionStrategy

Bases: BaseSelectionStrategy

Selection strategy that learns from user feedback and tool performance.

Init .

Returns:

Add return description]

Return type:

[TODO

add_feedback(tool_name, rating, context, feedback_data)

Add user feedback for learning.

Parameters:
Return type:

None

async select_tools(query, available_tools, context, max_tools=5)

Select tools using learned patterns and feedback.

Parameters:
  • query (str)

  • available_tools (list[haive.agents.discovery.semantic_discovery.ComponentMetadata])

  • context (haive.agents.discovery.dynamic_tool_selector.ContextAwareState)

  • max_tools (int)

Return type:

haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult

class agents.discovery.selection_strategies.SemanticSelectionStrategy(similarity_threshold=0.7)

Bases: BaseSelectionStrategy

Semantic similarity-based tool selection.

Init .

Parameters:

similarity_threshold (float) – [TODO: Add description]

async select_tools(query, available_tools, context, max_tools=5)

Select tools based on semantic similarity to query.

Parameters:
  • query (str)

  • available_tools (list[haive.agents.discovery.semantic_discovery.ComponentMetadata])

  • context (haive.agents.discovery.dynamic_tool_selector.ContextAwareState)

  • max_tools (int)

Return type:

haive.agents.discovery.dynamic_tool_selector.ToolSelectionResult

agents.discovery.selection_strategies.create_selection_strategy(strategy_name, **kwargs)

Create a selection strategy by name.

Parameters:

strategy_name (str)

Return type:

BaseSelectionStrategy