generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 184
Introduce hook and context management to OpenSearch Agents #4388
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
Open
mingshl
wants to merge
10
commits into
opensearch-project:main
Choose a base branch
from
mingshl:feature/context_manager_hooks_inline_create
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Introduce hook and context management to OpenSearch Agents #4388
mingshl
wants to merge
10
commits into
opensearch-project:main
from
mingshl:feature/context_manager_hooks_inline_create
+9,760
−1,549
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Xun Zhang <[email protected]>
…project#4345) * initiate context management api with hook implementation Signed-off-by: Mingshi Liu <[email protected]> * apply spotless Signed-off-by: Mingshi Liu <[email protected]> --------- Signed-off-by: Mingshi Liu <[email protected]>
* add pre_llm hook to per agent Signed-off-by: Mingshi Liu <[email protected]> change context management passing from query parameters to payload Signed-off-by: Mingshi Liu <[email protected]> pass hook registery into PER Signed-off-by: Mingshi Liu <[email protected]> apply spotless Signed-off-by: Mingshi Liu <[email protected]> initiate context management api with hook implementation Signed-off-by: Mingshi Liu <[email protected]> * add comment Signed-off-by: Mingshi Liu <[email protected]> * format Signed-off-by: Mingshi Liu <[email protected]> * add validation Signed-off-by: Mingshi Liu <[email protected]> --------- Signed-off-by: Mingshi Liu <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
Signed-off-by: Mingshi Liu <[email protected]>
caa6d57 to
4eaeb94
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Add Complete Context Management Framework with Memory-Integrated Hook Events to ML Agents
This PR introduces a comprehensive context management system for ML agents, featuring memory-integrated hook
events, complete hook registry with fault-tolerant execution, enhanced context integration, and intelligent
resource management for enterprise-grade deployments.
Major Features:
Complete Hook Registry System
• Fault-Tolerant Event Emission: emitEvent() with exception isolation and comprehensive logging
• Thread-Safe Operations: ConcurrentHashMap ensuring concurrent callback registration and execution
• Callback Management: Type-safe callback registration with monitoring capabilities
• Production-Grade Error Handling: Individual callback failures don't affect system operation
Comprehensive Hook Event Architecture
• HookEvent Base Class: Abstract base with invocation state for all lifecycle events
• PreLLMEvent: pre llm event with context integration and retrieved re-act interactions, including tool used result/ completed steps
• EnhancedPostToolEvent: Tool event with context integration
• Event Hierarchy: Well-designed inheritance from HookEvent to specialized events
Complete CRUD REST API Implementation
• Create Operations: MLCreateContextManagementTemplateAction, MLCreateContextManagementTemplateRequest,
MLCreateContextManagementTemplateResponse
• Read Operations: MLGetContextManagementTemplateAction, MLGetContextManagementTemplateRequest,
MLGetContextManagementTemplateResponse
• Delete Operations: MLDeleteContextManagementTemplateAction, MLDeleteContextManagementTemplateRequest,
MLDeleteContextManagementTemplateResponse
• Full CRUD Lifecycle: Complete template management with create, read, and delete operations
Context Management Integration
• ML Agent Integration: contextManagementName and contextManagement fields with validation
• Template System: ContextManagementTemplate with hooks, validation, and serialization
• Hook Provider Integration: ContextManagerHookProvider registers callbacks for all event types
Rich Context State Management
• ContextManagerContext: Comprehensive context with prompts, history, tools, interactions, and parameters
• Utility Methods: getEstimatedTokenCount(), getMessageCount(), addParameter(), addToolInteraction()
• Memory Integration: Context managers can access both current context and retrieved memory
• Dynamic Modification: Runtime context updates with memory and invocation state tracking
Event-Driven Execution Pipeline
• Tool Event Processing: handlePostTool() processes enhanced tool events with context
• Pre-LLM Processing: handlePreLLM() processes context before LLM execution
• Memory Event Processing: handlePostMemory() processes memory events with context and history
• Automatic Execution: All events processed automatically through hook registry
Complete Activation Rules System
• TokensExceedRule: Context-aware activation using comprehensive token estimation
• MessageCountExceedRule: Conversation length management with memory integration
• CompositeActivationRule: Complex conditions considering memory and context state
Token Counting Architecture
• TokenCounter Interface: Standardized interface with multiple truncation strategies
• Context Integration: Token counters integrated with activation rules and memory state
• Pluggable Design: Interface supports model-specific implementations
Pluggable Context Manager Architecture
• ContextManagerConfig: Configuration with type, activation, and manager settings
• Template Management: Complete template system with memory-integrated hooks
• Registry Integration: Managers registered for memory, tool, and LLM events
Technical Highlights:
• Comprehensive Event Model: Complete lifecycle coverage with memory, tool, and LLM events
• Fault-Tolerant Processing: Exception isolation ensures system stability across all event types
• Rich Context Access: Context managers have access to full context and memory
Architecture Benefits:
• Complete Lifecycle Coverage: Events cover all major phases of ML agent execution
• Integrated Memory Management: Memory retrieval and context management work together seamlessly
• Enterprise Reliability: Fault-tolerant design with comprehensive error handling
Use Cases:
• Comprehensive Resource Management: Manage tokens across current context and memory history
Impact:
• Comprehensive Agent Lifecycle: Full coverage of memory, tool, and LLM execution phases
• Advanced AI Orchestration: Sophisticated context management with memory integration
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.