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>
92 lines
2.8 KiB
C++
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
|