11# -
22# #%L
3- # Extended LLM Agent
3+ # SmartFix LLM Agent
44# %%
55# Copyright (C) 2025 Contrast Security, Inc.
66# %%
3131from google .adk .agents import LlmAgent
3232from src .utils import debug_log
3333
34- # Import ExtendedLiteLlm at module level so it's available for model_rebuild()
35- ExtendedLiteLlm = None
34+ # Import SmartFixLiteLlm at module level so it's available for model_rebuild()
35+ SmartFixLiteLlm = None
3636try :
37- from .extended_litellm import ExtendedLiteLlm
37+ from .smartfix_litellm import SmartFixLiteLlm
3838except ImportError :
3939 pass
4040
4141
42- class ExtendedLlmAgent (LlmAgent ):
43- """Extended LLM Agent that preserves ExtendedLiteLlm statistics across calls.
42+ class SmartFixLlmAgent (LlmAgent ):
43+ """SmartFix LLM Agent that preserves SmartFixLiteLlm statistics across calls.
4444
45- This class solves the issue where ExtendedLiteLlm accumulated statistics
45+ This class solves the issue where SmartFixLiteLlm accumulated statistics
4646 aren't preserved when using the model within a Google ADK Agent. It ensures
47- that the same ExtendedLiteLlm instance is used for all LLM calls and provides
47+ that the same SmartFixLiteLlm instance is used for all LLM calls and provides
4848 convenient methods to access accumulated statistics.
4949
5050 Example usage:
5151 ```python
52- from src.extensions.extended_litellm import ExtendedLiteLlm
53- from src.extensions.extended_llm_agent import ExtendedLlmAgent
52+ from src.extensions.smartfix_litellm import SmartFixLiteLlm
53+ from src.extensions.smartfix_llm_agent import SmartFixLlmAgent
5454
5555 # Create the extended model
56- model = ExtendedLiteLlm (model="bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0")
56+ model = SmartFixLiteLlm (model="bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0")
5757
5858 # Create the extended agent
59- agent = ExtendedLlmAgent (
59+ agent = SmartFixLlmAgent (
6060 name="my-agent",
6161 model=model,
6262 instruction="You are a helpful assistant."
@@ -77,48 +77,48 @@ class ExtendedLlmAgent(LlmAgent):
7777 original_extended_model : Optional [Any ] = Field (
7878 default = None ,
7979 exclude = True ,
80- description = "Reference to the original ExtendedLiteLlm instance for stats access"
80+ description = "Reference to the original SmartFixLiteLlm instance for stats access"
8181 )
8282
8383 @model_validator (mode = 'after' )
8484 def _preserve_extended_model_reference (self ):
85- """Preserve a reference to the ExtendedLiteLlm instance if provided."""
85+ """Preserve a reference to the SmartFixLiteLlm instance if provided."""
8686 # Import here to avoid circular imports
8787 try :
88- from .extended_litellm import ExtendedLiteLlm
88+ from .smartfix_litellm import SmartFixLiteLlm
8989
90- if isinstance (self .model , ExtendedLiteLlm ):
90+ if isinstance (self .model , SmartFixLiteLlm ):
9191 # Store reference to the original instance
9292 self .original_extended_model = self .model
93- debug_log (f"[EXTENDED_AGENT ] Preserved reference to ExtendedLiteLlm instance for agent: { self .name } " )
93+ debug_log (f"[SMARTFIX_AGENT ] Preserved reference to SmartFixLiteLlm instance for agent: { self .name } " )
9494
9595 except ImportError :
96- # ExtendedLiteLlm not available, ignore
96+ # SmartFixLiteLlm not available, ignore
9797 pass
9898
9999 return self
100100
101101 @override
102102 @property
103103 def canonical_model (self ):
104- """Override to ensure we return the original ExtendedLiteLlm instance."""
105- # If we have a preserved ExtendedLiteLlm instance, return it
104+ """Override to ensure we return the original SmartFixLiteLlm instance."""
105+ # If we have a preserved SmartFixLiteLlm instance, return it
106106 if self .original_extended_model is not None :
107107 return self .original_extended_model
108108
109109 # Otherwise, use the parent's canonical_model
110110 return super ().canonical_model
111111
112112 def has_extended_model (self ) -> bool :
113- """Check if this agent is using an ExtendedLiteLlm model."""
113+ """Check if this agent is using an SmartFixLiteLlm model."""
114114 try :
115- from .extended_litellm import ExtendedLiteLlm
116- return isinstance (self .canonical_model , ExtendedLiteLlm )
115+ from .smartfix_litellm import SmartFixLiteLlm
116+ return isinstance (self .canonical_model , SmartFixLiteLlm )
117117 except ImportError :
118118 return False
119119
120120 def get_extended_model (self ) -> Optional [Any ]:
121- """Get the ExtendedLiteLlm instance if available."""
121+ """Get the SmartFixLiteLlm instance if available."""
122122 if self .has_extended_model ():
123123 return self .canonical_model
124124 return None
@@ -127,18 +127,18 @@ def gather_accumulated_stats_dict(self) -> dict:
127127 """Get accumulated token usage and cost statistics as dictionary.
128128
129129 This method provides programmatic access to the accumulated statistics
130- from the ExtendedLiteLlm instance being used by this agent.
130+ from the SmartFixLiteLlm instance being used by this agent.
131131
132132 Returns:
133133 dict: Dictionary containing accumulated statistics
134134
135135 Raises:
136- ValueError: If the agent is not using an ExtendedLiteLlm model.
136+ ValueError: If the agent is not using an SmartFixLiteLlm model.
137137 """
138138 extended_model = self .get_extended_model ()
139139 if extended_model is None :
140140 raise ValueError (
141- f"Agent '{ self .name } ' is not using an ExtendedLiteLlm model. "
141+ f"Agent '{ self .name } ' is not using an SmartFixLiteLlm model. "
142142 "Cannot access accumulated statistics. "
143143 f"Current model type: { type (self .canonical_model ).__name__ } "
144144 )
@@ -149,18 +149,18 @@ def gather_accumulated_stats(self) -> str:
149149 """Get accumulated token usage and cost statistics as JSON string.
150150
151151 This method provides programmatic access to the accumulated statistics
152- from the ExtendedLiteLlm instance being used by this agent.
152+ from the SmartFixLiteLlm instance being used by this agent.
153153
154154 Returns:
155155 str: JSON formatted string containing accumulated statistics
156156
157157 Raises:
158- ValueError: If the agent is not using an ExtendedLiteLlm model.
158+ ValueError: If the agent is not using an SmartFixLiteLlm model.
159159 """
160160 extended_model = self .get_extended_model ()
161161 if extended_model is None :
162162 raise ValueError (
163- f"Agent '{ self .name } ' is not using an ExtendedLiteLlm model. "
163+ f"Agent '{ self .name } ' is not using an SmartFixLiteLlm model. "
164164 "Cannot access accumulated statistics. "
165165 f"Current model type: { type (self .canonical_model ).__name__ } "
166166 )
@@ -171,12 +171,12 @@ def reset_accumulated_stats(self) -> None:
171171 """Reset accumulated statistics to start fresh.
172172
173173 Raises:
174- ValueError: If the agent is not using an ExtendedLiteLlm model.
174+ ValueError: If the agent is not using an SmartFixLiteLlm model.
175175 """
176176 extended_model = self .get_extended_model ()
177177 if extended_model is None :
178178 raise ValueError (
179- f"Agent '{ self .name } ' is not using an ExtendedLiteLlm model. "
179+ f"Agent '{ self .name } ' is not using an SmartFixLiteLlm model. "
180180 "Cannot reset accumulated statistics. "
181181 f"Current model type: { type (self .canonical_model ).__name__ } "
182182 )
@@ -197,12 +197,12 @@ def get_accumulated_stats_summary(self) -> dict:
197197 - And more detailed breakdowns
198198
199199 Raises:
200- ValueError: If the agent is not using an ExtendedLiteLlm model.
200+ ValueError: If the agent is not using an SmartFixLiteLlm model.
201201 """
202202 extended_model = self .get_extended_model ()
203203 if extended_model is None :
204204 raise ValueError (
205- f"Agent '{ self .name } ' is not using an ExtendedLiteLlm model. "
205+ f"Agent '{ self .name } ' is not using an SmartFixLiteLlm model. "
206206 "Cannot access accumulated statistics. "
207207 f"Current model type: { type (self .canonical_model ).__name__ } "
208208 )
@@ -236,7 +236,7 @@ def get_model_info(self) -> dict:
236236 dict: Dictionary containing model information including:
237237 - model_name: The model name/identifier
238238 - model_type: The class name of the model
239- - is_extended: Whether it's an ExtendedLiteLlm instance
239+ - is_extended: Whether it's an SmartFixLiteLlm instance
240240 - has_stats: Whether accumulated statistics are available
241241 """
242242 model = self .canonical_model
@@ -251,11 +251,11 @@ def get_model_info(self) -> dict:
251251 }
252252
253253
254- # Rebuild the model schema after ExtendedLiteLlm is available
254+ # Rebuild the model schema after SmartFixLiteLlm is available
255255# This resolves forward references and ensures Pydantic can fully validate the model
256- if ExtendedLiteLlm is not None :
256+ if SmartFixLiteLlm is not None :
257257 try :
258- ExtendedLlmAgent .model_rebuild ()
258+ SmartFixLlmAgent .model_rebuild ()
259259 except Exception :
260260 # If rebuild fails for any reason, just continue
261261 # The class will still work, just without perfect type validation
0 commit comments