There is no built-in way, but it's easy to program. Let's simplify your question to computing
$$\sum_{2\leq d \leq n\atop (d,n)=1} a(d) $$
This can be done as follows:
sumcoprime(a, n) = vecsum( [a(d) | d <- [2..n], gcd(n,d)==1] );
? sumcoprime(d -> 1/d, 20)
%1 = 2521693/2909907
? n = 20; S = 0; for (d = 2, n, if (gcd(d,n)==1, S += 1/d)); S
%2 = 2521693/2909907 \ double check
In many concrete cases, $a(d)$ will be a multiplicative function, and the sum can first be rewritten as a product over primes (less than $n$ and not dividing $n$).
sum(d=2,n, if(gcd(d,n)==1, a(n)/d))? – Somos Aug 14 '22 at 18:33