Skip to content

Rationalise Thinking Prompt Behavior #1790

Description

@igordayen

OVERVIEW

Let's consider a test

void createObjectWithThinkingResult() {
        logger.info("Running thinking positive test");

        PromptRunner runner = ai.withDefaultLlm(); // <1>
        assertTrue(runner.supportsThinking(), "Expected the prompt runner to support thinking"); // <2>

        ThinkingResponse<TravelPlan> response = runner
            .withSystemPrompt( // <3>
                """
                     You are a travel assistant.
                     You MUST:
                   1. Provide reasoning inside <decision_reasoning>...</decision_reasoning>
                   2. Keep reasoning concise (3-5 bullet points)
                   3. Explain why the itinerary is optimal.

                   <decision_reasoning>
                   Explain:
                   - time constraint
                   - risk of being late
                   - trade-offs
                   </decision_reasoning>
                   """)
            .thinking() // <4>
            .createObject("""
                Create a short travel plan for a three-day trip from London to Paris.
                Include major landmarks.
                Make the most optimal and balanced itinerary.
                """, TravelPlan.class); // <5>

        logger.info("Positive thinking response: {}", response);
        logger.info("Positive thinking content: {}", response.getThinkingContent());

        assertNotNull(response);
        assertTrue(response.hasResult());
        assertNotNull(response.getResult());
        assertTrue(response.hasThinking()); // <5>
    }

Worth noting:

  • The prompt specifically asks to generate reasoning with a proper tag
  • thinkg() - just indicates expected result ThinkingResponse
  • framework will not strip non-JSON within LLM response, unlike non-thinking counterpart, but rather parse it as reasoning

Would like to discuss (and maybe convert issue into Discussion) the following consequences.
What if the user did not include any request for reasoning in the prompt?
There is no enforcement to generate reasoning.

Possibilities:

  • syntax```thinkg("some-tag") ````, and auto-add some standardized system message "You MUST generate reasoning with <some-tag"
  • create standard ThinkingSystemMessageTransformer - will append to the system message the same
    But what IF a user-created prompt with reasoning includes tag A, but some-tag=tag B?
    Trust that the user is well aware and will use only one of the mechanisms: regular prompting OR auto-generated system prompt?

Note - this is different from another issue on Thinking - to have a uniform solution across non-streaming and streaming and refine native-thinking-support: #1716

@jimador, @azanux - could you please review?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions