haoyuan-sjtu
Deepseek-Harness-Lifelong-Agent
A governed long-term memory core for AI agents, with technical-preview adapter contracts for DeepSeek Harness integration.
- Stars
- 0
- Language
- TypeScript
- Created
- Aug 14, 2026
- Updated
- Aug 14, 2026
Introduction
DeepSeek Harness Lifelong Agent
中文说明 · Security policy · Contributing
Repository: https://github.com/haoyuan-sjtu/Deepseek-Harness-Lifelong-Agent
Governed long-term memory for AI agents. This TypeScript package provides a small, auditable policy core for deciding what an agent may remember, retrieve, retire, or revoke.
Technical Preview — DSH compatibility
The standalone governance core is runnable and unit-tested. The included DSH adapter defines integration contracts only; it has not yet been registered and end-to-end validated against a pinned DSH/Cordis release. It must not be presented as a drop-in plugin for arbitrary DSH versions.
Why this project exists
Long-running agents need continuity: project constraints, validated decisions, prior failures, user-approved preferences, and lessons from completed work. A naive “save everything and retrieve it later” design creates a different class of failures:
- a model summary, a one-off tool response, or unconfirmed feedback becomes a durable but false rule;
- stale decisions silently steer a new task after the repository, policy, or environment has changed;
- project, user, or sensitive information crosses an authorization boundary;
- conflicting memories are injected together and prompt the agent to make an arbitrary choice;
- memory retrieval consumes the context window and causes unpredictable token and cost growth;
- a recalled item cannot be traced to its source or reliably withdrawn after a correction.
DSH Governed Memory treats long-term memory as a controlled lifecycle, not a transcript archive. It gives the host application explicit, inspectable decisions at every point where memory enters or leaves the model context.
Design approach
The core implements the following lifecycle:
capture → quarantine → verify → promoted → retrieve
↘ decay / superseded / revoked
- Capture into quarantine. Model summaries, individual tool outputs, and unconfirmed feedback begin as
quarantinerecords and are not retrievable by default. - Verify and explicitly promote. A record requires verified A/B-grade evidence and an explicit approval decision before it becomes
promoted. - Filter before retrieval. The registry rejects records that are not promoted, are cross-scope, privacy-denied, expired, stale, superseded, revoked, or in canonical-key conflict.
- Retrieve a token-bounded minimum set. A
ContextLedgerrecords selected and excluded records, estimated token use, and machine-readable reason codes. - Preflight the request budget. A cost policy returns
ALLOW,MITIGATE, orBLOCKbefore the model request; estimates are never represented as provider billing. - Preserve auditability. Capture, promotion, retrieval, decay, and revocation emit events so a host can reconstruct why a memory was visible or withheld.
Features in this beta
| Capability | Beta behavior |
|---|---|
| Candidate isolation | capture() always writes quarantine |
| Promotion gate | Requires verified A/B evidence and an approval argument |
| Retrieval policy | Enforces status, scope, privacy, expiry, conflict, relevance, and token budget |
| Conflict/staleness | Same canonicalKey promoted records are denied; stale records enter decay |
| Revocation | revoke() blocks future retrieval and emits an audit event |
| Context governance | ContextLedger records inclusions/exclusions and tokens |
| Budget governance | Session/daily remaining budget produces ALLOW / MITIGATE / BLOCK |
| DSH boundary | onPreStep, onRequest, and onSessionEvent adapter contracts |
Install
This beta is published as source on GitHub. Use the repository workflow below; dsh-governed-memory is not yet published to npm.
For repository development, use Node.js 20 or newer:
git clone https://github.com/haoyuan-sjtu/Deepseek-Harness-Lifelong-Agent.git
cd Deepseek-Harness-Lifelong-Agent
npm ci
npm run check
If you fork the repository, replace the clone URL with your fork URL.
Quick start
import { MemoryRegistry } from 'dsh-governed-memory';
const registry = new MemoryRegistry();
// Untrusted or unreviewed material starts quarantined, even if the caller
// supplied a different initial status.
registry.capture({
id: 'budget-policy',
status: 'quarantine',
scope: 'project',
privacy: 'internal',
canonicalKey: 'project:budget-policy',
text: 'Use a dual budget threshold.',
tags: ['budget'],
evidence: [{ uri: 'docs://decision', level: 'A', locator: '1', verified: true }],
createdAt: new Date().toISOString(),
reviewBy: '2026-12-01T00:00:00Z',
expiresAt: '2027-01-01T00:00:00Z',
confidence: 0.9,
maxTokens: 120,
parentIds: []
});
// Promotion is deliberately explicit.
registry.verifyAndPromote('budget-policy', true);
const result = registry.retrieve({
scope: 'project',
allowedPrivacy: ['public', 'internal'],
now: '2026-08-14T00:00:00Z',
queryTags: ['budget'],
tokenBudget: 256
});
console.log(result.selected.map(memory => memory.id)); // ['budget-policy']
console.log(result.excluded); // records withheld with reason codes
Run the repository example with npm run example.
Non-negotiable governance invariants
- Model summaries, single tool outputs, and unconfirmed feedback are never automatically promoted.
- Only
promotedmemories that pass scope, privacy, expiry, conflict, relevance, and token-budget checks may be retrieved. quarantine,verify,decay,superseded, andrevokedrecords are denied by default.- Every retrieval decision has an inclusion/exclusion trail and reason code.
- A one-request override, if a host implements one, must be host-scoped, time-limited, and must not create a permanent bypass.
- The package does not convert estimates into actual provider usage or billing claims.
DSH integration status
src/dsh-adapter.ts supplies onPreStep, onRequest, and onSessionEvent contracts. The intended mapping is:
| DSH integration point | Responsibility |
|---|---|
agent/pre-step | Retrieve eligible memory, assemble a ContextLedger, and persist model-visible provenance |
agent/request | Perform a preflight budget decision before an LLM call |
| durable session events | Record capture, verification, promotion, retrieval, decay, supersession, and revocation |
| LLM usage processing | Normalize actual or conservative usage in the host integration |
See the integration contract and the configuration intent example. Before using it with a real DSH deployment, verify Cordis service registration, waterfall next() semantics, SessionEventMap extension, storage atomicity, and provider usage fields for that exact release.
Evaluation
The repository includes a four-condition protocol in docs/evaluation_protocol.md:
- C0: no long-term memory;
- C1: quarantine candidates only — expected to behave like C0 for retrieval;
- C2: promoted memory with governance filters;
- C3: promoted memory with ContextLedger and budget governance.
Evaluate deterministic task verification, harmful side effects, unauthorized retrieval, revoked-memory references, input/output/memory tokens, cost, latency, and human approvals. A memory feature is not successful merely because a final answer looks better; it must improve verified outcomes without weakening the safety and cost guardrails.
Security and privacy
Do not store credentials, raw private sessions, or unrestricted sensitive data in a memory registry. Deployment still requires correct host authorization, storage permissions, and secret handling. Read SECURITY.md before deployment; report vulnerabilities privately through the repository's GitHub Security Advisories.
Development
| Command | Purpose |
|---|---|
npm run build | Compile TypeScript and declarations |
npm test | Run governance-core unit tests |
npm run example | Run the minimal example |
npm run check | Build, tests, and example |
npm run pack:dry-run | Inspect npm release contents |
The npm package uses a files allowlist and publishes only dist/src/, README.md, LICENSE, NOTICE, and SECURITY.md.
Roadmap
- Validate direct Cordis registration against a pinned DSH release.
- Add a persistent Markdown/registry storage adapter with atomic updates.
- Add integration tests for session-event replay, revocation propagation, and real usage normalization.
- Execute the C0–C3 evaluation protocol on a representative task suite.
- Define a maintained compatibility matrix once end-to-end DSH validation exists.
License
MIT. See LICENSE.