#pragma once // Session and memory seams of the ADK, with bounded in-memory defaults. // These are local interfaces: the ADK does not depend on the sessions // module (Agent Sessions / Memory Bank); an adapter over that module can // implement the same interfaces later. #include #include #include #include #include #include #include "clients/body/json.h" #include "google/gemini_types.h" namespace molo::google::adk { struct Event { std::string author; // "user" or an agent name Content content; bool final = false; // A final answer of an agent (kept in history) clients::body::Json to_json() const; }; struct Session { std::string id; std::string user_id; clients::body::Json state = clients::body::Json::object(); std::vector events; }; class SessionService { public: virtual ~SessionService() = default; virtual Session create(const std::string& id, const std::string& user_id) = 0; virtual std::optional get(const std::string& id) = 0; virtual void save(const Session& session) = 0; virtual bool remove(const std::string& id) = 0; }; // Bounded: kMaxSessions (oldest created evicted), kMaxEventsPerSession // (oldest dropped), kMaxStateKeys and kMaxStateValueBytes on save. class InMemorySessionService : public SessionService { public: Session create(const std::string& id, const std::string& user_id) override; std::optional get(const std::string& id) override; void save(const Session& session) override; bool remove(const std::string& id) override; std::size_t size() const; private: mutable std::mutex mutex_; std::map sessions_; std::vector order_; // creation order for eviction }; struct MemoryEntry { std::string user_id; std::string session_id; std::string author; std::string text; }; class MemoryService { public: virtual ~MemoryService() = default; // Stores the text of the session's user and final agent events. virtual void add_session(const Session& session) = 0; virtual std::vector search(const std::string& user_id, const std::string& query, std::size_t limit) = 0; }; // Keyword overlap ranking, no embeddings. Bounded by kMaxMemoryEntries // (oldest dropped) and kMaxMemoryResults per search. class InMemoryMemoryService : public MemoryService { public: void add_session(const Session& session) override; std::vector search(const std::string& user_id, const std::string& query, std::size_t limit) override; std::size_t size() const; private: mutable std::mutex mutex_; std::vector entries_; }; } // namespace molo::google::adk