Toolkit

In this documentation, we will cover the essential aspects of the Yeager AI Toolkit, including its components, tools, and usage. We will also provide examples and explain how to create custom tools for your agents.

Toolkit

The Yeager AI Toolkit is a collection of pre-built tools designed to simplify the development process and enhance the capabilities of your AI agents. It is based on the YeagerAIToolkit class, which allows users to register and manage tools for their agents.

from yeagerai import YeagerAIToolkit, YeagerAITool

class CustomTool(YeagerAITool):
    ...

# Register the custom tool in the YeagerAIToolkit
toolkit = YeagerAIToolkit()
toolkit.register_tool(CustomTool)

Tools

Tools in Yeager AI are specific functionalities or features that can be added to your agents. They are built upon the YeagerAITool class and can be registered in the YeagerAIToolkit for easy access and management.

Creating Custom Tools

To create a custom tool, follow these steps:

  1. Define the tool's specifications.

  2. Create a solution sketch.

  3. Implement the tool as a Python class, inheriting from YeagerAITool.

  4. Register the tool in the YeagerAIToolkit.

from yeagerai import YeagerAITool

class CustomTool(YeagerAITool):
    name = "Custom Tool"
    description = "A description of the tool's purpose and functionality."

    def _run(self, query: str) -> str:
        # Tool's main functionality
        ...

    async def _arun(self, query: str) -> str:
        # Asynchronous version of the tool's main functionality
        ...

Registering Custom Tools

To register a custom tool in the YeagerAIToolkit, simply create a new instance of the toolkit and call the register_tool() method with your custom tool class as the argument:

from yeagerai import YeagerAIToolkit

toolkit = YeagerAIToolkit()
toolkit.register_tool(CustomTool)

Using Custom Tools in Agents

To use a custom tool in your agents, register it in the YeagerAIToolkit and instantiate your Agent with the toolkit as an argument:

from yeagerai import YeagerAIToolkit, Agent

toolkit = YeagerAIToolkit()
toolkit.register_tool(CustomTool)

my_agent = Agent(toolkit=toolkit)

Example: Custom Tool Creation and Usage

In this example, we will create a custom tool called WordCounter that counts the number of words in a given text. We will then register this tool in the YeagerAIToolkit and use it in an agent.

  1. Create the WordCounter custom tool:

from yeagerai import YeagerAITool

class WordCounter(YeagerAITool):
    name = "Word Counter"
    description = "Counts the number of words in the given text."

    def _run(self, text: str) -> int:
        return len(text.split())

    async def _arun(self, text: str) -> int:
        return self._run(text)
  1. Register the WordCounter tool in the YeagerAIToolkit:

    from yeagerai import YeagerAIToolkit
    
    toolkit = YeagerAIToolkit() 
    toolkit.register_tool(WordCounter)
  2. Use the `WordCounter` tool in an agent:

    from yeagerai import YeagerAIToolkit, Agent
    
    toolkit = YeagerAIToolkit()
    toolkit.register_tool(WordCounter)
    
    my_agent = Agent(toolkit=toolkit)
    
    # Use the WordCounter tool
    text = "This is an example sentence."
    word_count = my_agent.run_tool("Word Counter", text)
    print(f"The number of words in the text: {word_count}")

This example demonstrates how to create a custom tool, register it in the YeagerAIToolkit, and utilize it within an agent.

Conclusion

The Yeager AI Toolkit offers an easy way to create, register, and manage tools that can enhance the capabilities of your AI agents. By following the guidelines and examples in this documentation, you can create custom tools tailored to your specific needs and leverage them in your agents.

Last updated