HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/mysqlsh/lib/python3.8/site-packages/oci/addons/adk/tool/tool.py
# coding: utf-8
# Copyright (c) 2016, 2025, Oracle and/or its affiliates.  All rights reserved.
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.

from functools import wraps

from oci.addons.adk.util import get_callable_description


def tool(func=None, *, name=None, description=None):
    """
    Decorator to mark a function as a tool for the agent.

    Args:
        func: The function to decorate
        name: Optional name for the tool (defaults to function name)
        description: Optional description (defaults to function docstring)
    """

    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            return func(*args, **kwargs)

        # wrap the function with tool metadata
        wrapper._is_tool = True
        wrapper._tool_name = name or func.__name__
        wrapper._tool_description = (
            description or get_callable_description(callable_func=func) or ""
        )

        return wrapper

    # Handle both @tool and @tool(name="name", description="desc") syntax
    if func is None:
        return decorator
    return decorator(func)