Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Reason content

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Nov 18, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Nov 18, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

if os.path.exists(code_path):
os.remove(code_path)
return {
'step_type': 'chat_step',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided Python function execute_block has a minor issue with string concatenation. Instead of using an OR operator (or) which could lead to unexpected results when handling empty strings, it should be combined more straightforwardly. Here's the revised version:

def execute_block(self, message_list: List[BaseMessage],
                     chat_result):
    # Existing logic...
    
    if 'reasoning_content' in chat_result.response_metadata:
        reasoning_content = chat_result.response_metadata.get('reasoning_content', '')
    else:
        reasoning_content = reasoning_result.get('reasoning_content') + reasoning_result_end.get(
            'reasoning_content')
        
    # Revised line
    output_string = ("{}{}{}".format(*[
        item or ""
        for item in [
            reasoning_result.get('content'),
            reasoning_result_end.get('content'),
            " " if any(item) else "",  # Add space only if either part is not empty
            reasoning_content
        ]
]))
    
    post_response_handler.handler(chat_id, chat_record_id, paragraph_list, problem_text,
                                 content, manage, self, padding_problem_text,
                                 reasoning_content=output_string)

In this revision, I used tuple unpacking within f-string formatting. This method ensures that all values are evaluated and concatenated correctly without unnecessary checks for emptiness. The spaces are added conditionally based on whether either the main content or reasoning content is present.

reasoning_content = (reasoning_result.get('reasoning_content') or '') + (reasoning_result_end.get('reasoning_content') or '')
_write_context(node_variable, workflow_variable, node, workflow, content, reasoning_content)


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided Python function is mostly correct but contains two minor issues:

  1. The line content = reasoning_result.get('content') + reasoning_result_end.get('content') can be simplified using logical OR (or) to avoid multiple conditions.

  2. Similarly, the line where both reasoning_content and its fallbacks are concatenated should also use or.

Here's an optimized version of the code with these corrections:

def write_context(node_variable: Dict, workflow_variable: Dict, node: INode,
                 workflow: WorkflowData, response):
    # Sum reasoning content from responses or their empty strings
    reasoning_content = (response.reasoning_content or '') \
                      + (response.response_metadata.get('reasoning_content', '') or '')

    content = reasoninig_result.get('content') + reasoning_resultEnd.get('content')

    _write_context(node_variable, workflow_variable, node, workflow, content, reasoning_content)

These changes ensure that if either response.reasoning_content or the one specified in metadata is None, it will default to an empty string before concatenation. This avoids potential runtime errors when attempting non-string values.

@zhanweizhang7 zhanweizhang7 merged commit e939c6e into v2 Nov 18, 2025
3 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_reason_context branch November 18, 2025 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants