Add cycles to canisters as necessary

I want to write Motoko code that will add cycles to another (not the same as the current actor) canister as necessary.

To add cycles only as necessary, it would be beneficial to know the amount of cycles that the canister already has. But available and balance (BTW, what is the difference?) return amount of cycles for the current canister only. (BTW, it would be a great feature addition to query cycles of another canister.)

So, how to do this? Is it a good idea to add a query function that will return the number of cycles of the canister? Should I call this function before every other Motoko call to the canister, to count how many cycles to .add()?

It is all because I have a potentially infinite tree of canisters (the tree is going to have 3 levels) and don’t want to add cycles to a canister, if it is already “rich” in cycles, to save money.

That will be a lot of work on the canister side!, you would need to update the cycle balance every time a deposit, withdraw, method call is made. better you use management_canister
there is a method in the management canister called canister_status
I’m providing link to the rust crate.
Also there is already a project called that fits your need.
I think the project was writtten in motoko.