2424
2525from app .agent .listen_chat_agent import ListenChatAgent , logger
2626from app .model .chat import AgentModelConfig , Chat
27+ from app .model .model_platform import patch_bedrock_cloud_config
2728from app .service .task import ActionCreateAgentData , Agents , get_task_lock
2829from app .utils .event_loop_utils import _schedule_async_task
2930
@@ -80,7 +81,14 @@ def agent_model(
8081 for attr in config_attrs :
8182 effective_config [attr ] = getattr (options , attr )
8283 extra_params = options .extra_params or {}
83-
84+ # Cloud mode: inject default Bedrock region and adjust URL for proxy.
85+ if (
86+ effective_config .get ("model_platform" ) == "aws-bedrock-converse"
87+ and options .is_cloud ()
88+ ):
89+ effective_config ["api_url" ], extra_params = patch_bedrock_cloud_config (
90+ effective_config ["api_url" ], extra_params
91+ )
8492 init_param_keys = {
8593 "api_version" ,
8694 "azure_ad_token" ,
@@ -90,6 +98,10 @@ def agent_model(
9098 "client" ,
9199 "async_client" ,
92100 "azure_deployment_name" ,
101+ "region_name" ,
102+ "aws_access_key_id" ,
103+ "aws_secret_access_key" ,
104+ "aws_session_token" ,
93105 }
94106
95107 init_params = {}
@@ -113,6 +125,26 @@ def agent_model(
113125 else :
114126 model_config [k ] = v
115127
128+ # Auto-inject prompt caching based on model platform
129+ try :
130+ model_platform_enum = ModelPlatformType (
131+ effective_config ["model_platform" ].lower ()
132+ )
133+ if model_platform_enum in {
134+ ModelPlatformType .ANTHROPIC ,
135+ ModelPlatformType .AWS_BEDROCK_CONVERSE ,
136+ }:
137+ model_config .setdefault ("cache_control" , "5m" )
138+ elif model_platform_enum == ModelPlatformType .OPENAI :
139+ model_config .setdefault (
140+ "prompt_cache_key" , str (options .project_id )
141+ )
142+ except (ValueError , AttributeError ):
143+ logging .error (
144+ f"Invalid model platform: { effective_config ['model_platform' ]} " ,
145+ exc_info = True ,
146+ )
147+
116148 if agent_name == Agents .task_agent :
117149 model_config ["stream" ] = True
118150 if agent_name == Agents .browser_agent :
@@ -137,10 +169,8 @@ def agent_model(
137169 model_platform_enum = None
138170
139171 if effective_config ["model_platform" ].lower () == "anthropic" :
140- if model_config .get ("cache_control" ) is None :
141- model_config ["cache_control" ] = "5m"
142172 if model_config .get ("max_tokens" ) is None :
143- model_config ["max_tokens" ] = 64000
173+ model_config ["max_tokens" ] = 128000
144174
145175 model = ModelFactory .create (
146176 model_platform = effective_config ["model_platform" ],
0 commit comments