mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-06-06 05:51:19 +08:00
fix(agent): use provider registry for claw402, echo reasoning_content for thinking models, add Beta badge
- Agent now uses mcp.NewAIClientByProvider() for claw402 provider, ensuring x402 payment signing works correctly instead of generic HTTP client - Added ReasoningContent field to Message/LLMResponse structs and wired serialization/parsing so DeepSeek thinking models work in multi-turn - Added Beta badge to Agent nav tab in HeaderBar Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -165,13 +165,26 @@ func (a *Agent) loadAIClientFromStoreUser(storeUserID string) (mcp.AIClient, str
|
|||||||
apiKey := strings.TrimSpace(string(model.APIKey))
|
apiKey := strings.TrimSpace(string(model.APIKey))
|
||||||
customAPIURL := strings.TrimSpace(model.CustomAPIURL)
|
customAPIURL := strings.TrimSpace(model.CustomAPIURL)
|
||||||
modelName := strings.TrimSpace(model.CustomModelName)
|
modelName := strings.TrimSpace(model.CustomModelName)
|
||||||
customAPIURL, modelName = resolveModelRuntimeConfig(model.Provider, customAPIURL, modelName, model.ID)
|
provider := strings.ToLower(strings.TrimSpace(model.Provider))
|
||||||
|
|
||||||
|
// Use the provider registry for providers like claw402 that have their own
|
||||||
|
// client implementation (x402 payment, custom auth, etc.).
|
||||||
|
if client := mcp.NewAIClientByProvider(provider); client != nil {
|
||||||
|
if modelName == "" {
|
||||||
|
modelName = model.ID
|
||||||
|
}
|
||||||
|
client.SetAPIKey(apiKey, customAPIURL, modelName)
|
||||||
|
a.log().Info("agent AI client selected (provider registry)", "store_user_id", candidateUserID, "model_id", model.ID, "provider", provider, "model", modelName)
|
||||||
|
return client, modelName, true
|
||||||
|
}
|
||||||
|
|
||||||
|
customAPIURL, modelName = resolveModelRuntimeConfig(provider, customAPIURL, modelName, model.ID)
|
||||||
if apiKey == "" || customAPIURL == "" {
|
if apiKey == "" || customAPIURL == "" {
|
||||||
a.log().Warn(
|
a.log().Warn(
|
||||||
"skipping incomplete enabled AI model",
|
"skipping incomplete enabled AI model",
|
||||||
"store_user_id", candidateUserID,
|
"store_user_id", candidateUserID,
|
||||||
"model_id", model.ID,
|
"model_id", model.ID,
|
||||||
"provider", model.Provider,
|
"provider", provider,
|
||||||
"has_api_key", apiKey != "",
|
"has_api_key", apiKey != "",
|
||||||
"has_custom_api_url", customAPIURL != "",
|
"has_custom_api_url", customAPIURL != "",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4014,6 +4014,9 @@ func (a *Agent) thinkAndActLegacyWithStore(ctx context.Context, storeUserID stri
|
|||||||
if resp.Content != "" {
|
if resp.Content != "" {
|
||||||
assistantMsg.Content = resp.Content
|
assistantMsg.Content = resp.Content
|
||||||
}
|
}
|
||||||
|
if resp.ReasoningContent != "" {
|
||||||
|
assistantMsg.ReasoningContent = resp.ReasoningContent
|
||||||
|
}
|
||||||
messages = append(messages, assistantMsg)
|
messages = append(messages, assistantMsg)
|
||||||
|
|
||||||
for _, tc := range resp.ToolCalls {
|
for _, tc := range resp.ToolCalls {
|
||||||
|
|||||||
@@ -279,6 +279,7 @@ func (client *Client) ParseMCPResponseFull(body []byte) (*LLMResponse, error) {
|
|||||||
Choices []struct {
|
Choices []struct {
|
||||||
Message struct {
|
Message struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
|
ReasoningContent string `json:"reasoning_content"`
|
||||||
ToolCalls []ToolCall `json:"tool_calls"`
|
ToolCalls []ToolCall `json:"tool_calls"`
|
||||||
} `json:"message"`
|
} `json:"message"`
|
||||||
} `json:"choices"`
|
} `json:"choices"`
|
||||||
@@ -311,6 +312,7 @@ func (client *Client) ParseMCPResponseFull(body []byte) (*LLMResponse, error) {
|
|||||||
msg := result.Choices[0].Message
|
msg := result.Choices[0].Message
|
||||||
return &LLMResponse{
|
return &LLMResponse{
|
||||||
Content: msg.Content,
|
Content: msg.Content,
|
||||||
|
ReasoningContent: msg.ReasoningContent,
|
||||||
ToolCalls: msg.ToolCalls,
|
ToolCalls: msg.ToolCalls,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -624,6 +626,11 @@ func (client *Client) BuildRequestBodyFromRequest(req *Request) map[string]any {
|
|||||||
} else {
|
} else {
|
||||||
m["content"] = msg.Content
|
m["content"] = msg.Content
|
||||||
}
|
}
|
||||||
|
// DeepSeek thinking models require reasoning_content to be echoed back
|
||||||
|
// in multi-turn conversations when present in assistant messages.
|
||||||
|
if msg.ReasoningContent != "" {
|
||||||
|
m["reasoning_content"] = msg.ReasoningContent
|
||||||
|
}
|
||||||
messages = append(messages, m)
|
messages = append(messages, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import "context"
|
|||||||
type Message struct {
|
type Message struct {
|
||||||
Role string `json:"role"` // "system", "user", "assistant", "tool"
|
Role string `json:"role"` // "system", "user", "assistant", "tool"
|
||||||
Content string `json:"content,omitempty"` // Text content (omitted when ToolCalls present)
|
Content string `json:"content,omitempty"` // Text content (omitted when ToolCalls present)
|
||||||
|
ReasoningContent string `json:"reasoning_content,omitempty"` // Thinking-model reasoning (must be echoed back in multi-turn)
|
||||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // Set by assistant when calling tools
|
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // Set by assistant when calling tools
|
||||||
ToolCallID string `json:"tool_call_id,omitempty"` // Set on role="tool" result messages
|
ToolCallID string `json:"tool_call_id,omitempty"` // Set on role="tool" result messages
|
||||||
}
|
}
|
||||||
@@ -30,6 +31,7 @@ type ToolCallFunction struct {
|
|||||||
// Exactly one of the two fields will be non-empty for a well-formed response.
|
// Exactly one of the two fields will be non-empty for a well-formed response.
|
||||||
type LLMResponse struct {
|
type LLMResponse struct {
|
||||||
Content string // Plain-text reply (final answer)
|
Content string // Plain-text reply (final answer)
|
||||||
|
ReasoningContent string // Thinking-model reasoning content
|
||||||
ToolCalls []ToolCall // Structured tool invocations
|
ToolCalls []ToolCall // Structured tool invocations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ export default function HeaderBar({
|
|||||||
page: 'agent',
|
page: 'agent',
|
||||||
path: ROUTES.agent,
|
path: ROUTES.agent,
|
||||||
label: 'Agent',
|
label: 'Agent',
|
||||||
|
badge: 'Beta',
|
||||||
requiresAuth: false,
|
requiresAuth: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user