11import asyncio
22import json
3- import os
43import re
54import traceback
65import uuid
@@ -108,9 +107,9 @@ class CugaComponent(ToolCallingAgentComponent):
108107 info = (
109108 "Custom instructions or policies for the agent to adhere to during its operation.\n "
110109 "Example:\n "
111- "# Plan\n "
110+ "## Plan\n "
112111 "< planning instructions e.g. which tools and when to use>\n "
113- "# Answer\n "
112+ "## Answer\n "
114113 "< final answer instructions how to answer>"
115114 ),
116115 value = "" ,
@@ -193,6 +192,20 @@ class CugaComponent(ToolCallingAgentComponent):
193192 info = "If true, will add a tool to the agent that returns the current date." ,
194193 value = True ,
195194 ),
195+ BoolInput (
196+ name = "lite_mode" ,
197+ display_name = "Enable CugaLite" ,
198+ info = "Enable CugaLite for simple API tasks (faster execution)." ,
199+ value = True ,
200+ advanced = False ,
201+ ),
202+ IntInput (
203+ name = "lite_mode_tool_threshold" ,
204+ display_name = "CugaLite Tool Threshold" ,
205+ info = "Route to CugaLite if app has fewer than this many tools." ,
206+ value = 25 ,
207+ advanced = False ,
208+ ),
196209 BoolInput (
197210 name = "browser_enabled" ,
198211 display_name = "Enable Browser" ,
@@ -254,33 +267,27 @@ async def call_agent(
254267 }
255268 logger .debug (f"LLM MODEL TYPE: { type (llm )} " )
256269 if current_input :
257- try :
258- from cuga .config import settings as cuga_settings
270+ # Import settings first
271+ from cuga .config import settings
259272
260- logger .info ("Updating cuga settings programmatically" )
261- cuga_settings .set ("advanced_features.registry" , False ) # noqa: FBT003
273+ # Use Dynaconf's set() method to update settings dynamically
274+ # This properly updates the settings object without corruption
275+ logger .debug ("Updating CUGA settings via Dynaconf set() method" )
262276
263- if self .browser_enabled :
264- logger .info ("browser_enabled is true, setting mode to hybrid" )
265- cuga_settings .set ("advanced_features.mode" , "hybrid" )
266- cuga_settings .set ("advanced_features.use_vision" , False ) # noqa: FBT003
267- else :
268- logger .info ("browser_enabled is false, setting mode to api" )
269- cuga_settings .set ("advanced_features.mode" , "api" )
270-
271- logger .info (f"Cuga settings updated - MODE: { cuga_settings .get ('advanced_features.mode' )} " )
272- except (ImportError , AttributeError ) as e :
273- logger .warning (f"Could not update cuga settings: { e } " )
274- os .environ ["DYNACONF_ADVANCED_FEATURES__REGISTRY" ] = "false"
275- if self .browser_enabled :
276- logger .info ("browser_enabled is true, setting env to hybrid" )
277- os .environ ["DYNACONF_ADVANCED_FEATURES__MODE" ] = "hybrid"
278- os .environ ["DYNACONF_ADVANCED_FEATURES__USE_VISION" ] = "false"
279- else :
280- logger .info ("browser_enabled is false, setting env to api" )
281- os .environ ["DYNACONF_ADVANCED_FEATURES__MODE" ] = "api"
277+ settings .advanced_features .registry = False
278+ settings .advanced_features .lite_mode = self .lite_mode
279+ settings .advanced_features .lite_mode_tool_threshold = self .lite_mode_tool_threshold
280+
281+ if self .browser_enabled :
282+ logger .info ("browser_enabled is true, setting mode to hybrid" )
283+ settings .advanced_features .mode = "hybrid"
284+ settings .advanced_features .use_vision = False
285+ else :
286+ logger .info ("browser_enabled is false, setting mode to api" )
287+ settings .advanced_features .mode = "api"
282288
283289 from cuga .backend .activity_tracker .tracker import ActivityTracker
290+ from cuga .backend .cuga_graph .nodes .api .variables_manager .manager import VariablesManager
284291 from cuga .backend .cuga_graph .utils .agent_loop import StreamEvent
285292 from cuga .backend .cuga_graph .utils .controller import (
286293 AgentRunner as CugaAgent ,
@@ -291,6 +298,16 @@ async def call_agent(
291298 from cuga .backend .llm .models import LLMManager
292299 from cuga .configurations .instructions_manager import InstructionsManager
293300
301+ var_manager = VariablesManager ()
302+
303+ # Reset var_manager if this is the first message in history
304+ logger .info (f"[CUGA] Checking history_messages: count={ len (history_messages ) if history_messages else 0 } " )
305+ if not history_messages or len (history_messages ) == 0 :
306+ logger .info ("[CUGA] First message in history detected, resetting var_manager" )
307+ var_manager .reset ()
308+ else :
309+ logger .info (f"[CUGA] Continuing conversation with { len (history_messages )} previous messages" )
310+
294311 llm_manager = LLMManager ()
295312 llm_manager .set_llm (llm )
296313 instructions_manager = InstructionsManager ()
@@ -760,11 +777,13 @@ async def get_memory_data(self):
760777 list: List of Message objects representing the chat history
761778 """
762779 logger .info ("[CUGA] Retrieving chat history messages." )
780+ logger .info (f"[CUGA] Session ID: { self .graph .session_id } " )
763781 messages = (
764782 await MemoryComponent (** self .get_base_args ())
765783 .set (session_id = self .graph .session_id , order = "Ascending" , n_messages = self .n_messages )
766784 .retrieve_messages ()
767785 )
786+ logger .info (f"[CUGA] Retrieved { len (messages )} messages from memory" )
768787 return [
769788 message for message in messages if getattr (message , "id" , None ) != getattr (self .input_value , "id" , None )
770789 ]
0 commit comments