feat(agent): make the agentic loop the primary brain path

thinkAndAct/thinkAndActStream now try the native function-calling loop
first for fresh conversations; in-flight legacy flows (skill sessions,
workflows, execution states, pending proposals) stay on the legacy stack
until they finish. NOFX_AGENT_V2=off restores the old routing entirely.
This commit is contained in:
tinkle-community
2026-06-11 01:03:08 +08:00
parent 785922697b
commit f3c33b55d7
3 changed files with 70 additions and 0 deletions

View File

@@ -4,11 +4,13 @@ import (
"context"
"errors"
"log/slog"
"path/filepath"
"strings"
"testing"
"time"
"nofx/mcp"
"nofx/store"
)
// scriptedAIClient returns queued LLMResponses (or errors) in order for
@@ -250,6 +252,45 @@ func TestRunAgenticTurnIncludesRecentHistory(t *testing.T) {
}
}
func TestShouldUseAgenticTurn(t *testing.T) {
t.Setenv("NOFX_AGENT_V2", "")
a := newAgenticTestAgent(&scriptedAIClient{})
if !a.shouldUseAgenticTurn(10) {
t.Fatal("fresh conversation with AI client should use the agentic turn")
}
t.Run("disabled by env", func(t *testing.T) {
t.Setenv("NOFX_AGENT_V2", "off")
if a.shouldUseAgenticTurn(10) {
t.Fatal("env kill switch must disable the agentic turn")
}
})
t.Run("no AI client", func(t *testing.T) {
noAI := New(nil, nil, DefaultConfig(), slog.Default())
if noAI.shouldUseAgenticTurn(10) {
t.Fatal("agentic turn requires an AI client")
}
})
t.Run("active legacy session stays on legacy stack", func(t *testing.T) {
st, err := store.New(filepath.Join(t.TempDir(), "agentic-guard.db"))
if err != nil {
t.Fatalf("create store: %v", err)
}
b := New(nil, st, DefaultConfig(), slog.Default())
b.SetAIClient(&scriptedAIClient{})
if !b.shouldUseAgenticTurn(11) {
t.Fatal("fresh conversation should use the agentic turn")
}
b.saveActiveSkillSession(newActiveSkillSession(11, "strategy_management", "create"))
if b.shouldUseAgenticTurn(11) {
t.Fatal("active skill session must stay on the legacy stack")
}
})
}
func TestAgentV2Enabled(t *testing.T) {
cases := []struct {
value string