46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
// Agent Studio export / import of an agent definition. The format follows
|
||
|
|
// ADK's Agent Config (agent_class, name, model, description, instruction,
|
||
|
|
// tools [{name}], sub_agents) with two local rules: sub_agents are inlined
|
||
|
|
// objects (config_path references are rejected loudly) and workflow agents
|
||
|
|
// carry max_iterations. A definition names tools; behavior comes from the
|
||
|
|
// ToolRegistry at import time, so a definition never contains 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 (clients::body::yaml_dump).
|
||
|
|
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 (at most kMaxDefinitionBytes) then from_json.
|
||
|
|
static std::shared_ptr<BaseAgent> from_text(const std::string& text,
|
||
|
|
const ToolRegistry& registry);
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace molo::google::adk
|