-
Notifications
You must be signed in to change notification settings - Fork 216
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
Bug: Significant Cold Start Initialization Delay in Orchestration Framework #126
Comments
Hi @karanakatle ,
Let us know if you need further assistance. |
@karanakatle any updates on this? |
@karanakatle , I'm about to close this since I didn't hear anything from you. Let me know if you need further assistance. |
Hello @brnaba-aws
Is there any chance or way to save the time consuming in 1st and 3rd point Code is attached for reference. Cloudwatch logs also attached for analysis |
For:
|
@karanakatle , one more thing. I don't think you are using the latest python version since I don't see this try/except with Anthropic: new import method One thing that I just noticed is the fact that each Lex bot will instantiate a boto3.client('lexv2-runtime', region_name=self.region). We haven't provided a way to reuse a client passed as a parameter. |
Sure @brnaba-aws , thnx for the help. |
could you please try to use this LexBotAgent? example: lex_client = boto3.client('lexv2-runtime', region_name=os.getenv('AWS_REGION','us-east-1'))
my_agent = LexBotAgent(LexBotAgentOptions(client=lex_client, bot_id = '', bot_alias_id='', locale_id=''))
my_agent_2 = LexBotAgent(LexBotAgentOptions(client=lex_client, bot_id = '', bot_alias_id='', locale_id='')) from typing import List, Dict, Optional
from dataclasses import dataclass
import boto3
from botocore.exceptions import BotoCoreError, ClientError
from multi_agent_orchestrator.agents import Agent, AgentOptions
from multi_agent_orchestrator.types import ConversationMessage, ParticipantRole
from multi_agent_orchestrator.utils import Logger
import os
from typing import Any
@dataclass
class LexBotAgentOptions(AgentOptions):
bot_id: str = None
bot_alias_id: str = None
locale_id: str = None
client: Optional[Any] = None
class LexBotAgent(Agent):
def __init__(self, options: LexBotAgentOptions):
super().__init__(options)
if (options.region is None):
self.region = os.environ.get("AWS_REGION", 'us-east-1')
else:
self.region = options.region
if options.client:
self.lex_client = options.client
else:
self.lex_client = boto3.client('lexv2-runtime', region_name=self.region)
self.bot_id = options.bot_id
self.bot_alias_id = options.bot_alias_id
self.locale_id = options.locale_id
if not all([self.bot_id, self.bot_alias_id, self.locale_id]):
raise ValueError("bot_id, bot_alias_id, and locale_id are required for LexBotAgent")
async def process_request(self, input_text: str, user_id: str, session_id: str,
chat_history: List[ConversationMessage],
additional_params: Optional[Dict[str, str]] = None) -> ConversationMessage:
try:
params = {
'botId': self.bot_id,
'botAliasId': self.bot_alias_id,
'localeId': self.locale_id,
'sessionId': session_id,
'text': input_text,
'sessionState': {} # You might want to maintain session state if needed
}
response = self.lex_client.recognize_text(**params)
concatenated_content = ' '.join(
message.get('content', '') for message in response.get('messages', [])
if message.get('content')
)
return ConversationMessage(
role=ParticipantRole.ASSISTANT.value,
content=[{"text": concatenated_content or "No response from Lex bot."}]
)
except (BotoCoreError, ClientError) as error:
Logger.error(f"Error processing request: {str(error)}")
raise error |
Expected Behaviour
The orchestration framework should initialize with minimal delay during cold starts, ensuring consistent performance across all Lambda invocations, including the first execution.
Current Behaviour
When a new Lambda instance is created, the orchestration framework incurs a significant initialization delay of 5-7 seconds. This delay occurs before any classification or other processing steps, resulting in a total latency of 7-9 seconds for the first invocation.
However, subsequent invocations on the same Lambda instance execute within 1-2 seconds, indicating the issue is specific to cold start initialization. This behavior impacts the overall performance and user experience during the first execution.
Note: Testing with provisioned concurrency (set to 5) does keep 5 instances of the Lambda function warm; however, the issue persists when execution shifts to a new Lambda instance outside of these provisioned instances. The orchestration framework initialization itself takes 5-7 seconds, which adversely impacts performance and user experience during the first execution.
Code snippet
Possible Solution
No response
Steps to Reproduce
The text was updated successfully, but these errors were encountered: