-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfallback_inicial.py
More file actions
48 lines (36 loc) · 1.66 KB
/
fallback_inicial.py
File metadata and controls
48 lines (36 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Nodo 3: Fallback Inicial - Initial fallback processing."""
import logging
from app.agents.state import AgentState
logger = logging.getLogger(__name__)
def fallback_inicial(state: AgentState) -> AgentState:
"""
Fallback Inicial node - Performs initial fallback processing.
This node:
1. Defensively checks if the prompt was flagged as malicious
2. Adjusts the text if needed (e.g., formatting, normalization)
3. Prepares text for paraphrasing step
Args:
state: Agent state containing the prompt or initial context
Returns:
Updated state with adjusted_text set (if applicable) or error_message if malicious
"""
updated_state = state.copy()
# Defensive check: Verify that the prompt was not flagged as malicious
# This should not happen due to routing, but serves as an extra safety layer
if state.get("is_malicious", False):
logger.warning(
"Defensive check triggered: Malicious prompt reached fallback_inicial node. "
"This indicates a potential routing issue."
)
updated_state["error_message"] = "The requested information or action is not possible by the agent."
updated_state["adjusted_text"] = None
return updated_state
# TODO: Implement initial fallback logic
# This should:
# 1. Normalize text (remove extra spaces, fix encoding, etc.)
# 2. Apply any necessary text adjustments
# 3. Set adjusted_text if adjustments were made, otherwise None
# Placeholder: For now, we'll use the prompt as-is
prompt = state.get("prompt", "")
updated_state["adjusted_text"] = prompt if prompt else None
return updated_state