Skip to content

feat(memory): Add SOS Memory Service integration#50

Open
servathadi wants to merge 1 commit intogoogle:mainfrom
servathadi:feat/sos-memory-service
Open

feat(memory): Add SOS Memory Service integration#50
servathadi wants to merge 1 commit intogoogle:mainfrom
servathadi:feat/sos-memory-service

Conversation

@servathadi
Copy link

Summary

Adds SOSMemoryService - a memory service integration for SOS (Sovereign Operating System), an open-source agent orchestration framework.

Features

  • FRC Physics: Memories ranked by Frequency (access count), Recency (time decay), and Context (semantic relevance)
  • Lineage Tracking: Cryptographic hash chain for memory provenance and auditability
  • Multi-Agent Isolation: Each agent has its own memory namespace
  • Semantic Search: Vector embedding-based similarity matching

Components Added

File Description
src/google/adk_community/memory/sos_memory_service.py Main memory service implementation
contributing/samples/sos_memory/ Sample agent demonstrating usage
tests/unittests/memory/test_sos_memory_service.py 20 unit tests

Usage Example

from google.adk_community.memory import SOSMemoryService

memory_service = SOSMemoryService(
    base_url="https://mirror.example.com",
    api_key="your-api-key",
    agent_id="my-agent"
)

# Use with ADK agent
agent = Agent(
    model='gemini-2.0-flash',
    name='my_agent',
    memory_service=memory_service,
    tools=[load_memory, preload_memory],
)

Value Proposition

  • Extends ADK's memory ecosystem with FRC-weighted retrieval
  • Provides lineage tracking for enterprise audit requirements
  • Integrates with existing SOS deployments

Test Plan

  • All 20 unit tests pass
  • Sample agent imports correctly
  • Manual testing with live SOS Mirror instance

🤖 Generated with Claude Code

Add SOSMemoryService for ADK, providing semantic memory with:
- FRC Physics: Frequency-Recency-Context weighted retrieval
- Lineage Tracking: Cryptographic hash chain for memory provenance
- Multi-Agent Isolation: Agent-specific memory namespaces
- Semantic Search: Vector-based similarity matching

Components:
- src/google/adk_community/memory/sos_memory_service.py
- contributing/samples/sos_memory/ (sample agent)
- tests/unittests/memory/test_sos_memory_service.py (20 tests)

SOS (Sovereign Operating System) is an open-source agent
orchestration framework: https://github.com/servathadi/sos

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@google-cla
Copy link

google-cla bot commented Feb 4, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @servathadi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the ADK's memory ecosystem by integrating with the SOS Mirror API. This integration provides agents with a sophisticated semantic memory backend that leverages FRC physics for highly relevant information retrieval, cryptographic lineage tracking for auditability, and isolated memory namespaces for multi-agent environments. The changes include the core service implementation, a configurable service class, a comprehensive sample agent, and robust unit tests.

Highlights

  • SOS Memory Service Integration: Introduces the SOSMemoryService for ADK agents, enabling integration with the SOS (Sovereign Operating System) Mirror API for advanced memory management.
  • Advanced Memory Features: Implements FRC (Frequency, Recency, Context) physics for intelligent memory retrieval, cryptographic lineage tracking for provenance, multi-agent isolation, and semantic search capabilities.
  • Sample Agent and Tests: Includes a new sample agent (contributing/samples/sos_memory/) demonstrating the usage of the SOS Memory Service and 20 dedicated unit tests (tests/unittests/memory/test_sos_memory_service.py) to ensure functionality.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • contributing/samples/sos_memory/README.md
    • New file detailing the SOS Memory Agent sample, including features like FRC Physics, Lineage Tracking, prerequisites, quick start instructions, configuration options for SOSMemoryServiceConfig, and explanations of FRC physics and lineage tracking.
  • contributing/samples/sos_memory/main.py
    • New file providing the main entry point for the SOS Memory Agent sample, setting up the SOSMemoryService with environment variables and running the agent.
  • contributing/samples/sos_memory/sos_memory_agent/init.py
    • New file defining the sos_memory_agent package.
  • contributing/samples/sos_memory/sos_memory_agent/agent.py
    • New file defining the root_agent for the SOS Memory Agent sample, configured with SOS Mirror for semantic memory and FRC physics.
  • src/google/adk_community/memory/init.py
    • Modified to export the newly added SOSMemoryService and SOSMemoryServiceConfig classes.
  • src/google/adk_community/memory/sos_memory_service.py
    • New file containing the SOSMemoryService class, which implements BaseMemoryService for ADK, and SOSMemoryServiceConfig for service configuration. It handles API interactions with SOS Mirror for storing and searching memories, including lineage hash computation and salience determination.
  • tests/unittests/memory/test_sos_memory_service.py
    • New file containing unit tests for SOSMemoryService and SOSMemoryServiceConfig, covering initialization, hash computation, salience logic, search payload construction, memory entry conversion, and error handling during API calls.
