Agency, in a nutshell, is the capacity of individuals to think and act of their own free will, unhindered by a person or group who is abusing power and authority. (For example, a controlling girlfriend or an oppressive government.)
To write a character who has agency, you need to write a person who thinks for themselves and acts on their own to improve their situation and/or future, even if they are in an oppressive situation. Think of it this way: a “damsel in distress” versus a “strong female heroine.” A character with agency acts in ways that affect the plot. Their actions move the story forward.
If your character is a princess who is locked in a tower, and she just sits and waits to be rescued, she doesn’t have agency. She’s not thinking about her situation, questioning it, challenging it, and trying to change it. The agency belongs entirely to the character who locks her up and the character who saves her. The story isn’t moving forward when she’s just sitting around waiting to be rescued. The story moves forward when a rescue plot is underway and she is finally whisked away from the tower–but if she’s not involved in her own rescue, she’s not moving the story forward. Her rescuer is.
A princess in a tower with agency is one who thinks about why she’s locked up, questions whether or not it’s right, comes to her own decision and challenges that which she does not see as right. She will act in ways that improve her situation, thus moving the story forward. If her goal is escape, she will act in ways that build toward that end. Even if she fails, the point is that she tried.
It’s okay for characters with agency to sometimes rely on others, or to even be completely unable to act of their own free will. They just need to be capable of doing it when they can. A great example would be June/Offred in The Handmaid’s Tale. Because of the society she lives in, and her specific situation, she’s often limited as far as what she can actually do, but she finds small ways to challenge the authority robbing her of her agency. And most important of all, she thinks for herself and is, at least, inwardly defiant, even when she can’t express it outwardly. Despite her situation, the character manages to act in ways that move the story forward.