code: def create_agent_signer(user_id):
      
      sock = connect_to_agent(env=os.environ)
      keygrip = get_keygrip(user_id)
  
      def sign(digest):
          """Sign the digest and return an ECDSA/RSA/DSA signature."""
          return sign_digest(sock=sock, keygrip=keygrip, digest=digest)
  
      return sign
docs: Sign digest with existing GPG keys using gpg-agent tool.