Skip to content

Toolcall loop when using tool name in withToolChoice #822

@apm-tobias-duesterhus

Description

@apm-tobias-duesterhus

Hey There,

I am using Version 0.99.11 and probably found a bug or did something totally wrong.

I create the following test-script to verify the effect:

$weatherTool = Tool::as('weather')
    ->for('Get current weather conditions')
    ->withStringParameter('city', 'The city to get weather for')
    ->using(function (string $city): string {
        // Your weather API logic here
        Log::debug('weather tool called for city: ' . $city);
        return "The weather in {$city} is sunny and 72°F.";
    });

$pendingRequest = \Prism\Prism\Facades\Prism::text()->using(
    provider: Provider::OpenAI,
    model: ...,
    providerConfig: ...
);

$result = $pendingRequest
    ->withMessages([new UserMessage('What is the weather like in New York today?')])
    ->withTools([$weatherTool])
    ->withToolChoice('weather')
    ->withMaxSteps(5)
    ->asText();

dump($result->text);

In this case, the log from the weather tool is printed five times, the result test from the llm is empty. In case I comment out the tool choice, I get the correct answer. This seems to be an issue at least for OpenAI and Gemini.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions