Skip to content

inject_params

autogen.tools.dependency_injection.inject_params #

inject_params(f)

Injects parameters into a function, removing injected dependencies from its signature.

This function is used to modify a function by injecting dependencies and removing injected parameters from the function's signature.

PARAMETER DESCRIPTION
f

The function to modify with dependency injection.

TYPE: Callable[..., Any]

RETURNS DESCRIPTION
Callable[..., Any]

The modified function with injected dependencies and updated signature.

Source code in autogen/tools/dependency_injection.py
def inject_params(f: Callable[..., Any]) -> Callable[..., Any]:
    """Injects parameters into a function, removing injected dependencies from its signature.

    This function is used to modify a function by injecting dependencies and removing
    injected parameters from the function's signature.

    Args:
        f: The function to modify with dependency injection.

    Returns:
        The modified function with injected dependencies and updated signature.
    """
    # This is a workaround for Python 3.9+ where staticmethod.__func__ is accessible
    if sys.version_info >= (3, 9) and isinstance(f, staticmethod) and hasattr(f, "__func__"):
        f = _fix_staticmethod(f)

    f = _string_metadata_to_description_field(f)
    f = _set_return_annotation_to_any(f)
    f = inject(f)
    f = _remove_injected_params_from_signature(f)

    return f