Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap agent outputs in a literalmap #3143

Merged
merged 3 commits into from
Feb 19, 2025

Conversation

samhita-alla
Copy link
Contributor

@samhita-alla samhita-alla commented Feb 19, 2025

Tracking issue

Why are the changes needed?

This is necessary because although the result is already a literal, it is being converted to a literal again. Since literal isn't a valid Python type, it ends up being pickled. This issue surfaced in Flytekit 1.15.0.

What changes were proposed in this pull request?

Wrapping agent outputs in a LiteralMap so they don't get converted to literals again.

How was this patch tested?

Tested the OpenAI plugin with the updated code.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Summary by Bito

Fixed a bug in agent output handling where results were being converted to literals multiple times, affecting Python type validation in Flytekit 1.15.0. Implemented proper LiteralMap wrapping for agent outputs in AWS SageMaker and OpenAI plugins to prevent double literal conversion. Modified AWS SageMaker plugin test cases to enhance output type validation and added conditional checks for LiteralMap instances with improved mock return value handling.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 1

@flyte-bot
Copy link
Contributor

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - The AI Code Review Agent skipped reviewing this change because it is configured to exclude certain pull requests based on the source/target branch or the pull request status. You can change the settings here, or contact the agent instance creator at [email protected].

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.99%. Comparing base (66d4aed) to head (c9217c8).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3143      +/-   ##
==========================================
+ Coverage   76.85%   76.99%   +0.13%     
==========================================
  Files         206      213       +7     
  Lines       21851    22348     +497     
  Branches     2837     2837              
==========================================
+ Hits        16794    17207     +413     
- Misses       4269     4354      +85     
+ Partials      788      787       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Samhita Alla <[email protected]>
pingsutw
pingsutw previously approved these changes Feb 19, 2025
@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 19, 2025

Code Review Agent Run #813c1a

Actionable Suggestions - 1
  • plugins/flytekit-openai/tests/openai_batch/test_agent.py - 1
    • Consider adding more specific output assertions · Line 159-159
Review Details
  • Files reviewed - 4 · Commit Range: c9217c8..b466614
    • plugins/flytekit-aws-sagemaker/flytekitplugins/awssagemaker_inference/boto3_agent.py
    • plugins/flytekit-aws-sagemaker/tests/test_boto3_agent.py
    • plugins/flytekit-openai/flytekitplugins/openai/batch/agent.py
    • plugins/flytekit-openai/tests/openai_batch/test_agent.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Signed-off-by: Samhita Alla <[email protected]>
@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 19, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Bug Fix - Fix Agent Output Literal Conversion

boto3_agent.py - Wrapped outputs in LiteralMap to prevent double literal conversion

agent.py - Updated output format to use LiteralMap wrapper

Testing - Enhanced Test Coverage for LiteralMap Implementation

test_boto3_agent.py - Added LiteralMap type validation in agent tests

test_agent.py - Cleaned up imports and added LiteralMap assertion test

@@ -157,6 +156,7 @@ async def test_openai_batch_agent(mock_retrieve, mock_create, mock_context):
mock_retrieve.return_value = batch_retrieve_result
resource = await agent.get(metadata)
assert resource.phase == TaskExecution.SUCCEEDED
assert isinstance(resource.outputs, literals.LiteralMap)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding more specific output assertions

Consider adding more specific assertions to validate the structure and content of the LiteralMap outputs. This could help catch potential issues with the output format early.

Code suggestion
Check the AI-generated fix before applying
Suggested change
assert isinstance(resource.outputs, literals.LiteralMap)
assert isinstance(resource.outputs, literals.LiteralMap)
assert 'result' in resource.outputs.literals
assert isinstance(resource.outputs.literals['result'].scalar.primitive.string_value, str)

Code Review Run #813c1a


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@flyte-bot
Copy link
Contributor

flyte-bot commented Feb 19, 2025

Code Review Agent Run #0f8cc0

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: b466614..d2af43f
    • plugins/flytekit-aws-sagemaker/tests/test_boto3_agent.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@eapolinario eapolinario enabled auto-merge (squash) February 19, 2025 19:12
@eapolinario eapolinario merged commit 806ff20 into master Feb 19, 2025
34 of 36 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.

5 participants