Files
moloapp/src/google/adk/studio.h
T

49 lines
1.9 KiB
C++

#pragma once
// Agent Studio export / import of an agent definition. The format is ADK's
// Agent Config (google/adk-python AgentConfig.json: agent_class, name, model,
// description, instruction, output_key, tools [{name, args}], sub_agents,
// max_iterations), JSON or YAML, with one local rule: sub_agents are inlined
// objects (the schema's config_path / code references are rejected loudly).
// Unknown fields and ADK fields this runtime lacks (callbacks, schemas,
// generate_content_config) are rejected by name. A definition names tools;
// behavior comes from the ToolRegistry at import time, so it never carries code.
#include <map>
#include <memory>
#include <string>
#include "clients/body/json.h"
#include "google/adk/agent.h"
namespace molo::google::adk {
class ToolRegistry {
public:
ToolRegistry(); // Pre-registers exit_loop.
void add(std::shared_ptr<Tool> tool); // Replaces a tool of the same name.
std::shared_ptr<Tool> find(const std::string& name) const;
std::vector<std::string> names() const;
std::size_t size() const { return tools_.size(); }
private:
std::map<std::string, std::shared_ptr<Tool>> tools_;
};
class AgentDefinition {
public:
static clients::body::Json to_json(const BaseAgent& agent);
// Block-style YAML of the same document (adk::yaml::dump); from_text reads it back.
static std::string to_yaml(const BaseAgent& agent);
// Validates class, names, tool names, counts, depth before building.
static std::shared_ptr<BaseAgent> from_json(const clients::body::Json& doc,
const ToolRegistry& registry);
// Parses JSON (text starting with '{') or the strict YAML subset of
// yaml.h (at most kMaxDefinitionBytes), then from_json.
static std::shared_ptr<BaseAgent> from_text(const std::string& text,
const ToolRegistry& registry);
};
} // namespace molo::google::adk