Spaces:
Runtime error
Runtime error
Update agent_langchain.py
Browse files- agent_langchain.py +4 -14
agent_langchain.py
CHANGED
|
@@ -29,15 +29,6 @@ ROUTING_URL = os.environ.get("ROUTING_URL")
|
|
| 29 |
SPACE_URL = os.environ.get("SPACE_URL", "http://localhost:7860")
|
| 30 |
FIREBASE_CREDS_PATH = os.environ.get("FIREBASE_CREDS_PATH")
|
| 31 |
|
| 32 |
-
import json
|
| 33 |
-
|
| 34 |
-
# If Firebase credentials are stored as a secret string, write them to /tmp
|
| 35 |
-
if os.environ.get("FIREBASE_CREDS_JSON"):
|
| 36 |
-
creds_path = "/tmp/firebase_creds.json"
|
| 37 |
-
with open(creds_path, "w") as f:
|
| 38 |
-
f.write(os.environ["FIREBASE_CREDS_JSON"])
|
| 39 |
-
os.environ["FIREBASE_CREDS_PATH"] = creds_path
|
| 40 |
-
|
| 41 |
# Initialize Firebase
|
| 42 |
db = None
|
| 43 |
if FIREBASE_CREDS_PATH and os.path.exists(FIREBASE_CREDS_PATH):
|
|
@@ -159,7 +150,7 @@ def save_ticket_to_firestore(ticket_data: Dict[str, Any]):
|
|
| 159 |
|
| 160 |
# Gemini LLM
|
| 161 |
llm = ChatGoogleGenerativeAI(
|
| 162 |
-
model="gemini-2.
|
| 163 |
temperature=0.3,
|
| 164 |
google_api_key=GEMINI_API_KEY
|
| 165 |
)
|
|
@@ -229,7 +220,6 @@ GUIDING PRINCIPLES:
|
|
| 229 |
4. **Escalate wisely** - Only escalate when truly necessary (low KB confidence, complex issues, or failed solutions)
|
| 230 |
5. **Maintain context** - Remember previous conversation history when handling follow-ups
|
| 231 |
6. **Be empathetic** - Users are frustrated when things break; be professional and supportive
|
| 232 |
-
7. **Be Useful** - If low KB confidence , then try answering the query using general Knowledge and escalate the issue.
|
| 233 |
|
| 234 |
DECISION FRAMEWORK:
|
| 235 |
- For a NEW ticket: You might need to classify, route, search KB - but decide based on what's needed
|
|
@@ -266,10 +256,10 @@ agent_executor = AgentExecutor(
|
|
| 266 |
agent=agent,
|
| 267 |
tools=tools,
|
| 268 |
verbose=True,
|
| 269 |
-
max_iterations=
|
| 270 |
-
handle_parsing_errors=
|
| 271 |
return_intermediate_steps=True,
|
| 272 |
-
early_stopping_method="
|
| 273 |
)
|
| 274 |
|
| 275 |
# Main Processing Function
|
|
|
|
| 29 |
SPACE_URL = os.environ.get("SPACE_URL", "http://localhost:7860")
|
| 30 |
FIREBASE_CREDS_PATH = os.environ.get("FIREBASE_CREDS_PATH")
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Initialize Firebase
|
| 33 |
db = None
|
| 34 |
if FIREBASE_CREDS_PATH and os.path.exists(FIREBASE_CREDS_PATH):
|
|
|
|
| 150 |
|
| 151 |
# Gemini LLM
|
| 152 |
llm = ChatGoogleGenerativeAI(
|
| 153 |
+
model="gemini-2.0-flash-exp",
|
| 154 |
temperature=0.3,
|
| 155 |
google_api_key=GEMINI_API_KEY
|
| 156 |
)
|
|
|
|
| 220 |
4. **Escalate wisely** - Only escalate when truly necessary (low KB confidence, complex issues, or failed solutions)
|
| 221 |
5. **Maintain context** - Remember previous conversation history when handling follow-ups
|
| 222 |
6. **Be empathetic** - Users are frustrated when things break; be professional and supportive
|
|
|
|
| 223 |
|
| 224 |
DECISION FRAMEWORK:
|
| 225 |
- For a NEW ticket: You might need to classify, route, search KB - but decide based on what's needed
|
|
|
|
| 256 |
agent=agent,
|
| 257 |
tools=tools,
|
| 258 |
verbose=True,
|
| 259 |
+
max_iterations=6, # Reduced to prevent loops
|
| 260 |
+
handle_parsing_errors="Check your output and make sure it conforms to the format instructions!",
|
| 261 |
return_intermediate_steps=True,
|
| 262 |
+
early_stopping_method="force" # Force stop if max iterations reached
|
| 263 |
)
|
| 264 |
|
| 265 |
# Main Processing Function
|