Refine memory settings and admin usage stats
This commit is contained in:
@@ -1229,6 +1229,17 @@ def create_app(state: AgentState) -> FastAPI:
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
@app.get('/api/memory/events')
|
||||
async def get_memory_events(account_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
safe_account = _safe_account_id(account_id)
|
||||
return {
|
||||
'queue': state.memory_manager.queue_snapshot(safe_account),
|
||||
'events': state.memory_manager.list_recent_events(safe_account, limit=20),
|
||||
}
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
@app.get('/api/memory/skills/{skill_name}')
|
||||
async def get_skill_memory(skill_name: str, account_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
@@ -3561,6 +3572,7 @@ def _list_admin_accounts(state: AgentState) -> list[dict[str, Any]]:
|
||||
total_tokens = 0
|
||||
input_tokens = 0
|
||||
output_tokens = 0
|
||||
reasoning_tokens = 0
|
||||
latest_mtime = 0.0
|
||||
models: dict[str, int] = {}
|
||||
for path in session_files:
|
||||
@@ -3573,6 +3585,7 @@ def _list_admin_accounts(state: AgentState) -> list[dict[str, Any]]:
|
||||
usage = data.get('usage') if isinstance(data.get('usage'), dict) else {}
|
||||
input_tokens += int(usage.get('input_tokens') or 0)
|
||||
output_tokens += int(usage.get('output_tokens') or 0)
|
||||
reasoning_tokens += int(usage.get('reasoning_tokens') or 0)
|
||||
total_tokens += int(
|
||||
usage.get('total_tokens')
|
||||
or (usage.get('input_tokens') or 0) + (usage.get('output_tokens') or 0)
|
||||
@@ -3590,7 +3603,14 @@ def _list_admin_accounts(state: AgentState) -> list[dict[str, Any]]:
|
||||
'tool_calls': tool_calls,
|
||||
'input_tokens': input_tokens,
|
||||
'output_tokens': output_tokens,
|
||||
'reasoning_tokens': reasoning_tokens,
|
||||
'total_tokens': total_tokens,
|
||||
'average_tokens_per_session': (
|
||||
round(total_tokens / session_count, 1) if session_count else 0
|
||||
),
|
||||
'average_tool_calls_per_session': (
|
||||
round(tool_calls / session_count, 1) if session_count else 0
|
||||
),
|
||||
'latest_session_at': latest_mtime,
|
||||
'models': models,
|
||||
'user_memory_lines': _count_optional_lines(memory_dir / USER_MEMORY_FILENAME),
|
||||
|
||||
Reference in New Issue
Block a user