Skip to content

Tool interaction persistence, ToolCache, and HasMemory - #4

Open
TonsOfFun wants to merge 2 commits into
mainfrom
claude/analytics-api-key-encryption-9kwpsc
Open

Tool interaction persistence, ToolCache, and HasMemory#4
TonsOfFun wants to merge 2 commits into
mainfrom
claude/analytics-api-key-encryption-9kwpsc

Conversation

@TonsOfFun

Copy link
Copy Markdown
Contributor

Summary

Three additions that make solid_agent persist and cache the full agent interaction stream out of the box, for any Rails app using activeagent:

  • Tool interaction persistenceHasContext now persists every tool-result message from the response's message stack to the context via add_tool_message (deduped by tool_call_id), so conversations record the full agent ↔ tool/MCP exchange, not just the final assistant text. Contexts without add_tool_message are skipped, keeping it drop-in for existing apps.
  • SolidAgent::ToolCache — caches tool/MCP/service results by (tool, normalized args) with a TTL, backed by Rails.cache (any read/write store can be injected). Error-shaped results ({ error: ... }) are never cached; replayed results are tagged cached: true so callers and models can tell a replay from a fresh call.
  • SolidAgent::HasMemory — an agent-curated summary list the model decides when to read/write via save_memory/recall_memory function-calling tools. Memory is scoped to a subject record (memorable, scope) rather than the agent class, so agents operating on the same subject share it — a handoff channel with source_agent provenance on every entry and AgentMemory#to_prompt for instruction injection. The install generator ships the agent_memories/agent_memory_entries tables and models.

Test plan

  • test/solid_agent/tool_cache_test.rb — cache/replay tagging, stable keys across arg ordering and key types, error skipping, TTL, disable, no-store passthrough.
  • test/solid_agent/has_memory_test.rb — tool definitions, save/recall roundtrip, cross-agent handoff on a shared subject, category filtering, no-subject errors.
  • Full gem suite: 201 runs, 0 failures.
  • Consumed end-to-end by the activeagents platform PR (companion branch of the same name), which exercises persistence and caching against Postgres.

Merge order: merge this before activeagents' companion PR — the app's Gemfile tracks solid_agent main, and the app-side glue defers to these gem implementations once present.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B5PaDq3uaUWuA8UW4K7siP


Generated by Claude Code

claude added 2 commits July 29, 2026 19:46
Conversations persisted through HasContext only recorded the final
assistant message; the tool/MCP roundtrips in the response's message
stack were dropped, so downstream views (like the ActiveAgents
Interactions dashboard) couldn't show what an agent actually did.

- HasContext now persists each tool-result message to the context via
  add_tool_message (already part of the install generator's
  AgentContext), deduped by tool_call_id so shared message stacks in
  multi-turn conversations don't duplicate rows. Contexts without
  add_tool_message are skipped, keeping the change drop-in for
  existing apps.

- New SolidAgent::ToolCache caches tool/MCP/service results by
  (tool, normalized args) with a TTL, backed by Rails.cache out of
  the box and by any read/write store elsewhere. Error-shaped results
  ({ error: ... }) are never cached, and replayed hashes are tagged
  cached: true so callers can tell a replay from a fresh call.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B5PaDq3uaUWuA8UW4K7siP
Bakes a memory concern into solid_agent: agents persist a summary list
they decide when to read/write while interacting with tools, other
agents, and users.

- SolidAgent::HasMemory exposes save_memory/recall_memory as
  function-calling tool definitions plus matching instance methods, so
  a provider's tool calls route straight to persistent memory. The
  memory subject defaults to params[:memorable], falling back to the
  HasContext contextable.
- Memory is scoped to (memorable subject, scope) rather than the agent
  class, so any agent operating on the same subject shares it — a
  handoff channel between agents, with source_agent provenance on
  every entry and AgentMemory#to_prompt for instruction injection.
- The install generator now creates agent_memories /
  agent_memory_entries tables and AgentMemory/AgentMemoryEntry models
  implementing the duck-typed contract, so existing Rails apps get
  memory out of the box alongside contexts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B5PaDq3uaUWuA8UW4K7siP
@superconductor-for-github

Copy link
Copy Markdown

Superconductor is workingView implementation


I'll get back to you soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants