mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-14 19:37:31 +08:00
feat: align provider runtimes with cliproxyapi
This commit is contained in:
@@ -369,13 +369,13 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
|
||||
if dup {
|
||||
continue
|
||||
}
|
||||
if p2, err := providers.CreateProviderByName(cfg, name); err == nil {
|
||||
loop.providerPool[name] = p2
|
||||
loop.providerNames = append(loop.providerNames, name)
|
||||
if pc, ok := config.ProviderConfigByName(cfg, name); ok {
|
||||
loop.providerResponses[name] = pc.Responses
|
||||
}
|
||||
if p2, err := providers.CreateProviderByName(cfg, name); err == nil {
|
||||
loop.providerPool[name] = p2
|
||||
loop.providerNames = append(loop.providerNames, name)
|
||||
if pc, ok := config.ProviderConfigByName(cfg, name); ok {
|
||||
loop.providerResponses[name] = pc.Responses
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Inject recursive run logic so subagents can use full tool-calling flows.
|
||||
@@ -644,6 +644,13 @@ func (al *AgentLoop) getSessionProvider(sessionKey string) string {
|
||||
return v
|
||||
}
|
||||
|
||||
func (al *AgentLoop) syncSessionDefaultProvider(sessionKey string) {
|
||||
if al == nil || len(al.providerNames) == 0 {
|
||||
return
|
||||
}
|
||||
al.setSessionProvider(sessionKey, al.providerNames[0])
|
||||
}
|
||||
|
||||
func (al *AgentLoop) markSessionStreamed(sessionKey string) {
|
||||
key := strings.TrimSpace(sessionKey)
|
||||
if key == "" {
|
||||
@@ -977,6 +984,7 @@ func (al *AgentLoop) ProcessDirectWithOptions(ctx context.Context, content, sess
|
||||
if sessionKey == "" {
|
||||
sessionKey = "main"
|
||||
}
|
||||
al.syncSessionDefaultProvider(sessionKey)
|
||||
ns := normalizeMemoryNamespace(memoryNamespace)
|
||||
var metadata map[string]string
|
||||
if ns != "main" {
|
||||
@@ -1015,9 +1023,7 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
|
||||
return "", err
|
||||
}
|
||||
defer release()
|
||||
if len(al.providerNames) > 0 {
|
||||
al.setSessionProvider(msg.SessionKey, al.providerNames[0])
|
||||
}
|
||||
al.syncSessionDefaultProvider(msg.SessionKey)
|
||||
// Add message preview to log
|
||||
preview := truncate(msg.Content, 80)
|
||||
logger.InfoCF("agent", logger.C0171,
|
||||
@@ -1733,6 +1739,11 @@ func (al *AgentLoop) buildResponsesOptions(sessionKey string, maxTokens int64, t
|
||||
"max_tokens": maxTokens,
|
||||
"temperature": temperature,
|
||||
}
|
||||
if strings.EqualFold(strings.TrimSpace(al.getSessionProvider(sessionKey)), "codex") {
|
||||
if key := strings.TrimSpace(sessionKey); key != "" {
|
||||
options["codex_execution_session"] = key
|
||||
}
|
||||
}
|
||||
responsesCfg := al.responsesConfigForSession(sessionKey)
|
||||
responseTools := make([]map[string]interface{}, 0, 2)
|
||||
if responsesCfg.WebSearchEnabled {
|
||||
|
||||
44
pkg/agent/loop_codex_options_test.go
Normal file
44
pkg/agent/loop_codex_options_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package agent
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBuildResponsesOptionsAddsCodexExecutionSession(t *testing.T) {
|
||||
loop := &AgentLoop{
|
||||
sessionProvider: map[string]string{
|
||||
"chat-1": "codex",
|
||||
},
|
||||
}
|
||||
|
||||
options := loop.buildResponsesOptions("chat-1", 8192, 0.7)
|
||||
if got := options["codex_execution_session"]; got != "chat-1" {
|
||||
t.Fatalf("expected codex_execution_session chat-1, got %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildResponsesOptionsSkipsCodexExecutionSessionForOtherProviders(t *testing.T) {
|
||||
loop := &AgentLoop{
|
||||
sessionProvider: map[string]string{
|
||||
"chat-1": "claude",
|
||||
},
|
||||
}
|
||||
|
||||
options := loop.buildResponsesOptions("chat-1", 8192, 0.7)
|
||||
if _, ok := options["codex_execution_session"]; ok {
|
||||
t.Fatalf("expected no codex_execution_session for non-codex provider, got %#v", options["codex_execution_session"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncSessionDefaultProviderOverridesStaleSessionProvider(t *testing.T) {
|
||||
loop := &AgentLoop{
|
||||
providerNames: []string{"openai"},
|
||||
sessionProvider: map[string]string{
|
||||
"chat-1": "codex",
|
||||
},
|
||||
}
|
||||
|
||||
loop.syncSessionDefaultProvider("chat-1")
|
||||
|
||||
if got := loop.getSessionProvider("chat-1"); got != "openai" {
|
||||
t.Fatalf("expected stale session provider to be replaced with current default, got %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user