mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix(compression): harden provider context handoff
This commit is contained in:
parent
192ef93ad5
commit
34bab1c6ac
7 changed files with 293 additions and 42 deletions
|
|
@ -28,6 +28,30 @@ Lifecycle:
|
|||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from agent.redact import redact_sensitive_text
|
||||
|
||||
|
||||
MEMORY_CONTEXT_MAX_CHARS = 6_000
|
||||
_MEMORY_CONTEXT_HEAD_CHARS = 4_000
|
||||
_MEMORY_CONTEXT_TAIL_CHARS = 1_500
|
||||
_MEMORY_CONTEXT_TRUNCATION_MARKER = "\n...[memory provider context truncated]...\n"
|
||||
|
||||
|
||||
def sanitize_memory_context(memory_context: str) -> str:
|
||||
"""Prepare provider context for a context-engine/LLM egress boundary."""
|
||||
sanitized = redact_sensitive_text(
|
||||
memory_context.strip(),
|
||||
force=True,
|
||||
redact_url_credentials=True,
|
||||
)
|
||||
if len(sanitized) <= MEMORY_CONTEXT_MAX_CHARS:
|
||||
return sanitized
|
||||
return (
|
||||
sanitized[:_MEMORY_CONTEXT_HEAD_CHARS]
|
||||
+ _MEMORY_CONTEXT_TRUNCATION_MARKER
|
||||
+ sanitized[-_MEMORY_CONTEXT_TAIL_CHARS:]
|
||||
)
|
||||
|
||||
|
||||
class ContextEngine(ABC):
|
||||
"""Base class all context engines must implement."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue