Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

  • Remove unused import (BaseMessage) from base.py line 86
  • Remove unnecessary column check in execute method (line 726)
  • Refactor to pass ExecutionContext directly instead of AgentPrompterContext wrapper
  • Move conversation construction logic into _get_conversation method
  • Refactor error handling to let error handler differentiate exceptions
  • Extract validation logic into conversation class
  • Extract history table processing into dedicated method (line 829)
  • Add row IDs to error messages (lines 845-847, 853)
  • Remove AgentPrompterContext class if no longer needed
  • Simplify create_output_table method (remove with_error_column parameter)
  • Combine and simplify list comprehensions in output construction
  • Remove _append_messages wrapper in _agent.py if inline wrapping used
  • Remove AgentWidgetContext wrapper in _data_service.py
  • Clean up redundant references in _data_service.py
  • Address all code review feedback and fix code style issues
  • Validate each AI message (not just final) and simplify output table creation
  • Fix trailing whitespace
  • Remove validate_ai_message parameter - import directly instead

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits January 14, 2026 15:46
- Remove unused BaseMessage import from base.py
- Remove unnecessary column check in execute (already in configure)
- Pass ExecutionContext directly instead of AgentPrompterContext wrapper
- Move conversation construction into _get_conversation method
- Extract history table processing into dedicated method with row IDs in error messages
- Move validation logic into AgentPrompterConversation.validate_final_message
- Remove AgentPrompterContext class (no longer needed)
- Simplify create_output_table by removing with_error_column parameter
- Remove AgentWidgetContext wrapper in _data_service.py
- Simplify FrontendConversation.create_output_table to use self._tool_converter
- Remove _append_messages wrapper in _agent.py (inline wrapping)

Co-authored-by: AtR1an <[email protected]>
The error handler now has a single handle_error method that accepts any exception
and makes the differentiation itself, simplifying the calling code.

Co-authored-by: AtR1an <[email protected]>
- Move BaseMessage import to module level to avoid repeated import overhead
- Remove inline imports from frequently called methods
- Extract duplicated append_msg logic into shared _append_sanitized_message helper
- Fix inconsistent whitespace in import statements

Co-authored-by: AtR1an <[email protected]>
- Fix row index access using iloc[idx].name instead of index[idx]
- Move IterationLimitError import to top of _error_handler.py module

Co-authored-by: AtR1an <[email protected]>
- Use history_df.index[idx] to correctly get row index
- Remove extra trailing blank lines in _agent.py for consistency

Co-authored-by: AtR1an <[email protected]>
Copilot AI changed the title [WIP] Fix error handling for conversation histories Refactor agent execution to simplify context handling and reduce code duplication Jan 14, 2026
Copilot AI requested a review from AtR1an January 14, 2026 15:55
return
self._append_messages(response)

self._conversation.append_messages(response)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this wrap the response into a message?

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 append_messages method in AgentPrompterConversation already handles wrapping single messages into a list (line 892-893 in base.py):

if isinstance(messages, BaseMessage):
    messages = [messages]

So when we call self._conversation.append_messages(response) with a single BaseMessage response from invoke(), it's automatically wrapped. The code is working correctly.

ctx.set_warning(str(e))
else:
conversation.append_error(e)
conversation.validate_final_message(validate_ai_message, ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

The conversation should validate each AI message, not just the final one. Therefore validate_ai_message should be a method of the conversation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored in commit ed6e64e. The conversation now validates each AI message as it's added via the append_messages method, not just the final message. The validate_ai_message function is passed to the conversation constructor and called for every AI message added.

Comment on lines 969 to 982
desanitized_messages_and_errors = [
{
"message": tool_converter.desanitize_tool_names(moe["message"])
if moe["message"] is not None
else None,
"error": moe["error"],
}
for moe in messages_and_errors
]
messages = [
from_langchain_message(msg) if msg is not None else None
for msg in desanitized_messages
from_langchain_message(moe["message"])
if moe["message"] is not None
else None
for moe in desanitized_messages_and_errors
Copy link
Contributor

Choose a reason for hiding this comment

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

This is even more complicated and harder to read than the previous implementation that I asked you to simplify. Can't you define a helper function that returns None if the input is None and otherwise desanitizes and converts to a KNIME message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified in commit ed6e64e. Added helper function to_knime_message_or_none that returns None if input is None, otherwise desanitizes and converts to KNIME message. This eliminates the nested list comprehensions and makes the code much more readable.

@AtR1an
Copy link
Contributor

AtR1an commented Jan 14, 2026

@copilot apply requested changes

Copilot AI and others added 2 commits January 14, 2026 16:08
… table creation

- Move validation logic into append_messages to validate each AI message as it's added
- Simplify create_output_table with to_knime_message_or_none helper function
- Remove validate_final_message method (now inline in append_messages)
- Properly handle FAIL mode with ctx.set_warning for validation errors

Co-authored-by: AtR1an <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jan 14, 2026

@copilot apply requested changes

All requested changes have been applied in commits ed6e64e and f484d43:

  1. ✅ Validation now happens for each AI message (not just final) via append_messages method
  2. ✅ Simplified create_output_table with to_knime_message_or_none helper function
  3. ✅ Response wrapping handled correctly by existing append_messages logic

All files compile successfully and are ready for review.

history_table: Optional[knext.Table],
tool_converter,
data_registry,
validate_ai_message,
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no need to pass a method handle. It's always the same method. Just call it directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit f3e8f4a. The AgentPrompterConversation class now imports validate_ai_message directly from the _agent module instead of receiving it as a parameter. This simplifies the method signature since it's always the same function.

Instead of passing validate_ai_message as a parameter through _get_conversation,
the AgentPrompterConversation class now imports and calls it directly from the
_agent module. This simplifies the API since it's always the same function.

Co-authored-by: AtR1an <[email protected]>
Copilot AI requested a review from AtR1an January 14, 2026 16:22
@AtR1an AtR1an marked this pull request as ready for review January 15, 2026 09:13
@AtR1an AtR1an requested a review from a team as a code owner January 15, 2026 09:13
@AtR1an AtR1an merged commit b3273f7 into bug/AP-25110-implement-error-handling-option Jan 15, 2026
1 check failed
@AtR1an AtR1an deleted the copilot/sub-pr-5 branch January 15, 2026 09:13
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 this pull request may close these issues.

2 participants