Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
44609e2
1
Parent(s): 4f25676
backend stabilization
Browse files- agents/suggestion.py +3 -2
- core/llm.py +2 -3
- core/tasks.py +1 -1
- nexus_worker.py +21 -19
agents/suggestion.py
CHANGED
|
@@ -84,7 +84,8 @@ async def _process_suggestion(state: AgentState, db: Any) -> Dict[str, Any]:
|
|
| 84 |
# 3. Generate Drafts via LLM
|
| 85 |
from langchain_core.output_parsers import JsonOutputParser
|
| 86 |
prompt = ChatPromptTemplate.from_template(SUGGESTION_PROMPT)
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
import asyncio
|
| 90 |
logger.info(f"Suggestion node generating reply and draft via LLM for ticket {state['ticket_id']}")
|
|
@@ -94,7 +95,7 @@ async def _process_suggestion(state: AgentState, db: Any) -> Dict[str, Any]:
|
|
| 94 |
"description": state["description"],
|
| 95 |
"context": context,
|
| 96 |
"is_new_topic": state.get("is_new_topic", False)
|
| 97 |
-
}), timeout=
|
| 98 |
except asyncio.TimeoutError:
|
| 99 |
logger.warning(f"Suggestion node TIMEOUT for ticket {state['ticket_id']}. Using fallback.")
|
| 100 |
result = {
|
|
|
|
| 84 |
# 3. Generate Drafts via LLM
|
| 85 |
from langchain_core.output_parsers import JsonOutputParser
|
| 86 |
prompt = ChatPromptTemplate.from_template(SUGGESTION_PROMPT)
|
| 87 |
+
# Pass a higher timeout to the LLM client as well
|
| 88 |
+
chain = prompt | get_llm(timeout=300) | JsonOutputParser()
|
| 89 |
|
| 90 |
import asyncio
|
| 91 |
logger.info(f"Suggestion node generating reply and draft via LLM for ticket {state['ticket_id']}")
|
|
|
|
| 95 |
"description": state["description"],
|
| 96 |
"context": context,
|
| 97 |
"is_new_topic": state.get("is_new_topic", False)
|
| 98 |
+
}), timeout=300.0) # Increased to 5 minutes for local Ollama execution
|
| 99 |
except asyncio.TimeoutError:
|
| 100 |
logger.warning(f"Suggestion node TIMEOUT for ticket {state['ticket_id']}. Using fallback.")
|
| 101 |
result = {
|
core/llm.py
CHANGED
|
@@ -38,9 +38,8 @@ def get_llm(provider: str = None, model: str = None, use_fast_model: bool = Fals
|
|
| 38 |
return _llm_cache[cache_key]
|
| 39 |
|
| 40 |
if provider == "freellmapi":
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
llm = FailoverChatModel(primary, backup)
|
| 44 |
elif provider == "ollama":
|
| 45 |
llm = _init_ollama(model=model, **kwargs)
|
| 46 |
else:
|
|
|
|
| 38 |
return _llm_cache[cache_key]
|
| 39 |
|
| 40 |
if provider == "freellmapi":
|
| 41 |
+
logging.warning("freellmapi is deprecated. Falling back to ollama as primary.")
|
| 42 |
+
llm = _init_ollama(model=model, **kwargs)
|
|
|
|
| 43 |
elif provider == "ollama":
|
| 44 |
llm = _init_ollama(model=model, **kwargs)
|
| 45 |
else:
|
core/tasks.py
CHANGED
|
@@ -1767,7 +1767,7 @@ async def record_workflow_step_task(
|
|
| 1767 |
input_data=input_data,
|
| 1768 |
output_data=output_data,
|
| 1769 |
current_stage=current_stage,
|
| 1770 |
-
duration_ms=duration_ms
|
| 1771 |
)
|
| 1772 |
await db.commit()
|
| 1773 |
except Exception as e:
|
|
|
|
| 1767 |
input_data=input_data,
|
| 1768 |
output_data=output_data,
|
| 1769 |
current_stage=current_stage,
|
| 1770 |
+
duration_ms=duration_ms or 0.0
|
| 1771 |
)
|
| 1772 |
await db.commit()
|
| 1773 |
except Exception as e:
|
nexus_worker.py
CHANGED
|
@@ -147,9 +147,28 @@ async def on_job_end(ctx):
|
|
| 147 |
if job.started_at:
|
| 148 |
job.duration_ms = (job.finished_at - job.started_at).total_seconds() * 1000
|
| 149 |
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
job.status = JobStatus.SUCCESS
|
| 152 |
-
result_data = sanitize_for_db(
|
| 153 |
job.result = result_data
|
| 154 |
|
| 155 |
# Cache Populate: If this was a history recovery, cache for instant UI hydration
|
|
@@ -166,23 +185,6 @@ async def on_job_end(ctx):
|
|
| 166 |
# Success logging
|
| 167 |
|
| 168 |
logger.info(f"✅ Job SUCCESS: {job.task_name} | ID: {job_id}")
|
| 169 |
-
else:
|
| 170 |
-
exception = ctx.get("exception")
|
| 171 |
-
result = ctx.get("result")
|
| 172 |
-
|
| 173 |
-
# ARQ edge case: sometimes exception is returned in the result field
|
| 174 |
-
if exception is None and isinstance(result, Exception):
|
| 175 |
-
exception = result
|
| 176 |
-
|
| 177 |
-
if exception is None:
|
| 178 |
-
# Verify if job was cancelled or worker is genuinely shutting down
|
| 179 |
-
job.error = "SYSTEM_INTERRUPTION: Job was interrupted (Worker Shutdown or Cancelled)."
|
| 180 |
-
job.status = JobStatus.INTERRUPTED
|
| 181 |
-
logger.warning(f"⚠️ Job INTERRUPTED: {job.task_name} | ID: {job_id}")
|
| 182 |
-
else:
|
| 183 |
-
job.status = JobStatus.FAILED
|
| 184 |
-
job.error = str(exception)
|
| 185 |
-
logger.error(f"❌ Job FAILED: {job.task_name} | ID: {job_id} | {job.error}")
|
| 186 |
|
| 187 |
db.add(job)
|
| 188 |
await db.commit()
|
|
|
|
| 147 |
if job.started_at:
|
| 148 |
job.duration_ms = (job.finished_at - job.started_at).total_seconds() * 1000
|
| 149 |
|
| 150 |
+
success = ctx.get("success", True) if "success" in ctx else True
|
| 151 |
+
exception = ctx.get("exception")
|
| 152 |
+
result = ctx.get("result")
|
| 153 |
+
|
| 154 |
+
# ARQ edge case: sometimes exception is returned in the result field
|
| 155 |
+
if exception is None and isinstance(result, Exception):
|
| 156 |
+
exception = result
|
| 157 |
+
success = False
|
| 158 |
+
|
| 159 |
+
if not success or exception is not None:
|
| 160 |
+
if exception is None:
|
| 161 |
+
# Verify if job was cancelled or worker is genuinely shutting down
|
| 162 |
+
job.error = "SYSTEM_INTERRUPTION: Job was interrupted (Worker Shutdown or Cancelled)."
|
| 163 |
+
job.status = JobStatus.INTERRUPTED
|
| 164 |
+
logger.warning(f"⚠️ Job INTERRUPTED: {job.task_name} | ID: {job_id}")
|
| 165 |
+
else:
|
| 166 |
+
job.status = JobStatus.FAILED
|
| 167 |
+
job.error = str(exception)
|
| 168 |
+
logger.error(f"❌ Job FAILED: {job.task_name} | ID: {job_id} | {job.error}")
|
| 169 |
+
else:
|
| 170 |
job.status = JobStatus.SUCCESS
|
| 171 |
+
result_data = sanitize_for_db(result)
|
| 172 |
job.result = result_data
|
| 173 |
|
| 174 |
# Cache Populate: If this was a history recovery, cache for instant UI hydration
|
|
|
|
| 185 |
# Success logging
|
| 186 |
|
| 187 |
logger.info(f"✅ Job SUCCESS: {job.task_name} | ID: {job_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
db.add(job)
|
| 190 |
await db.commit()
|