Back to home

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
  1. Capture into quarantine. Model summaries, individual tool outputs, and unconfirmed feedback begin as quarantine records and are not retrievable by default.
  2. Verify and explicitly promote. A record requires verified A/B-grade evidence and an explicit approval decision before it becomes promoted.
  3. 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.
  4. Retrieve a token-bounded minimum set. A ContextLedger records selected and excluded records, estimated token use, and machine-readable reason codes.
  5. Preflight the request budget. A cost policy returns ALLOW, MITIGATE, or BLOCK before the model request; estimates are never represented as provider billing.
  6. 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

CapabilityBeta behavior
Candidate isolationcapture() always writes quarantine
Promotion gateRequires verified A/B evidence and an approval argument
Retrieval policyEnforces status, scope, privacy, expiry, conflict, relevance, and token budget
Conflict/stalenessSame canonicalKey promoted records are denied; stale records enter decay
Revocationrevoke() blocks future retrieval and emits an audit event
Context governanceContextLedger records inclusions/exclusions and tokens
Budget governanceSession/daily remaining budget produces ALLOW / MITIGATE / BLOCK
DSH boundaryonPreStep, 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 promoted memories that pass scope, privacy, expiry, conflict, relevance, and token-budget checks may be retrieved.
  • quarantine, verify, decay, superseded, and revoked records 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 pointResponsibility
agent/pre-stepRetrieve eligible memory, assemble a ContextLedger, and persist model-visible provenance
agent/requestPerform a preflight budget decision before an LLM call
durable session eventsRecord capture, verification, promotion, retrieval, decay, supersession, and revocation
LLM usage processingNormalize 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

CommandPurpose
npm run buildCompile TypeScript and declarations
npm testRun governance-core unit tests
npm run exampleRun the minimal example
npm run checkBuild, tests, and example
npm run pack:dry-runInspect npm release contents

The npm package uses a files allowlist and publishes only dist/src/, README.md, LICENSE, NOTICE, and SECURITY.md.

Roadmap

  1. Validate direct Cordis registration against a pinned DSH release.
  2. Add a persistent Markdown/registry storage adapter with atomic updates.
  3. Add integration tests for session-event replay, revocation propagation, and real usage normalization.
  4. Execute the C0–C3 evaluation protocol on a representative task suite.
  5. Define a maintained compatibility matrix once end-to-end DSH validation exists.

License

MIT. See LICENSE.