By "agency," we mean the ability of a subject to act independently and affect change on their surroundings. Foucault problematizes this definition by arguing that subjectivity is produced by the relationship of individuals to power. In other words, "who we are" as individuals is determined by our relationship to larger social structures. In Discipline and Punish, for example, Foucault writes about how subjects are defined as criminals because of their status as prisoners: because they are in the power of the institution, they are "known" as criminals, a label which comes to define people and how they are treated.
"Agency," in this context, is the power to resist the power structures that would define or limit our subjectivity. Rather than existing in opposition to power, however, Foucault sees agency as a necessary element of power. That is, in the same way that agency is the resistance of individuals to power structures, power structures develop and evolve in response to agency.
This finds expression in many ways in Foucault's writing. Agency can be found in people at the margins of society or in those who do not conform to accepted notions of sexuality or gender; in delinquency and indiscipline, in which acting out is a way of calling attention to the "controlled illegality" of dominant social orders; or in those who give voice to these marginal subjects.