Handler

Handler in Eclipse

In the Eclipse framework, a handler—also referred to as tool calling—is a component that manages specific operations within the system. While "tool calling" often denotes the invocation of a single function, a handler encompasses the logic required to organize and execute particular tasks, playing a pivotal role in the framework's functionality.

Creating Custom Handlers

To develop custom handlers, you can extend the BaseHandler class from the eclipse.handler.base module. This approach allows you to define specialized behavior tailored to your application's requirements.

Additionally, Eclipse offers pre-built handlers for various services and libraries, facilitating seamless integration and reducing development effort.

Tools

Within this context, a tool is an asynchronous method or function designed to perform a specific action within the larger system. Tools handle tasks such as fetching data from external APIs or executing computations. By marking these methods with the @tool decorator, you enable the system to recognize and invoke them as needed.

Example: Defining a Custom Handler

Below is an example of how to define a custom handler using the BaseHandler class and the @tool decorator:

from eclipse.handler.base import BaseHandler
from eclipse.handler.decorators import tool

class ExaHandler(BaseHandler):

    @tool
    async def search_contents(
        self,
        *,
        query: str,
        use_autoprompt: bool,
        num_results: int = 10,
        search_type: str | None = None
    ):
        # Implement the logic for searching contents here
        pass

In this example, the ExaHandler class inherits from BaseHandler. The search_contents method is decorated with @tool, indicating that it can be invoked by the system as a tool. This method accepts parameters such as query, use_autoprompt, num_results, and an optional search_type, allowing for flexible and dynamic operation.

By leveraging handlers and tools in Eclipse, developers can create modular, reusable components that enhance the framework's capability to manage and execute complex tasks efficiently.

Last updated