agent fix
This commit is contained in:
@@ -41,14 +41,25 @@ import (
|
||||
func liveChat(t *testing.T) (utils.Chat, string) {
|
||||
t.Helper()
|
||||
|
||||
// Provider defaults exactly as production does, so this exercises the
|
||||
// defaulting rather than working around it. The first version read the
|
||||
// variable straight and skipped silently the moment `ASSISTANT_PROVIDER`
|
||||
// was left unset — which is precisely the configuration this is meant to
|
||||
// prove works.
|
||||
provider := strings.ToLower(strings.TrimSpace(os.Getenv("ASSISTANT_PROVIDER")))
|
||||
model := os.Getenv("ASSISTANT_MODEL")
|
||||
if provider == "" && strings.TrimSpace(model) != "" {
|
||||
provider = "openai"
|
||||
}
|
||||
|
||||
cfg := config.AssistantConfig{
|
||||
Provider: strings.ToLower(strings.TrimSpace(os.Getenv("ASSISTANT_PROVIDER"))),
|
||||
Provider: provider,
|
||||
BaseURL: os.Getenv("ASSISTANT_BASE_URL"),
|
||||
APIKey: os.Getenv("ASSISTANT_API_KEY"),
|
||||
Balanced: os.Getenv("ASSISTANT_MODEL"),
|
||||
Balanced: model,
|
||||
}
|
||||
if cfg.APIKey == "" || !cfg.Enabled() {
|
||||
t.Skip("no ASSISTANT_* provider configured; skipping the live model test")
|
||||
if !cfg.Enabled() {
|
||||
t.Skipf("no model configured, skipping the live test: %s", cfg.Why())
|
||||
}
|
||||
|
||||
chat, err := utils.NewChat(cfg)
|
||||
|
||||
@@ -97,12 +97,19 @@ type AssistantService interface {
|
||||
Approve(ctx context.Context, agentName, card string, caller tools.Caller) (AssistantAnswer, error)
|
||||
// Available reports whether typed questions work at all here.
|
||||
Available() bool
|
||||
// Unavailable says WHY not, or "" when it is available. A disabled composer
|
||||
// with no reason is indistinguishable from a misspelled variable, which is
|
||||
// how this stayed off without anybody being able to tell.
|
||||
Unavailable() string
|
||||
}
|
||||
|
||||
type assistantService struct {
|
||||
registry *tools.Registry
|
||||
chat utils.Chat
|
||||
agents map[string]Agent
|
||||
// Why the model is absent, from config. Carried rather than recomputed so
|
||||
// the answer the endpoint gives is the one the server actually started with.
|
||||
why string
|
||||
// How fast one person may ask. Only questions are limited — approving a
|
||||
// change the person has already read costs nothing and must not be the call
|
||||
// that gets refused.
|
||||
@@ -120,6 +127,19 @@ func NewAssistantService(registry *tools.Registry, chat utils.Chat, agents map[s
|
||||
|
||||
func (s *assistantService) Available() bool { return s.chat != nil }
|
||||
|
||||
func (s *assistantService) Unavailable() string {
|
||||
if s.chat != nil {
|
||||
return ""
|
||||
}
|
||||
if s.why != "" {
|
||||
return s.why
|
||||
}
|
||||
return "no assistant model is configured"
|
||||
}
|
||||
|
||||
// SetUnavailableReason records why there is no model, for the status endpoint.
|
||||
func (s *assistantService) SetUnavailableReason(why string) { s.why = why }
|
||||
|
||||
func (s *assistantService) Approve(ctx context.Context, agentName, card string, caller tools.Caller) (AssistantAnswer, error) {
|
||||
agent, known := s.agents[agentName]
|
||||
if !known {
|
||||
|
||||
Reference in New Issue
Block a user