Tools

Tools to conquer the world of AI

FloAI is designed to be compatible with Langchain tools, meaning you can seamlessly integrate any tool from Langchain and utilize it within FloAI workflows.

If you are already familiar with Langchain tools, you’ll find it easy to import and build tools that work out of the box with FloAI’s agentic architecture.

FloAI provides the docorator @flotool to build your own tools eaily.

Building your tools

Creating custom tools in FloAI is as easy as defining a function and wrapping it with the @flotool decorator from FloAI. Here’s a breakdown of how to build different types of tools.

Simple Function Tool

Here is how you build a tool to numbers:

from flo_ai.tools import flotool

class AdditionToolInput(BaseModel):
    numbers: List[int] = Field(..., description='List of numbers to add')

@flotool(name='AdditionTool', description='Tool to add numbers', argument_contract=AdditionToolInput)
def addition_tool(numbers: List[int]) -> str:
    result = sum(numbers)
    return f'The sum is {result}'

flotool also supports async:

from flo_ai.tools import flotool

class AdditionToolInput(BaseModel):
    numbers: List[int] = Field(..., description='List of numbers to add')

@flotool(name='AdditionTool', description='Tool to add numbers', argument_contract=AdditionToolInput)
async def addition_tool(numbers: List[int]) -> str:
    result = sum(numbers)
    await asyncio.sleep(1)
    return f'The sum is {result}'

When using async tools, dont forget to use async_invoke instead of invoke while running flo

Using langchain BaseTool class

from langchain.tools import BaseTool
from typing import Optional

# Create a custom tool by extending BaseTool
class MultiplyTool(BaseTool):
    name = "Multiply Tool"
    description = "This tool multiplies two numbers and returns the result."

    def _run(self, a: int, b: int) -> int:
        """Execute the tool synchronously."""
        return a * b

    async def _arun(self, a: int, b: int) -> int:
        """Execute the tool asynchronously (required by BaseTool)."""
        # For async functionality, you'd normally await an async call here.
        return a * b

Langchain tools can also be more complex, interacting with external APIs or handling more sophisticated logic. The flexibility of FloAI allows you to compose these tools into your agent workflows.

For more information on creating and utilizing Langchain tools, please refer to the Langchain Tools Documentation.

Here are some popular pre-built tools: https://python.langchain.com/v0.1/docs/integrations/tools/

Last updated