agentconnect.prompts.tools module

Tool definitions for the AgentConnect framework.

This module provides tools that agents can use to interact with each other, search for specialized agents, and collaborate on tasks. These tools are designed to be used with LangGraph workflows and LLM-based agents.

Key components:

  • Agent search tools: Find agents with specific capabilities

  • Collaboration tools: Send requests to other agents and manage responses

  • Task decomposition tools: Break complex tasks into manageable subtasks

  • Tool registry: Central registry for managing available tools

The tools in this module are designed to be used within the agent’s workflow to enable seamless agent-to-agent communication and collaboration.

class PromptTools(agent_registry=None, communication_hub=None, llm=None)

Bases: object

Class for creating and managing tools for agent prompts.

This class is responsible for creating, registering, and managing the tools that agents can use to perform actions such as searching for other agents, sending collaboration requests, and decomposing tasks.

Each agent has its own isolated set of tools through a dedicated ToolRegistry instance, ensuring that tools are properly configured for the specific agent using them.

The class supports both connected mode (with registry and hub) and standalone mode (without registry and hub, for direct chat interactions).

Parameters:
agent_registry

Registry for accessing agent information, can be None in standalone mode

communication_hub

Hub for agent communication, can be None in standalone mode

llm

Optional language model for tools that require LLM capabilities

_current_agent_id

ID of the agent currently using these tools

_tool_registry

Registry for managing available tools

_available_capabilities

Cached list of available capabilities

_agent_specific_tools_registered

Flag indicating if agent-specific tools are registered

_is_standalone_mode

Flag indicating if operating in standalone mode (without registry/hub)

create_tool_from_function(func, name, description, args_schema, category=None, coroutine=None)

Create a tool from a function with proper async support.

This method creates a LangChain StructuredTool that can be used in agent workflows. It supports both synchronous and asynchronous implementations of the tool, allowing for efficient handling of I/O-bound operations.

The tool is automatically registered in the tool registry with the specified category, making it available for agent use.

Parameters:
  • func (Callable[..., Any]) – The synchronous function implementation

  • name (str) – Name of the tool (must be unique)

  • description (str) – Description of the tool that will be shown to the agent

  • args_schema (Type[TypeVar(T, bound= BaseModel)]) – Pydantic model for the tool’s arguments validation

  • category (Optional[str]) – Optional category for the tool (e.g., ‘collaboration’, ‘task_management’)

  • coroutine (Optional[Callable[..., Awaitable[Any]]]) – Optional async implementation of the function for better performance

Return type:

StructuredTool

Returns:

A StructuredTool that can be used in LangChain workflows

Note

If both sync and async implementations are provided, the async version will be used when the agent is running in an async context.

create_agent_search_tool()

Create a tool for searching agents by capability.

Return type:

StructuredTool

create_send_collaboration_request_tool()

Create a tool for sending collaboration requests to other agents.

Return type:

StructuredTool

create_check_collaboration_result_tool()

Create a tool for checking the status of sent collaboration requests.

Return type:

StructuredTool

create_task_decomposition_tool()

Create a tool for decomposing complex tasks into subtasks.

This tool helps agents break down complex tasks into smaller, more manageable subtasks. It’s useful for organizing and prioritizing work, especially for multi-step processes that would be difficult to tackle as a single unit.

The tool uses the LLM to analyze the task and create a structured decomposition with clear, actionable subtasks. Each subtask includes a unique ID, title, and description.

Return type:

StructuredTool

Returns:

A StructuredTool for task decomposition that can be used in agent workflows

Note

If the LLM is not available, the tool will fall back to a simple rule-based decomposition.

set_current_agent(agent_id)

Set the current agent ID for context in tools.

This method establishes the context for which agent is using the tools, which is essential for agent-specific tools like collaboration requests. It also triggers the registration of agent-specific tools if they haven’t been registered yet.

Parameters:

agent_id (str) – The ID of the agent currently using the tools

Return type:

None

Note

This method logs whenever the agent context changes to help with debugging and tracing agent interactions.

get_tools_for_workflow(categories=None, agent_id=None)

Get tools for a specific workflow based on categories.

This method retrieves the appropriate tools for a workflow, optionally filtered by category. It’s used by agent workflows to get the tools they need for specific tasks.

Parameters:
  • categories (Optional[List[str]]) – List of tool categories to include (e.g., ‘collaboration’, ‘task_management’)

  • agent_id (Optional[str]) – ID of the agent that will use these tools (for logging only, doesn’t change context)

Return type:

List[StructuredTool]

Returns:

List of StructuredTool instances configured for the agent

Note

If categories is None, all tools in the registry will be returned. The agent_id parameter is used only for logging and doesn’t change the current agent context.

property is_standalone_mode: bool

Check if the PromptTools instance is running in standalone mode.

Returns:

True if running in standalone mode (without registry/hub), False if running in connected mode (with registry/hub)