async def create_agent_with_args(args, ident: str = None):
    if ("did_exchange" in args and args.did_exchange) and args.mediation:
        raise Exception(
            "DID-Exchange connection protocol is not (yet) compatible with mediation"
        )

    require_indy()

    if "revocation" in args and args.revocation:
        tails_server_base_url = args.tails_server_base_url or os.getenv(
            "PUBLIC_TAILS_URL")
    else:
        tails_server_base_url = None

    arg_file = args.arg_file or os.getenv("ACAPY_ARG_FILE")

    # if we don't have a tails server url then guess it
    if ("revocation" in args
            and args.revocation) and not tails_server_base_url:
        # assume we're running in docker
        tails_server_base_url = (
            "http://" + (os.getenv("DOCKERHOST") or "host.docker.internal") +
            ":6543")

    if ("revocation" in args
            and args.revocation) and not tails_server_base_url:
        raise Exception(
            "If revocation is enabled, --tails-server-base-url must be provided"
        )

    genesis = await default_genesis_txns()
    if not genesis:
        print("Error retrieving ledger genesis transactions")
        sys.exit(1)

    agent_ident = ident if ident else (
        args.ident if "ident" in args else "Aries")
    agent = AgentContainer(
        genesis,
        agent_ident + ".agent",
        args.port,
        no_auto=args.no_auto,
        revocation=args.revocation if "revocation" in args else False,
        tails_server_base_url=tails_server_base_url,
        show_timing=args.timing,
        multitenant=args.multitenant,
        mediation=args.mediation,
        use_did_exchange=args.did_exchange
        if "did_exchange" in args else False,
        wallet_type=args.wallet_type,
        public_did=args.public_did if "public_did" in args else None,
        seed="random" if ("public_did" in args and args.public_did) else None,
        arg_file=arg_file,
    )

    return agent
    if not terminated:
        os._exit(1)


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(
        description="Runs a Regulator demo agent.")
    parser.add_argument(
        "-p",
        "--port",
        type=int,
        default=8100,
        metavar=("<port>"),
        help="Choose the starting port number to listen on",
    )
    parser.add_argument("--timing",
                        action="store_true",
                        help="Enable timing information")
    args = parser.parse_args()

    require_indy()

    try:
        asyncio.get_event_loop().run_until_complete(
            main(args.port, args.timing))
    except KeyboardInterrupt:
        os._exit(1)
def create_app(test_config=None):
    # create and configure the app
    app = Quart(__name__)
    cors(app, allow_origin="*")

    parser = argparse.ArgumentParser(
        description="Runs a Coordinator demo agent.")
    parser.add_argument(
        "-p",
        "--port",
        type=int,
        default=8020,
        metavar=("<port>"),
        help="Choose the starting port number to listen on",
    )
    parser.add_argument("--timing",
                        action="store_true",
                        help="Enable timing information")
    args = parser.parse_args()

    require_indy()
    agent = None

    try:
        agent = asyncio.get_event_loop().run_until_complete(
            create_agent(args.port, args.timing))
    except KeyboardInterrupt:
        os._exit(1)

    log_msg("Agent created", agent.active_connection_id)

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # a simple page that says hello
    @app.route('/hello')
    def hello():
        return 'Hello, World!'

    @app.route('/connect')
    async def connect():
        # Generate an invitation
        log_status(
            "#5 Create a connection to alice and print out the invite details")
        connection = await agent.admin_POST("/connections/create-invitation")

        agent.active_connection_id = connection["connection_id"]
        agent.connection_list.append(connection["connection_id"])
        log_msg("all connections :", agent.connection_list)
        log_json(connection, label="Invitation response:")
        log_msg("*****************")
        log_msg(json.dumps(connection["invitation"]),
                label="Invitation:",
                color=None)
        log_msg("*****************")
        agent._connection_ready = asyncio.Future()

        return json.dumps(connection["invitation"])

    @app.route('/trustedconnections')
    def connections():
        # Generate an invitation
        log_msg(agent.connection_list)
        return json.dumps(agent.trusted_connection_ids)

    return app