Activity
  • The author, servathadi, has implemented the SOSMemoryService and its configuration, along with a sample agent demonstrating its use.
  • Comprehensive unit tests (20 in total) have been added and are reported to be passing.
  • The sample agent has been verified to import correctly.
  • Manual testing with a live SOS Mirror instance is planned but not yet completed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an integration with the SOS Memory Service, providing features like FRC-weighted memory retrieval and lineage tracking. The implementation is well-structured and includes a comprehensive set of unit tests and a sample agent.

My review focuses on improving the robustness and maintainability of the new service. I've suggested changes to:

  • Decouple content from metadata to improve semantic search quality and simplify the code.
  • Increase the length of the lineage hash to reduce collision risks and enhance auditability.
  • Align the documentation with the implementation details.

Overall, this is a great addition to the ADK community memory services.

Comment on lines +148 to +156
metadata_parts = []
if event.author:
metadata_parts.append(f"Author: {event.author}")
if timestamp_str:
metadata_parts.append(f"Time: {timestamp_str}")

if metadata_parts:
metadata_prefix = "[" + ", ".join(metadata_parts) + "] "
enriched_content = metadata_prefix + content_text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Prepending metadata to the content text can negatively impact the quality of semantic search, as the embeddings will be generated from this modified text instead of the pure content. This also makes the implementation more brittle, requiring parsing logic in _convert_to_memory_entry to extract the original content.

Since the author and timestamp are already being stored in the metadata dictionary, this text enrichment is redundant. I suggest removing this logic. This will lead to cleaner embeddings and a more robust implementation.

As a follow-up, the parsing logic in _convert_to_memory_entry (lines 247-258) can also be removed, as the fallback to the metadata dictionary will handle retrieving the author and timestamp.

Every memory gets a lineage hash:

```python
hash = SHA256(previous_hash + agent_id + content + context)[:16]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The formula for the lineage hash in the README is slightly different from the actual implementation. The implementation uses colons to separate the components of the string being hashed. To avoid confusion, it would be best to update the example to reflect this.

Suggested change
hash = SHA256(previous_hash + agent_id + content + context)[:16]
hash = SHA256(f"{previous_hash}:{agent_id}:{content}:{context}")[:16]

"""Compute a lineage hash for memory provenance tracking."""
prev_hash = self._lineage_chain[-1] if self._lineage_chain else "genesis"
data = f"{prev_hash}:{self._agent_id}:{content}:{context}"
return hashlib.sha256(data.encode()).hexdigest()[:16]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Truncating the SHA256 hash to 16 characters (64 bits) increases the risk of hash collisions, which could compromise the integrity of the lineage tracking for auditability purposes. For a 64-bit hash, a collision becomes likely after around 2^32 (about 4 billion) entries. To improve robustness and reduce the chance of collisions, consider using a larger portion of the hash, for example, 32 characters (128 bits).

Suggested change
return hashlib.sha256(data.encode()).hexdigest()[:16]
return hashlib.sha256(data.encode()).hexdigest()[:32]

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.

1 participant