Implements docs/phase2.md §5 (Sub-agents), pulled forward from the harness's item 2 work: SubAgent/SubAgentRegistry let a caller run a nested agent.Loop with its own persona/tools/iteration cap and get its final response back. Run doesn't set Approver/Sandbox, so a single Ask approval on the caller's own delegating tool covers the whole nested run (Ask-permission tools execute unprompted when Config.Approver is nil). rony-harness consumes this for its delegate tool (builder/planner).
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
llm "github.com/VictorVargas/rony-llm-agent/pkg/llm"
|
|
"github.com/VictorVargas/rony-llm-agent/pkg/persona"
|
|
"github.com/VictorVargas/rony-llm-agent/pkg/tools"
|
|
)
|
|
|
|
func TestSubAgent_Run(t *testing.T) {
|
|
mockClient := &mockLLM{
|
|
generateFunc: func(ctx context.Context, req llm.CompletionRequest) (llm.CompletionResponse, error) {
|
|
return llm.CompletionResponse{Content: "sub-agent done"}, nil
|
|
},
|
|
}
|
|
|
|
sa := SubAgent{
|
|
Name: "planner",
|
|
Persona: persona.DefaultPersona(),
|
|
Tools: tools.NewRegistry(),
|
|
}
|
|
|
|
resp, err := sa.Run(context.Background(), mockClient, "", "plan the task")
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if resp.Content != "sub-agent done" {
|
|
t.Errorf("expected 'sub-agent done', got %q", resp.Content)
|
|
}
|
|
}
|
|
|
|
func TestSubAgent_Run_DefaultsMaxIterations(t *testing.T) {
|
|
mockClient := &mockLLM{
|
|
generateFunc: func(ctx context.Context, req llm.CompletionRequest) (llm.CompletionResponse, error) {
|
|
return llm.CompletionResponse{Content: "done"}, nil
|
|
},
|
|
}
|
|
|
|
sa := SubAgent{Persona: persona.DefaultPersona(), Tools: tools.NewRegistry()}
|
|
if sa.MaxIterations != 0 {
|
|
t.Fatalf("expected zero-value MaxIterations for this test, got %d", sa.MaxIterations)
|
|
}
|
|
|
|
if _, err := sa.Run(context.Background(), mockClient, "", "hi"); err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSubAgentRegistry_Get(t *testing.T) {
|
|
reg := SubAgentRegistry{
|
|
"builder": SubAgent{Name: "builder"},
|
|
}
|
|
|
|
got, ok := reg.Get("builder")
|
|
if !ok || got.Name != "builder" {
|
|
t.Fatalf("expected to find 'builder', got %+v, ok=%v", got, ok)
|
|
}
|
|
|
|
if _, ok := reg.Get("missing"); ok {
|
|
t.Error("expected 'missing' to not be found")
|
|
}
|
|
}
|