# File lib/mcollective/agents.rb, line 42
    def loadagent(agentname)
      agentfile = findagentfile(agentname)
      return false unless agentfile
      classname = class_for_agent(agentname)

      PluginManager.delete("#{agentname}_agent")

      begin
        single_instance = ["registration", "discovery"].include?(agentname)

        PluginManager.loadclass(classname)

        if activate_agent?(agentname)
          PluginManager << {:type => "#{agentname}_agent", :class => classname, :single_instance => single_instance}

          # Attempt to instantiate the agent once so any validation and hooks get run
          # this does a basic sanity check on the agent as a whole, if this fails it
          # will be removed from the plugin list
          PluginManager["#{agentname}_agent"]

          Util.subscribe(Util.make_subscriptions(agentname, :broadcast)) unless @@agents.include?(agentname)

          @@agents[agentname] = {:file => agentfile}
          return true
        else
          Log.debug("Not activating agent #{agentname} due to agent policy in activate? method")
          return false
        end
      rescue Exception => e
        Log.error("Loading agent #{agentname} failed: #{e}")
        PluginManager.delete("#{agentname}_agent")
        return false
      end
    end