Files
moloapp/src/google/adk/session.h
T
retoorandClaude Sonnet 5.5 33e6ab0d54 feat(clients): adk: agents, tools, runner with hard caps, multi-agent graph, MCP and A2A clients, Studio export, Garden, AP2, triggers
DirectModel over GoogleClient with thought-signature replay, discovery check
script, live verified against the real model (function calling, transfer, MCP).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 04:34:22 +02:00

92 lines
2.8 KiB
C++

#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 <map>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <vector>
#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<Event> events;
};
class SessionService {
public:
virtual ~SessionService() = default;
virtual Session create(const std::string& id, const std::string& user_id) = 0;
virtual std::optional<Session> 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<Session> 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<std::string, Session> sessions_;
std::vector<std::string> 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<MemoryEntry> 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<MemoryEntry> 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<MemoryEntry> entries_;
};
} // namespace molo::google::adk