yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tool_registry.h
Go to the documentation of this file.
1#ifndef YAZE_CLI_SERVICE_AGENT_TOOL_REGISTRY_H_
2#define YAZE_CLI_SERVICE_AGENT_TOOL_REGISTRY_H_
3
4#include <functional>
5#include <map>
6#include <memory>
7#include <optional>
8#include <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/status/statusor.h"
13#include "cli/service/ai/common.h" // For ToolCall
15
16namespace yaze {
17class Rom;
18namespace cli {
19namespace agent {
20
25 std::string name;
26 std::string category;
27 std::string description;
28 std::string usage;
29 std::vector<std::string> examples;
30 bool requires_rom = false;
31 bool requires_project = false; // New: distinguish project vs ROM dependency
32};
33
43 public:
44 // Factory function to create a handler instance
45 using HandlerFactory = std::function<std::unique_ptr<resources::CommandHandler>()>;
46
47 static ToolRegistry& Get();
48
49 // Registration
50 void RegisterTool(const ToolDefinition& def, HandlerFactory factory);
51
52 // Discovery
53 std::vector<ToolDefinition> GetAllTools() const;
54 std::optional<ToolDefinition> GetToolDefinition(const std::string& name) const;
55 std::vector<ToolDefinition> GetToolsByCategory(const std::string& category) const;
56
57 // Execution
58 absl::StatusOr<std::unique_ptr<resources::CommandHandler>> CreateHandler(
59 const std::string& tool_name) const;
60
61 private:
62 ToolRegistry() = default;
63
68
69 std::map<std::string, ToolEntry> tools_;
70};
71
72// Helper macro for static registration
73#define REGISTER_AGENT_TOOL(Name, Category, Desc, Usage, Examples, ReqRom, ReqProject, HandlerClass) \
74 static struct ToolReg_##HandlerClass { \
75 ToolReg_##HandlerClass() { \
76 yaze::cli::agent::ToolRegistry::Get().RegisterTool( \
77 {Name, Category, Desc, Usage, Examples, ReqRom, ReqProject}, \
78 []() { return std::make_unique<HandlerClass>(); } \
79 ); \
80 } \
81 } tool_reg_##HandlerClass;
82
83} // namespace agent
84} // namespace cli
85} // namespace yaze
86
87#endif // YAZE_CLI_SERVICE_AGENT_TOOL_REGISTRY_H_
Centralized registry for all agent tools.
void RegisterTool(const ToolDefinition &def, HandlerFactory factory)
std::function< std::unique_ptr< resources::CommandHandler >()> HandlerFactory
std::optional< ToolDefinition > GetToolDefinition(const std::string &name) const
std::map< std::string, ToolEntry > tools_
static ToolRegistry & Get()
std::vector< ToolDefinition > GetToolsByCategory(const std::string &category) const
std::vector< ToolDefinition > GetAllTools() const
absl::StatusOr< std::unique_ptr< resources::CommandHandler > > CreateHandler(const std::string &tool_name) const
Metadata describing a tool for the LLM.
std::vector< std::string > examples