Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FunctionTool does not use the proper function name #5138

Closed
Pierrolo opened this issue Jan 22, 2025 · 2 comments · Fixed by #5165
Closed

FunctionTool does not use the proper function name #5138

Pierrolo opened this issue Jan 22, 2025 · 2 comments · Fixed by #5165
Milestone

Comments

@Pierrolo
Copy link
Contributor

Pierrolo commented Jan 22, 2025

In FunctionTool init, when calling the function args_base_model_from_signature is does not return the name of the function, but the name of the last input. See below the current implementation of this function (from file python/packages/autogen-core/src/autogen_core/_function_utils.py) :

def args_base_model_from_signature(name: str, sig: inspect.Signature) -> Type[BaseModel]:
    fields: Dict[str, tuple[Type[Any], Any]] = {}
    for name, param in sig.parameters.items():
        # This is handled externally
        if name == "cancellation_token":
            continue

        if param.annotation is inspect.Parameter.empty:
            raise ValueError("No annotation")

        type = normalize_annotated_type(param.annotation)
        description = type2description(name, param.annotation)
        default_value = param.default if param.default is not inspect.Parameter.empty else PydanticUndefined

        fields[name] = (type, Field(default=default_value, description=description))

    return cast(BaseModel, create_model(name, **fields))  # type: ignore

In it, the param name is overwritten in the for loot. A correct implementation could look like :

def args_base_model_from_signature(name: str, sig: inspect.Signature) -> Type[BaseModel]:
    fields: Dict[str, tuple[Type[Any], Any]] = {}
    for param_name, param in sig.parameters.items():
        # This is handled externally
        if param_name == "cancellation_token":
            continue

        if param.annotation is inspect.Parameter.empty:
            raise ValueError("No annotation")

        type = normalize_annotated_type(param.annotation)
        description = type2description(name, param.annotation)
        default_value = param.default if param.default is not inspect.Parameter.empty else PydanticUndefined

        fields[param_name] = (type, Field(default=default_value, description=description))

    return cast(BaseModel, create_model(name, **fields))  # type: ignore
@ekzhu ekzhu added this to the 0.4.4 milestone Jan 23, 2025
@ekzhu
Copy link
Collaborator

ekzhu commented Jan 23, 2025

Looks like a bug. Would you like to contribute a PR for the fix?

@Pierrolo
Copy link
Contributor Author

Pierrolo commented Jan 23, 2025

sure i'll get to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants