Would this not mean that if you oppose the Iran war because it's bad to kill civilians or you want gas prices to go down, that's OK - but if you oppose the Iran war because you're trying to help the Iranian government's foreign policy goals, that's acting as a foreign agent?
(Similarly, demonstrating in support of Israel because you think the US-Israel alliance is good for the US vs. good for Israel.)
I guess that’s a defense you could claim to the judge, at the trial, after being arrested.