mirror of
https://github.com/hanzoai/agents.git
synced 2026-10-30 18:48:36 +00:00
Transforms hanzoai/agents from a marketplace config repo into a full agent orchestration platform by merging the AgentField infrastructure: - Go control plane (K8s-like agent orchestration, service mesh, DAG workflows) - Python SDK (FastAPI-based agent framework, LiteLLM, memory, DID/VC) - TypeScript SDK (@hanzo/agents - Vercel AI SDK, MCP, workflows) - Go SDK (idiomatic agent builder + client) - React 19 embedded dashboard (XyFlow DAGs, Recharts, Radix UI) - Docker/K8s/Helm deployment configs - Examples: hello world, deep research, RAG, simulation, benchmarks - Functional test suite across Python/Go/TypeScript All references rebranded: AgentField → Hanzo Agents - Module: github.com/hanzoai/agents/control-plane - Python: hanzo_agents - TypeScript: @hanzo/agents - Go: github.com/hanzoai/agents/sdk/go - Env vars: HANZO_AGENTS_* - Config: hanzo-agents.yaml Previous marketplace configs moved to config/ directory.
96 lines
2.2 KiB
Go
96 lines
2.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func newTestAgent(t *testing.T) *Agent {
|
|
t.Helper()
|
|
a, err := New(Config{
|
|
NodeID: "node-1",
|
|
Version: "1.0.0",
|
|
Logger: log.New(io.Discard, "", 0),
|
|
})
|
|
require.NoError(t, err)
|
|
return a
|
|
}
|
|
|
|
func captureOutput(t *testing.T, fn func() error) (string, string, error) {
|
|
t.Helper()
|
|
stdoutR, stdoutW, _ := os.Pipe()
|
|
stderrR, stderrW, _ := os.Pipe()
|
|
|
|
origStdout := os.Stdout
|
|
origStderr := os.Stderr
|
|
os.Stdout = stdoutW
|
|
os.Stderr = stderrW
|
|
|
|
err := fn()
|
|
|
|
stdoutW.Close()
|
|
stderrW.Close()
|
|
os.Stdout = origStdout
|
|
os.Stderr = origStderr
|
|
|
|
outBytes, _ := io.ReadAll(stdoutR)
|
|
errBytes, _ := io.ReadAll(stderrR)
|
|
|
|
return string(outBytes), string(errBytes), err
|
|
}
|
|
|
|
func TestParseCLIArgs_MergePriority(t *testing.T) {
|
|
a := newTestAgent(t)
|
|
|
|
tmpFile, err := os.CreateTemp(t.TempDir(), "input-*.json")
|
|
require.NoError(t, err)
|
|
_, err = tmpFile.WriteString(`{"source":"file","shared":2}`)
|
|
require.NoError(t, err)
|
|
tmpFile.Close()
|
|
|
|
origStdin := os.Stdin
|
|
stdinR, stdinW, _ := os.Pipe()
|
|
os.Stdin = stdinR
|
|
_, _ = stdinW.WriteString(`{"source":"stdin","shared":1}`)
|
|
stdinW.Close()
|
|
t.Cleanup(func() { os.Stdin = origStdin })
|
|
|
|
inv, err := a.parseCLIArgs([]string{
|
|
"--input-file", tmpFile.Name(),
|
|
"--input", `{"source":"flag","shared":3}`,
|
|
"--set", "shared=4",
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, inv.input)
|
|
assert.Equal(t, "flag", inv.input["source"])
|
|
assert.Equal(t, float64(4), inv.input["shared"])
|
|
}
|
|
|
|
func TestRunCLI_ExecutesDefaultReasoner(t *testing.T) {
|
|
a := newTestAgent(t)
|
|
|
|
a.RegisterReasoner("greet", func(ctx context.Context, input map[string]any) (any, error) {
|
|
assert.True(t, IsCLIMode(ctx))
|
|
args := GetCLIArgs(ctx)
|
|
assert.Equal(t, "Bob", args["name"])
|
|
return fmt.Sprintf("Hello, %s", input["name"]), nil
|
|
}, WithCLI(), WithDefaultCLI(), WithDescription("Greets a user"))
|
|
|
|
stdout, stderr, err := captureOutput(t, func() error {
|
|
return a.runCLI(context.Background(), []string{"--set", "name=Bob", "--output", "json"})
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
assert.Contains(t, stdout, "Hello, Bob")
|
|
assert.Equal(t, "", strings.TrimSpace(stderr))
|
|
}
|