AgentAdvisorPolicy(*, advisor_engine: Any = None, advisor_model: str = '', max_traces: int = 50)
Bases: AgentLearningPolicy
Higher-level LM analyzes traces, suggests agent structure changes.
Does NOT auto-apply changes — returns recommendations that can be
reviewed or applied via config.
Source code in src/openjarvis/learning/agent_advisor.py
| def __init__(
self,
*,
advisor_engine: Any = None,
advisor_model: str = "",
max_traces: int = 50,
) -> None:
self._advisor_engine = advisor_engine
self._advisor_model = advisor_model
self._max_traces = max_traces
|
Functions
update
update(trace_store: Any, **kwargs: object) -> Dict[str, Any]
Analyze traces and return agent improvement recommendations.
Source code in src/openjarvis/learning/agent_advisor.py
| def update(self, trace_store: Any, **kwargs: object) -> Dict[str, Any]:
"""Analyze traces and return agent improvement recommendations."""
try:
traces = trace_store.list_traces()
except Exception as exc:
logger.warning("Agent advisor analysis failed: %s", exc)
return {"recommendations": [], "confidence": 0.0}
# Collect failing or slow traces
problem_traces = []
for trace in traces[-self._max_traces :]:
is_failing = trace.outcome != "success"
is_slow = (trace.total_latency_seconds or 0) > 5.0
if is_failing or is_slow:
problem_traces.append(trace)
if not problem_traces:
return {
"recommendations": [],
"confidence": 1.0,
"message": "No problematic traces found",
}
# Analyze patterns without LM (structural analysis)
recommendations = self._analyze_patterns(problem_traces)
# If advisor engine available, get LM-guided recommendations
if self._advisor_engine and self._advisor_model:
try:
lm_recs = self._get_lm_recommendations(problem_traces)
recommendations.extend(lm_recs)
except Exception as exc:
logger.debug("Failed to parse agent advisor recommendation: %s", exc)
confidence = 1.0 - (len(problem_traces) / max(len(traces), 1))
return {
"recommendations": recommendations,
"confidence": round(confidence, 2),
"analyzed_traces": len(traces),
"problem_traces": len(problem_traces),
}
|