Skip to content

Conversation

@steven10a
Copy link
Collaborator

Update Agents to properly parse the conversation history for the user's last message

  • Failing to do so causes an error when the user is passing in conversation history and using the moderation endpoint (moderation endpoint expects a string)
  • Updated tests

Copilot AI review requested due to automatic review settings November 10, 2025 21:36
Copilot finished reviewing on behalf of steven10a November 10, 2025 21:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the GuardrailAgent to properly parse conversation history and extract the user's last message as a string, fixing an error when using the moderation endpoint (which expects string input rather than complex message structures).

Key Changes:

  • Replaces ContentUtils.extractTextFromMessage with new custom text extraction functions that handle nested conversation structures
  • Adds three new helper functions to recursively extract text from various input formats (content parts, message entries, and agent inputs)
  • Includes a new test case validating that conversation history is correctly parsed and the latest user message is extracted

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/agents.ts Removes unused imports and adds new text extraction functions (extractTextFromContentParts, extractTextFromMessageEntry, extractTextFromAgentInput) to handle conversation history parsing; refactors resolveInputText to use the new extraction logic
src/tests/unit/agents.test.ts Fixes indentation in existing test and adds new test case to verify conversation history parsing with multi-part user messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steven10a steven10a requested a review from Copilot November 10, 2025 22:10
Copilot finished reviewing on behalf of steven10a November 10, 2025 22:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steven10a steven10a requested a review from Copilot November 10, 2025 22:20
Copilot finished reviewing on behalf of steven10a November 10, 2025 22:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steven10a steven10a requested a review from Copilot November 10, 2025 22:36
Copilot finished reviewing on behalf of steven10a November 10, 2025 22:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steven10a steven10a requested a review from Copilot November 10, 2025 22:45
Copilot finished reviewing on behalf of steven10a November 10, 2025 22:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steven10a steven10a requested a review from Copilot November 10, 2025 22:58
Copilot finished reviewing on behalf of steven10a November 10, 2025 23:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return record.text.trim();
}
}

Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

[nitpick] The inline comment explains the parameter but doesn't clarify when this fallback path is reached. Consider adding a brief comment above this line explaining that this is a last-resort extraction attempt for object structures that don't match standard message patterns.

Suggested change
// Last-resort extraction: if entry does not match standard message patterns,
// attempt to extract text from any value type.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[nit]

@gabor-openai gabor-openai self-requested a review November 12, 2025 10:51
Copy link
Collaborator

@gabor-openai gabor-openai left a comment

Choose a reason for hiding this comment

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

TY

@gabor-openai gabor-openai merged commit 44ac88d into main Nov 12, 2025
7 checks passed
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.

3 participants