Assuming AnimationNodeStateMachine is assigned as a root of animation tree:
# Retrieve state machine controller
var playback = $animation_tree.get("parameters/playback")
# Make sure to `Start` a state machine before any transition can occur
playback.start('rest')
# ... code to change state here ...
if walking:
# Transition to a new state according to defined transition graph
playback.travel('walk')
if jumping:
playback.travel('jump')
You can stop the animation state machine simply with:
playback.stop()
See the docs for additional info.
Also the official blog post about the new animation system.