MCPcopy
hub / github.com/mudler/LocalAI / UpdateAgentForUser

Method UpdateAgentForUser

core/services/agentpool/agent_pool.go:905–927  ·  view source on GitHub ↗

UpdateAgentForUser updates a user's agent.

(userID, name string, config *state.AgentConfig)

Source from the content-addressed store, hash-verified

903
904// UpdateAgentForUser updates a user's agent.
905func (s *AgentPoolService) UpdateAgentForUser(userID, name string, config *state.AgentConfig) error {
906 // Auto-generate a user API key when auth is active and none is specified
907 if s.users.authDB != nil && userID != "" && config.APIKey == "" {
908 plaintext, _, err := auth.CreateAPIKey(s.users.authDB, userID, "agent:"+name, "user", s.appConfig.Auth.APIKeyHMACSecret, nil)
909 if err != nil {
910 return fmt.Errorf("failed to create API key for agent: %w", err)
911 }
912 config.APIKey = plaintext
913 }
914
915 if err := s.configBackend.UpdateConfig(userID, name, config); err != nil {
916 return err
917 }
918
919 // Auto-create collection when knowledge base or long-term memory is enabled
920 if config.EnableKnowledgeBase || config.LongTermMemory {
921 if err := s.ensureCollectionForUser(userID, config.Name); err != nil {
922 xlog.Warn("Failed to auto-create collection for agent", "agent", config.Name, "error", err)
923 }
924 }
925
926 return nil
927}
928
929// DeleteAgentForUser deletes a user's agent.
930func (s *AgentPoolService) DeleteAgentForUser(userID, name string) error {

Callers 1

UpdateAgentEndpointFunction · 0.80

Calls 3

CreateAPIKeyFunction · 0.92
UpdateConfigMethod · 0.65

Tested by

no test coverage detected