Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion external/eyrie
Submodule eyrie updated from 25a5d2 to 3e832f
2 changes: 1 addition & 1 deletion external/yaad
14 changes: 14 additions & 0 deletions internal/tool/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"strings"
"sync"

"github.com/GrayCodeAI/eyrie/client"
"github.com/GrayCodeAI/hawk/internal/intelligence/memory"
Expand Down Expand Up @@ -145,6 +146,7 @@ func canonicalForReadOnly(name string) string {

// Registry holds all registered tools.
type Registry struct {
mu sync.RWMutex
tools map[string]Tool
primary []Tool
}
Expand All @@ -171,19 +173,25 @@ func NewRegistry(tools ...Tool) *Registry {

// Get returns a tool by name.
func (r *Registry) Get(name string) (Tool, bool) {
r.mu.RLock()
defer r.mu.RUnlock()
t, ok := r.tools[name]
return t, ok
}

// PrimaryTools returns the model-visible tools registered in this registry.
func (r *Registry) PrimaryTools() []Tool {
r.mu.RLock()
defer r.mu.RUnlock()
out := make([]Tool, len(r.primary))
copy(out, r.primary)
return out
}

// Filter returns a new Registry containing only tools whose names are in the allowlist.
func (r *Registry) Filter(allow []string) *Registry {
r.mu.RLock()
defer r.mu.RUnlock()
set := make(map[string]bool, len(allow))
for _, name := range allow {
set[name] = true
Expand All @@ -199,6 +207,8 @@ func (r *Registry) Filter(allow []string) *Registry {

// EyrieTools converts all tools to eyrie tool definitions for the API.
func (r *Registry) EyrieTools() []client.EyrieTool {
r.mu.RLock()
defer r.mu.RUnlock()
out := make([]client.EyrieTool, 0, len(r.primary))
for _, t := range r.primary {
out = append(out, client.EyrieTool{
Expand All @@ -212,6 +222,8 @@ func (r *Registry) EyrieTools() []client.EyrieTool {

// Execute runs a tool by name with the given JSON input.
func (r *Registry) Execute(ctx context.Context, name string, input json.RawMessage) (string, error) {
r.mu.RLock()
defer r.mu.RUnlock()
t, ok := r.tools[name]
if !ok {
return "", fmt.Errorf("unknown tool: %s", name)
Expand All @@ -222,6 +234,8 @@ func (r *Registry) Execute(ctx context.Context, name string, input json.RawMessa
// Register adds a tool to the registry after creation.
// Returns error if a tool with the same name already exists (unless it's an alias).
func (r *Registry) Register(t Tool) error {
r.mu.Lock()
defer r.mu.Unlock()
if _, exists := r.tools[t.Name()]; exists {
return fmt.Errorf("tool %q already registered", t.Name())
}
Expand Down
Loading