Skip to content

Commit 9959d2f

Browse files
committed
feat: added supportfor sensitive variables
1 parent 4a55d47 commit 9959d2f

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/agent/custom_agent.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ def __init__(
9191
planner_llm: Optional[BaseChatModel] = None,
9292
planner_interval: int = 1, # Run planner every N steps
9393
):
94+
95+
# Load sensitive data from environment variables
96+
env_sensitive_data = {}
97+
for key, value in os.environ.items():
98+
if key.startswith('SENSITIVE_'):
99+
env_key = key.replace('SENSITIVE_', '', 1).lower()
100+
env_sensitive_data[env_key] = value
101+
102+
# Merge environment variables with provided sensitive_data
103+
if sensitive_data is None:
104+
sensitive_data = {}
105+
sensitive_data = {**env_sensitive_data, **sensitive_data} # Provided data takes precedence
106+
107+
94108
super().__init__(
95109
task=task,
96110
llm=llm,

webui.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@
4444
# Create the global agent state instance
4545
_global_agent_state = AgentState()
4646

47+
def resolve_sensitive_env_variables(text):
48+
"""
49+
Replace environment variable placeholders ($SENSITIVE_*) with their values.
50+
Only replaces variables that start with SENSITIVE_.
51+
"""
52+
if not text:
53+
return text
54+
55+
import re
56+
57+
# Find all $SENSITIVE_* patterns
58+
env_vars = re.findall(r'\$SENSITIVE_[A-Za-z0-9_]*', text)
59+
60+
result = text
61+
for var in env_vars:
62+
# Remove the $ prefix to get the actual environment variable name
63+
env_name = var[1:] # removes the $
64+
env_value = os.getenv(env_name)
65+
if env_value is not None:
66+
# Replace $SENSITIVE_VAR_NAME with its value
67+
result = result.replace(var, env_value)
68+
69+
return result
70+
4771
async def stop_agent():
4872
"""Request the agent to stop and update UI with enhanced feedback"""
4973
global _global_agent_state, _global_browser_context, _global_browser, _global_agent
@@ -141,6 +165,8 @@ async def run_browser_agent(
141165
+ glob.glob(os.path.join(save_recording_path, "*.[wW][eE][bB][mM]"))
142166
)
143167

168+
task = resolve_sensitive_env_variables(task)
169+
144170
# Run the agent
145171
llm = utils.get_llm_model(
146172
provider=llm_provider,

0 commit comments

Comments
 (0)