The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(memory,langfuse): compact literal/config builders and call-site formatting
Teknium99b7bb9addcf
diff --git a/plugins/memory/hindsight/__init__.py b/plugins/memory/hindsight/__init__.pyindex 709e2ba2f89..a750191a357 100644--- a/plugins/memory/hindsight/__init__.py+++ b/plugins/memory/hindsight/__init__.py@@ -274,8 +274,7 @@ REFLECT_SCHEMA = {def _load_config() -> dict:"""$HERMES_HOME/hindsight/config.json (profile-scoped), else ~/.hindsight/config.json(legacy, shared), else environment variables."""- for path in (get_hermes_home() / "hindsight" / "config.json",- Path.home() / ".hindsight" / "config.json"):+ for path in (get_hermes_home() / "hindsight" / "config.json", Path.home() / ".hindsight" / "config.json"):if path.exists():try:return json.loads(path.read_text(encoding="utf-8"))@@ -291,13 +290,8 @@ def _load_config() -> dict:"retain_source": os.environ.get("HINDSIGHT_RETAIN_SOURCE", _DEFAULT_RETAIN_SOURCE),"retain_user_prefix": os.environ.get("HINDSIGHT_RETAIN_USER_PREFIX", "User"),"retain_assistant_prefix": os.environ.get("HINDSIGHT_RETAIN_ASSISTANT_PREFIX", "Assistant"),- "banks": {- "hermes": {- "bankId": os.environ.get("HINDSIGHT_BANK_ID", "hermes"),- "budget": os.environ.get("HINDSIGHT_BUDGET", "mid"),- "enabled": True,- }- },+ "banks": {"hermes": {"bankId": os.environ.get("HINDSIGHT_BANK_ID", "hermes"),+ "budget": os.environ.get("HINDSIGHT_BUDGET", "mid"), "enabled": True}},}diff --git a/plugins/memory/hindsight/setup.py b/plugins/memory/hindsight/setup.pyindex e2f49cb73be..62e53f0cd26 100644--- a/plugins/memory/hindsight/setup.py+++ b/plugins/memory/hindsight/setup.py@@ -94,8 +94,7 @@ def run_setup(provider, hermes_home: str, config: dict) -> None:print("\n Configuring Hindsight memory:\n")existing_config = provider._config if isinstance(provider._config, dict) else _load_config()- if not isinstance(existing_config, dict):- existing_config = {}+ existing_config = existing_config if isinstance(existing_config, dict) else {}mode = _select(" Select mode", _MODE_ITEMS, _MODE_VALUES, existing_config.get("mode"))if mode is None:diff --git a/plugins/observability/langfuse/__init__.py b/plugins/observability/langfuse/__init__.pyindex 79076670954..d94402032b9 100644--- a/plugins/observability/langfuse/__init__.py+++ b/plugins/observability/langfuse/__init__.py@@ -345,22 +345,17 @@ def _normalize_read_file_payload(value: dict[str, Any], *, args: Any = None) ->if lines:normalized["returned_lines"] = {"start": lines[0]["line"], "end": lines[-1]["line"], "count": len(lines)}head, tail = _READ_FILE_HEAD_LINES, _READ_FILE_TAIL_LINES- if len(lines) <= head + tail:- normalized["content_preview"] = {"lines": lines}- else:- normalized["content_preview"] = {- "head": lines[:head],- "tail": lines[-tail:],- "omitted_line_count": len(lines) - head - tail,- }+ normalized["content_preview"] = {"lines": lines} if len(lines) <= head + tail else {+ "head": lines[:head], "tail": lines[-tail:], "omitted_line_count": len(lines) - head - tail,+ }elif value.get("content"):normalized["content_preview"] = {"text": value.get("content", "")}normalized.update({key: value[key] for key in _READ_FILE_META_KEYS if key in value})- base64_content = value.get("base64_content")- if isinstance(base64_content, str) and base64_content:- normalized["base64_content"] = {"omitted": True, "length": len(base64_content)}+ b64 = value.get("base64_content")+ if isinstance(b64, str) and b64:+ normalized["base64_content"] = {"omitted": True, "length": len(b64)}return normalized@@ -588,10 +583,8 @@ def _start_root_trace(task_key: str, *, task_id: str, session_id: str, platform:trace_ctx: Dict[str, Any] = {"trace_id": trace_id, **({"session_id": session_id} if session_id else {})}def open_root():- ctx = client.start_as_current_observation(- trace_context=trace_ctx, name="Hermes turn", as_type="chain",- input=trace_input, metadata=metadata, end_on_exit=False,- )+ ctx = client.start_as_current_observation(trace_context=trace_ctx, name="Hermes turn", as_type="chain",+ input=trace_input, metadata=metadata, end_on_exit=False)return ctx, ctx.__enter__()root_ctx = root_span = None@@ -618,10 +611,8 @@ def _start_root_trace(task_key: str, *, task_id: str, session_id: str, platform:def _start_child_observation(state: TraceState, *, client: Langfuse, name: str, as_type: str,input_value: Any, metadata: Optional[dict] = None,model: Optional[str] = None, model_parameters: Optional[dict] = None) -> Any:- return state.root_span.start_observation(- name=name, as_type=as_type, input=input_value, metadata=metadata or {},- model=model, model_parameters=model_parameters,- )+ return state.root_span.start_observation(name=name, as_type=as_type, input=input_value, metadata=metadata or {},+ model=model, model_parameters=model_parameters)def _end_observation(observation: Any, *, output: Any = None, metadata: Optional[dict] = None,@@ -768,8 +759,7 @@ def _pop_generation(task_key: str, api_call_count: Any) -> tuple[Optional[TraceS"""Detach the open generation for one API call. Returns (state, generation); either may be None."""with _STATE_LOCK:state = _TRACE_STATE.get(task_key)- generation = state.generations.pop(_request_key(api_call_count), None) if state else None- return state, generation+ return state, state.generations.pop(_request_key(api_call_count), None) if state else Nonedef _get_or_start_state_locked(task_key: str, **root_kwargs: Any) -> TraceState: