Tool interaction persistence, ToolCache, and HasMemory - #4
Open
TonsOfFun wants to merge 2 commits into
Open
Conversation
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 is working — View implementation I'll get back to you soon! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
HasContextnow persists every tool-result message from the response's message stack to the context viaadd_tool_message(deduped bytool_call_id), so conversations record the full agent ↔ tool/MCP exchange, not just the final assistant text. Contexts withoutadd_tool_messageare skipped, keeping it drop-in for existing apps.SolidAgent::ToolCache— caches tool/MCP/service results by(tool, normalized args)with a TTL, backed byRails.cache(any read/write store can be injected). Error-shaped results ({ error: ... }) are never cached; replayed results are taggedcached: trueso 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 viasave_memory/recall_memoryfunction-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 withsource_agentprovenance on every entry andAgentMemory#to_promptfor instruction injection. The install generator ships theagent_memories/agent_memory_entriestables 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.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