But on the other hand, if agency is anything vaguely like being able to make choices that matter in accomplishing goals, doesn't randomness necessarily decrease agency?
No, not at all. That's like saying that because you rolled low to attack a zombie your agency to attack in the first place was somehow reduced. Agency is
the ability to make meaningful choices. Agency is
not the ability to determine outcomes. And agency is
not predicated on perfect information.
To have agency you need some information to base your choice on. You cannot have zero information otherwise the choice is meaningless. But, importantly...just like in life, it's literally impossible to have perfect information. Further, you can still be wrong. You can still choose poorly. You information may be wrong. Random chance can prevent you from winning. You can still fail to achieve your desired goal. Etc. None of those negatives in any way removes or lessens your agency. This is why I put the words "perfect" in my post. People seem to be mistaking perfect information (which they cannot have) and perfect ability to determine outcomes (which they cannot have) with agency. That's not what agency is.
Take a basic platformer video game like Super Mario Bros., Metroid, or Castlevania. After playing a while you get used to the jumps, the distances, the speeds, etc. You internalize how the physics of the game world works. You have the information you need to make informed choices, i.e. you know the physics of the world, but, importantly...you can still guess wrong and miss a platform or miss an enemy with a shot or a jump. You still have agency, you can still make meaningful, informed choices...but you can still fail or be wrong. Because agency is not about perfect information or dictating outcomes.
So in D&D, you have PCs standing at a T-intersection. Do you go left or right? Not enough information to make an informed decision. So you as the player ask the referee for more info. They tell you the passage to the left is dusty, filled with cobwebs, and dark...but the passage to the right is clean to a sparkling shine with wall sconces and lit torches every 20 feet.
The players have enough information to make a meaningful choice. If they assume the well-lighted path is safe and the dusty path is dangerous, that's their assumption to make. They can be wrong though. Whether they check for traps is agency. Whether they investigate further is agency. Etc. Skipping all that and just walking down the well-lighted path is also agency...even if it's a trap-filled nightmare of Tucker's Kobolds.
This is why it's important for the referee to play fair and not railroad and not use illusionism. The players only have the referee's words to go by. They can only trust that the referee isn't switching this around to suit their whim. The world should be prepped and set, at least in any ways that matter to tonight's session. To move encounters is to rob players of their agency. Because it removes the meaning from their choices.