We propose a systems-level computational model of the basal ganglia based closely on known anatomy and physiology. First, we assume that the thalamic targets, which relay ascending information to cortical action and planning areas, are tonically inhibited by the basal ganglia. Second, we assume that the output stage of the basal ganglia, the internal segment of the globus pallidus (Gpi), selects a single action from several competing actions via lateral interactions. Third, we propose that a form of local working memory exists in the form of reciprocal connections between the external globus pallidus (Gpe) and the subthalamic nucleus (STN). As a test of the model, the system was trained to learn a sequence of states that required the context of previous actions. The striatum, which was assumed to represent a conjunction of cortical states, directly selected the action in the GP during training. The STN-to-GP connection strengths were modified by an associative learning rule and came to encode the sequence after 20 to 40 iterations through the sequence. Subsequently, the system automatically reproduced the sequence when cued to the first action. The behavior of the model was found to be sensitive to the ratio of the striatal-nigral learning rate to the STN-GP learning rate. Additionally, the degree of striatal inhibition of the globus pallidus had a significant influence on both learning and the ability to select an action. Low learning rates, which would be hypothesized to reflect low levels of dopamine, as in Parkinson's disease, led to slow acquisition of contextual information. However, this could be partially offset by modeling a lesion of the globus pallidus that resulted in an increase in the gain of the STN units. The parameter sensitivity of the model is discussed within the framework of existing behavioral and lesion data.