Introduce V2 Chat Agent#4732
Conversation
PR Reviewer Guide 🔍(Review updated until commit 5307e5a)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 5307e5a Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 0953e13
Suggestions up to commit c6211c0
Suggestions up to commit 17cb259
|
| Persistent review updated to latest commit c44a58e |
c44a58e to fefa92a Compare | Persistent review updated to latest commit fefa92a |
| Persistent review updated to latest commit 990f73d |
| Persistent review updated to latest commit 11334dd |
| Persistent review updated to latest commit 897a4ba |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@ ## main #4732 +/- ## ============================================ - Coverage 77.27% 76.97% -0.31% - Complexity 11621 11704 +83 ============================================ Files 948 951 +3 Lines 52168 52725 +557 Branches 6329 6422 +93 ============================================ + Hits 40315 40586 +271 - Misses 9175 9432 +257 - Partials 2678 2707 +29
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| Persistent review updated to latest commit 8cb1586 |
| Persistent review updated to latest commit 17cb259 |
1 similar comment
| Persistent review updated to latest commit 17cb259 |
| Persistent review updated to latest commit c6211c0 |
rithin-pullela-aws left a comment
There was a problem hiding this comment.
Thanks for the PR Pavan, this is a huge improvement to Agent framework.
Added small nits, since they are not huge concerns, approving the PR LGTM
| Map<String, ?> candidateMap = (Map<String, ?>) candidatesList.get(0); | ||
| Object contentObj = candidateMap.get("content"); | ||
| if (contentObj != null) { | ||
| return org.opensearch.ml.common.utils.StringUtils.toJson(contentObj); |
There was a problem hiding this comment.
Can we instead import org.opensearch.ml.common.utils.
| // Create mutable list for ReAct iterations (will append tool results) | ||
| List<Message> messages = new ArrayList<>(conversationHistory); | ||
| AtomicInteger iteration = new AtomicInteger(0); | ||
| TokenUsage[] accumulatedTokenUsage = new TokenUsage[1]; |
There was a problem hiding this comment.
nit, can be enhanced later: Looks like we are using this to accumulate tokens. Can we use AgentTokenTracker which abstracts away the token tracking and also provides granular data about token consumption?
| if (agentType.isV2() && inputMessages != null && memory != null) { | ||
| executeV2Agent(inputDataSet, tenantId, mlTask, isAsync, mlAgent, listener, memory, channel, hookRegistry, inputMessages); | ||
| return; | ||
| } |
There was a problem hiding this comment.
This skips the MCP flag check, can we move this part below like 930?
There was a problem hiding this comment.
will submit a PR most this
| Persistent review updated to latest commit 0953e13 |
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
…ng & context management, remove dead code Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
Signed-off-by: Pavan Yekbote <pybot@amazon.com>
| Persistent review updated to latest commit 5307e5a |

Description
This PR introduces a V2 Chat Agent - a major enhancement to the OpenSearch ML agent system that provides a unified interface, multi-modal support, and simplified agent registration.
Overview
Agent V2 addresses key limitations in the current agent framework by introducing a clean, message-centric architecture that:
Problem Statement
The current agent framework has accumulated technical debt through evolution:
questionparameterconversation_indexmemory loses multi-modal content (images/videos discarded)Solution: Agent V2 Framework
Key Feature: Unified Agent Interface
Before (V1) - Multi-step manual setup:
After (V2) - Single-step with auto-generation:
Multi-Modal Support
V2 agents support three input types:
1. TEXT Input - Simple string
{ "parameters": {"session_id": "session_001"}, "input": "What is machine learning?" }2. CONTENT_BLOCKS Input - Multi-modal array
{ "input": [ {"type": "text", "text": "What's in this image?"}, {"type": "image", "source": {"type": "base64", "format": "png", "data": "..."}} ] }3. MESSAGES Input - Full conversation array
{ "input": [ {"role": "user", "content": [{"text": "Hi"}]}, {"role": "assistant", "content": [{"text": "Hello!"}]}, {"role": "user", "content": [{"text": "Tell me about AI"}]} ] }Agentic Memory - Structured Storage
V2 uses agentic_memory which stores complete message objects including multi-modal content in
structured_data_blobusing Strands-compatible format:{ "structured_data_blob": { "message": { "role": "user", "content": [ {"text": "What's in this image?"}, {"image": {"format": "png", "source": {...}}} ] } }, "metadata": {"role": "user", "format": "strands", "type": "message"} }Key Benefits:
session_idmemory_idStandardized Output Format
V2 returns responses consistent with modern LLM APIs:
{ "stop_reason": "end_turn", "message": { "role": "assistant", "content": [{"text": "The response..."}] }, "memory_id": "abc123", "metrics": { "total_usage": { "inputTokens": 1234, "outputTokens": 567, "totalTokens": 1801 } } }Note
textinput.agentic_memoryLimitations
These limitations will be addressed in future PRs.
Testing
Created a comprehensive agent test suite to validate backward compatibility and functionality: https://github.com/pyek-bot/agent-v2-test-suite
Technical Architecture
Message-Centric Design
V2 eliminates the
questionparameter limitation and works exclusively with Message objects:New Agent Types
AbstractV2AgentRunner - Code Reuse Foundation
New abstract base class provides common V2 functionality:
AgentV2Output)Benefits:
MLChatAgentRunnerV2 - Clean Implementation
Extends
AbstractV2AgentRunnerwith chat-specific logic:What Happens During Registration
V2 Registration Flow
type: conversational_v2modelfield exists andmemory.typeis agentic_memorymodel.model_providerwith provider-specific formatAuto-Generated Resources
For
model_provider: "bedrock/converse", system creates connector with:model.credentialClear Validation
V2 prevents invalid configurations with helpful error messages:
Optional Migration Path
To use V2 features:
conversational→conversational_v2modelblockconversation_index→agentic_memoryNo forced migration - V1 agents continue indefinitely.
Summary
This PR delivers a complete Agent V2 Framework that:
This establishes a solid, maintainable foundation for future V2 agent types while keeping the existing V1 system fully operational.
Related Issues
Resolves #4552 - RFC: Unified Agent Interface with Multi-Modal Support
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.