惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
L
LangChain Blog
Jina AI
Jina AI
爱范儿
爱范儿
C
Check Point Blog
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
月光博客
月光博客
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Stack Overflow Blog
Stack Overflow Blog
V
V2EX
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Cosmic as Agent Memory: Structured, Versioned, and Queryable
Tony Spiro · 2026-06-19 · via DEV Community

AI agents get better the more they run. Every conversation turn, every task completed, every prompt refined adds to a growing body of context that shapes the next output. The compounding effect is real: an agent with 100 turns of memory and a versioned prompt history behaves meaningfully differently from one starting cold.

This post walks through using a structured, versioned, API-accessible store as the memory layer for AI agents, with TypeScript examples. Agent messages, system prompts, findings, and instructions are all stored as structured, versioned, API-accessible Objects. Each new turn adds to the record. Each prompt edit is tracked.

What Agent Memory Actually Needs

The compounding loop only works if the memory layer has the right properties. Most agent frameworks handle working memory well. The gap is episodic and semantic memory: what the agent learned, did, and produced across sessions.

Researchers at Elastic recently published a breakdown of agent memory tiers: working memory (in-context), episodic memory (past interactions), semantic memory (knowledge), and procedural memory (learned behaviors). Good persistent agent memory needs four properties:

  • Structured: queryable by type, status, date, or custom field, not just full-text search
  • Versioned: you need to know what the agent wrote at each point in time, not just the latest state
  • API-accessible: any model, any framework, any language should be able to read and write it
  • Human-reviewable: agents make mistakes; a human needs to inspect and correct outputs without touching a database

Objects as Agent Outputs

When an agent produces output, storing it as a structured Object gives you a queryable record with typed fields, a draft/published workflow so a human can review before promoting to production, a full audit trail of every change, REST API access from any runtime, and a dashboard UI where non-technical team members can inspect, edit, or approve agent outputs.

Here's a simple research agent that stores its findings as Cosmic Objects:

import { createBucketClient } from '@cosmicjs/sdk'

const cosmic = createBucketClient({
  bucketSlug: process.env.COSMIC_BUCKET_SLUG!,
  readKey: process.env.COSMIC_READ_KEY!,
  writeKey: process.env.COSMIC_WRITE_KEY!,
})

async function storeAgentFinding({
  topic,
  summary,
  sourceUrl,
  confidenceScore,
}: {
  topic: string
  summary: string
  sourceUrl: string
  confidenceScore: number
}) {
  const result = await cosmic.objects.insertOne({
    title: topic,
    type: 'agent-findings',
    status: 'draft', // human review before publishing
    metadata: {
      summary,
      source_url: sourceUrl,
      confidence_score: confidenceScore,
      reviewed: false,
    },
  })
  return result.object
}

The output is immediately visible in the dashboard. A team member can review the summary, edit it, toggle reviewed to true, and publish, all without touching code.

Storing Prompts, Context, and Conversation Memory

Agent outputs are only part of the picture. The other half is what goes in to the agent: system prompts, conversation history, and session context.

System Prompts as Objects

Instead of hardcoding system prompts in your codebase, store them as Objects. This gives you version control for prompts (draft a new version, test it, publish when ready, roll back if behavior degrades), non-engineer editable wording without a deploy, and environment-aware prompts per environment with zero code changes.

// Fetch the active system prompt for an agent
const { object: promptObject } = await cosmic.objects
  .findOne({
    type: 'agent-prompts',
    slug: 'content-research-agent',
    status: 'published',
  })
  .props('title,metadata.prompt_text,metadata.version')

const systemPrompt = promptObject.metadata.prompt_text

When you want to update the prompt, you edit it in the dashboard, save a new version, and publish. The agent picks it up on the next run with no deployment required.

Conversation Context and Message History

For agents that need to maintain state across sessions, store the conversation history as structured Objects:

async function storeMessage({
  sessionId,
  role,
  content,
  agentName,
}: {
  sessionId: string
  role: 'user' | 'assistant' | 'system'
  content: string
  agentName: string
}) {
  await cosmic.objects.insertOne({
    title: `${agentName} / ${sessionId} / ${role}`,
    type: 'agent-messages',
    status: 'published',
    metadata: {
      session_id: sessionId,
      role,
      content,
      agent_name: agentName,
    },
  })
}

// Retrieve full conversation context for a session
const { objects: messages } = await cosmic.objects
  .find({
    type: 'agent-messages',
    'metadata.session_id': sessionId,
  })
  .props('metadata.role,metadata.content,created_at')
  .sort('created_at')

The agent can reconstruct its full conversation history on every run. The history is human-readable in the dashboard, editable when needed, and queryable across sessions.

Querying Agent Memory

The real power is in retrieval. Because each agent output is a structured Object with typed metafields, you can query across your entire agent history:

// Get all unreviewed findings from the last 7 days
const { objects } = await cosmic.objects
  .find({
    type: 'agent-findings',
    'metadata.reviewed': false,
  })
  .props('id,title,metadata,created_at')
  .sort('-created_at')
  .limit(50)

// Get high-confidence findings on a specific topic
const { objects: topFindings } = await cosmic.objects
  .find({
    type: 'agent-findings',
    'metadata.confidence_score': { $gte: 0.85 },
  })
  .props('id,title,metadata')
  .sort('-metadata.confidence_score')

You are filtering by structured properties, sorting by custom scores, and scoping by review status. The agent's memory is queryable the same way any other content in your system is queryable.

Versioning: Know What the Agent Said When

A full revision history for every Object matters for auditability. If an agent's output informed a business decision, you need to know exactly what it said at the time of that decision, not just the current state. The same applies to prompts. When a prompt change shifts agent behavior, you can trace exactly which version was active and when. That's the kind of audit trail that matters as agents take on more consequential tasks.

Using the MCP Server

Cosmic ships a native MCP Server, which means any agent running in Claude, Cursor, Windsurf, or any MCP-compatible runtime can read and write Objects directly, with no custom API wrapper needed. The MCP Server exposes all 18 Cosmic tools to your agent: create objects, update objects, query by type, filter by metadata, manage media, and more.

Schema Design for Agent Context and Memory

The key to making this work well is defining clean Object types upfront. Three schemas cover most agent context and memory use cases:

agent-findings: summary (textarea), source_url (text), confidence_score (number 0-1), agent_name (text), session_id (text), reviewed (switch), tags (references)

agent-messages: role (select: user/assistant/system), content (textarea), agent_name (text), session_id (text)

agent-prompts: prompt_text (textarea), version (number), notes (textarea)

What You Get Out of the Box

You could build this with Postgres and a custom schema. A headless CMS includes a dashboard UI for every agent output with no custom admin to build, built-in revision history with no extra tables, a REST API ready to consume from any runtime, a draft/published workflow, media handling, and model agnosticism across any framework or language.

Read the full post on the Cosmic blog for the complete walkthrough, including the copy-paste schema setup and getting-started steps.